default disable all features and add bot join guild message
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m1s

This commit is contained in:
Lee 2024-07-05 19:33:10 +01:00
parent 4e866895a0
commit 0b09b8ba5f
24 changed files with 105 additions and 27 deletions

@ -128,4 +128,19 @@ public abstract class BatCommand {
protected final void addOptions(OptionData... options) {
commandData.addOptions(options);
}
/**
* Get the sub command by its class.
*
* @param clazz the class of the sub command
* @return the sub command
*/
public BatCommand getSubCommand(Class<? extends BatCommand> clazz) {
for (Map.Entry<String, BatCommand> entry : subCommands.entrySet()) {
if (entry.getValue().getClass().equals(clazz)) {
return entry.getValue();
}
}
return null;
}
}

@ -19,6 +19,11 @@ public abstract class Feature {
*/
private final String name;
/**
* The default state of the feature
*/
private final FeatureProfile.FeatureState defaultState;
/**
* The description of the feature
*/

@ -1,7 +1,6 @@
package cc.fascinated.bat.features.base.profile;
package cc.fascinated.bat.features;
import cc.fascinated.bat.common.Serializable;
import cc.fascinated.bat.features.Feature;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ -16,8 +15,6 @@ import java.util.Map;
*/
@NoArgsConstructor
public class FeatureProfile extends Serializable {
private static final FeatureState DEFAULT_STATE = FeatureState.ENABLED;
/**
* The feature states
*/
@ -30,11 +27,11 @@ public class FeatureProfile extends Serializable {
*/
public FeatureState getFeatureState(Feature feature) {
if (feature == null) {
return DEFAULT_STATE;
return FeatureProfile.FeatureState.DISABLED;
}
String featureName = feature.getName().toUpperCase();
if (!this.featureStates.containsKey(featureName)) {
this.featureStates.put(featureName, DEFAULT_STATE);
this.featureStates.put(featureName, feature.getDefaultState());
}
return this.featureStates.get(featureName);
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.afk;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.afk.command.AfkCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -13,7 +14,7 @@ import org.springframework.stereotype.Component;
@Component
public class AfkFeature extends Feature {
public AfkFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("AFK", true);
super("AFK", FeatureProfile.FeatureState.DISABLED, true);
registerCommand(commandService, context.getBean(AfkCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.autorole;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.autorole.command.AutoRoleCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
public class AutoRoleFeature extends Feature {
@Autowired
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Auto Role",true);
super("Auto Role", FeatureProfile.FeatureState.DISABLED, true);
registerCommand(commandService, context.getBean(AutoRoleCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.base;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.base.commands.botadmin.premium.PremiumAdminCommand;
import cc.fascinated.bat.features.base.commands.fun.EightBallCommand;
import cc.fascinated.bat.features.base.commands.fun.image.ImageCommand;
@ -24,7 +25,7 @@ import org.springframework.stereotype.Component;
public class BaseFeature extends Feature {
@Autowired
public BaseFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Base", false);
super("Base", FeatureProfile.FeatureState.DISABLED, false);
super.registerCommand(commandService, context.getBean(PremiumCommand.class));
super.registerCommand(commandService, context.getBean(PremiumAdminCommand.class));

@ -4,7 +4,7 @@ import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.FeatureService;

@ -4,7 +4,7 @@ import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.FeatureService;

@ -4,7 +4,7 @@ import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.FeatureService;

@ -2,6 +2,7 @@ package cc.fascinated.bat.features.birthday;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.birthday.command.BirthdayCommand;
import cc.fascinated.bat.features.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.model.BatGuild;
@ -22,7 +23,7 @@ public class BirthdayFeature extends Feature implements EventListener {
private final GuildService guildService;
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
super("Birthday", true);
super("Birthday", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;
registerCommand(commandService, context.getBean(BirthdayCommand.class));

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.counter;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.counter.command.CounterCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
public class CounterFeature extends Feature {
@Autowired
public CounterFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Counter", true);
super("Counter", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(CounterCommand.class));
}

@ -1,7 +1,7 @@
package cc.fascinated.bat.features.counter;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.NonNull;

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.drag;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.drag.command.DragCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
public class DragFeature extends Feature {
@Autowired
public DragFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Drag", true);
super("Drag", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(DragCommand.class));
}

@ -2,7 +2,7 @@ package cc.fascinated.bat.features.logging;
import cc.fascinated.bat.common.PasteUtils;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.logging.command.LogsCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.service.CommandService;
@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
public class LogFeature extends Feature {
@Autowired
public LogFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Logging", true);
super("Logging", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(LogsCommand.class));
}

@ -2,6 +2,7 @@ package cc.fascinated.bat.features.messagesnipe;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.messagesnipe.command.MessageSnipeCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
@ -29,7 +30,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
@Autowired
public MessageSnipeFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Message Snipe", false);
super("Message Snipe", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(MessageSnipeCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.moderation;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.moderation.command.PurgeCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
public class ModerationFeature extends Feature {
@Autowired
public ModerationFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Moderation", true);
super("Moderation", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(PurgeCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.namehistory;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.namehistory.command.NameHistoryCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -17,7 +18,7 @@ public class NameHistoryFeature extends Feature {
@Autowired
public NameHistoryFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Name History", true);
super("Name History", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(NameHistoryCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.reminder;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.reminder.command.ReminderCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.service.CommandService;
@ -36,7 +37,7 @@ public class ReminderFeature extends Feature {
@Autowired
public ReminderFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
super("Reminder", true);
super("Reminder", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;
super.registerCommand(commandService, context.getBean(ReminderCommand.class));

@ -5,6 +5,7 @@ import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberFormatter;
import cc.fascinated.bat.common.ScoreSaberUtils;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand;
import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand;
import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand;
@ -25,7 +26,7 @@ import org.springframework.stereotype.Component;
public class ScoreSaberFeature extends Feature {
@Autowired
public ScoreSaberFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("ScoreSaber", true);
super("ScoreSaber", FeatureProfile.FeatureState.DISABLED, true);
registerCommand(commandService, context.getBean(ScoreSaberCommand.class));
registerCommand(commandService, context.getBean(UserFeedCommand.class));

@ -5,6 +5,7 @@ import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.SpotifyUtils;
import cc.fascinated.bat.exception.BatException;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.spotify.command.SpotifyCommand;
import cc.fascinated.bat.features.spotify.profile.SpotifyProfile;
import cc.fascinated.bat.model.BatUser;
@ -28,7 +29,7 @@ import se.michaelthelin.spotify.model_objects.specification.Track;
public class SpotifyFeature extends Feature {
@Autowired
public SpotifyFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Spotify", true);
super("Spotify", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(SpotifyCommand.class));
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.welcomer;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.welcomer.command.WelcomerCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
public class WelcomerFeature extends Feature {
@Autowired
public WelcomerFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Welcomer", true);
super("Welcomer", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(WelcomerCommand.class));
}

@ -3,7 +3,7 @@ package cc.fascinated.bat.model;
import cc.fascinated.bat.BatApplication;
import cc.fascinated.bat.common.ProfileHolder;
import cc.fascinated.bat.common.Serializable;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.features.counter.CounterProfile;
import cc.fascinated.bat.features.logging.LogProfile;

@ -5,7 +5,7 @@ import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.Category;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.config.Config;
import cc.fascinated.bat.features.base.profile.FeatureProfile;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.Getter;
@ -36,6 +36,8 @@ import java.util.stream.Collectors;
@Getter
@DependsOn("discordService")
public class CommandService extends ListenerAdapter {
public static CommandService INSTANCE;
/**
* The registered commands
*/
@ -53,6 +55,7 @@ public class CommandService extends ListenerAdapter {
@Autowired
public CommandService(@NonNull GuildService guildService, @NonNull UserService userService) {
INSTANCE = this;
this.guildService = guildService;
this.userService = userService;
DiscordService.JDA.addEventListener(this);
@ -137,6 +140,21 @@ public class CommandService extends ListenerAdapter {
return commands.values().stream().filter(command -> command.getInfo().getCategory() == category).toList();
}
/**
* Gets a command by its class
*
* @param clazz The class of the command
* @return The command
*/
public BatCommand getCommand(Class<? extends BatCommand> clazz) {
for (Map.Entry<String, BatCommand> entry : this.commands.entrySet()) {
if (entry.getValue().getClass().equals(clazz)) {
return entry.getValue();
}
}
return null;
}
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getUser().isBot()) {

@ -1,13 +1,20 @@
package cc.fascinated.bat.service;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TimerUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.base.commands.general.HelpCommand;
import cc.fascinated.bat.features.base.commands.server.feature.FeatureCommand;
import cc.fascinated.bat.features.base.commands.server.feature.ListSubCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.premium.PremiumProfile;
import com.mongodb.client.model.Filters;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
@ -103,6 +110,29 @@ public class GuildService extends ListenerAdapter implements EventListener {
public final void onGuildJoin(GuildJoinEvent event) {
BatGuild guild = getGuild(event.getGuild().getId());
log.info("Joined guild \"{}\"", guild.getName());
// Send a welcome message to the guild
DefaultGuildChannelUnion defaultChannel = event.getGuild().getDefaultChannel();
if (defaultChannel == null) {
return;
}
TextChannel channel = defaultChannel.asTextChannel();
BatCommand featureCommand = CommandService.INSTANCE.getCommand(FeatureCommand.class);
BatCommand listSubCommand = featureCommand.getSubCommand(ListSubCommand.class);
channel.sendMessageEmbeds(EmbedUtils.genericEmbed()
.setDescription("""
Hello! I'm %s, thank you for inviting me to your server!
To get started, use the </%s> command to see all the commands I have to offer!
Most of my features are disabled by default, view my features with </%s %s:%s>
""".formatted(
DiscordService.JDA.getSelfUser().getAsMention(),
CommandService.INSTANCE.getCommand(HelpCommand.class).getSnowflake(),
featureCommand.getSnowflake(),
listSubCommand.getInfo().getName(),
listSubCommand.getSnowflake()
))
.build()).queue();
}
@Override