From 0b09b8ba5f6b77a3648ea7312ac41b1b315b51fb Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 5 Jul 2024 19:33:10 +0100 Subject: [PATCH] default disable all features and add bot join guild message --- .../cc/fascinated/bat/command/BatCommand.java | 15 ++++++++++ .../cc/fascinated/bat/features/Feature.java | 5 ++++ .../{base/profile => }/FeatureProfile.java | 9 ++---- .../bat/features/afk/AfkFeature.java | 3 +- .../features/autorole/AutoRoleFeature.java | 3 +- .../bat/features/base/BaseFeature.java | 3 +- .../server/feature/DisableSubCommand.java | 2 +- .../server/feature/EnableSubCommand.java | 2 +- .../server/feature/ListSubCommand.java | 2 +- .../features/birthday/BirthdayFeature.java | 3 +- .../bat/features/counter/CounterFeature.java | 3 +- .../features/counter/CountingListener.java | 2 +- .../bat/features/drag/DragFeature.java | 3 +- .../bat/features/logging/LogFeature.java | 4 +-- .../messagesnipe/MessageSnipeFeature.java | 3 +- .../moderation/ModerationFeature.java | 3 +- .../namehistory/NameHistoryFeature.java | 3 +- .../features/reminder/ReminderFeature.java | 3 +- .../scoresaber/ScoreSaberFeature.java | 3 +- .../bat/features/spotify/SpotifyFeature.java | 3 +- .../features/welcomer/WelcomerFeature.java | 3 +- .../cc/fascinated/bat/model/BatGuild.java | 2 +- .../bat/service/CommandService.java | 20 ++++++++++++- .../fascinated/bat/service/GuildService.java | 30 +++++++++++++++++++ 24 files changed, 105 insertions(+), 27 deletions(-) rename src/main/java/cc/fascinated/bat/features/{base/profile => }/FeatureProfile.java (91%) diff --git a/src/main/java/cc/fascinated/bat/command/BatCommand.java b/src/main/java/cc/fascinated/bat/command/BatCommand.java index b74d557..2dd8623 100644 --- a/src/main/java/cc/fascinated/bat/command/BatCommand.java +++ b/src/main/java/cc/fascinated/bat/command/BatCommand.java @@ -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 clazz) { + for (Map.Entry entry : subCommands.entrySet()) { + if (entry.getValue().getClass().equals(clazz)) { + return entry.getValue(); + } + } + return null; + } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/Feature.java b/src/main/java/cc/fascinated/bat/features/Feature.java index a7f137c..d5b1607 100644 --- a/src/main/java/cc/fascinated/bat/features/Feature.java +++ b/src/main/java/cc/fascinated/bat/features/Feature.java @@ -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 */ diff --git a/src/main/java/cc/fascinated/bat/features/base/profile/FeatureProfile.java b/src/main/java/cc/fascinated/bat/features/FeatureProfile.java similarity index 91% rename from src/main/java/cc/fascinated/bat/features/base/profile/FeatureProfile.java rename to src/main/java/cc/fascinated/bat/features/FeatureProfile.java index be29cc2..6b37184 100644 --- a/src/main/java/cc/fascinated/bat/features/base/profile/FeatureProfile.java +++ b/src/main/java/cc/fascinated/bat/features/FeatureProfile.java @@ -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); } diff --git a/src/main/java/cc/fascinated/bat/features/afk/AfkFeature.java b/src/main/java/cc/fascinated/bat/features/afk/AfkFeature.java index bbc3df2..beeb634 100644 --- a/src/main/java/cc/fascinated/bat/features/afk/AfkFeature.java +++ b/src/main/java/cc/fascinated/bat/features/afk/AfkFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java b/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java index 9f635db..cff594b 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java index 4d02ac3..ee48d86 100644 --- a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java +++ b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java @@ -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)); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java index f1c7410..d743419 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java index ec1fa38..3da2f17 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java index f9f36aa..0c27723 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java b/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java index 534ed1c..fa58a27 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java @@ -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)); diff --git a/src/main/java/cc/fascinated/bat/features/counter/CounterFeature.java b/src/main/java/cc/fascinated/bat/features/counter/CounterFeature.java index 8610047..25abbd6 100644 --- a/src/main/java/cc/fascinated/bat/features/counter/CounterFeature.java +++ b/src/main/java/cc/fascinated/bat/features/counter/CounterFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/counter/CountingListener.java b/src/main/java/cc/fascinated/bat/features/counter/CountingListener.java index 97bc426..eede287 100644 --- a/src/main/java/cc/fascinated/bat/features/counter/CountingListener.java +++ b/src/main/java/cc/fascinated/bat/features/counter/CountingListener.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/features/drag/DragFeature.java b/src/main/java/cc/fascinated/bat/features/drag/DragFeature.java index d8bf0d1..597dc1a 100644 --- a/src/main/java/cc/fascinated/bat/features/drag/DragFeature.java +++ b/src/main/java/cc/fascinated/bat/features/drag/DragFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java b/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java index 403dd54..06ac076 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java index aa5b3d2..3c3099e 100644 --- a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java +++ b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/moderation/ModerationFeature.java b/src/main/java/cc/fascinated/bat/features/moderation/ModerationFeature.java index 2601752..fba6f3a 100644 --- a/src/main/java/cc/fascinated/bat/features/moderation/ModerationFeature.java +++ b/src/main/java/cc/fascinated/bat/features/moderation/ModerationFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/namehistory/NameHistoryFeature.java b/src/main/java/cc/fascinated/bat/features/namehistory/NameHistoryFeature.java index dbb888c..9ade3f0 100644 --- a/src/main/java/cc/fascinated/bat/features/namehistory/NameHistoryFeature.java +++ b/src/main/java/cc/fascinated/bat/features/namehistory/NameHistoryFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/reminder/ReminderFeature.java b/src/main/java/cc/fascinated/bat/features/reminder/ReminderFeature.java index 662ecfd..1a492a0 100644 --- a/src/main/java/cc/fascinated/bat/features/reminder/ReminderFeature.java +++ b/src/main/java/cc/fascinated/bat/features/reminder/ReminderFeature.java @@ -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)); diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java b/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java index 9ceb92f..51609c9 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/ScoreSaberFeature.java @@ -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)); diff --git a/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java b/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java index 772217f..0673d06 100644 --- a/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java +++ b/src/main/java/cc/fascinated/bat/features/spotify/SpotifyFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerFeature.java b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerFeature.java index 2232e05..1f0b1f4 100644 --- a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerFeature.java +++ b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerFeature.java @@ -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)); } diff --git a/src/main/java/cc/fascinated/bat/model/BatGuild.java b/src/main/java/cc/fascinated/bat/model/BatGuild.java index 85c0a17..b02fd00 100644 --- a/src/main/java/cc/fascinated/bat/model/BatGuild.java +++ b/src/main/java/cc/fascinated/bat/model/BatGuild.java @@ -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; diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 34804e9..2384460 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -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 clazz) { + for (Map.Entry 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()) { diff --git a/src/main/java/cc/fascinated/bat/service/GuildService.java b/src/main/java/cc/fascinated/bat/service/GuildService.java index ecacbe6..1db5755 100644 --- a/src/main/java/cc/fascinated/bat/service/GuildService.java +++ b/src/main/java/cc/fascinated/bat/service/GuildService.java @@ -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 command to see all the commands I have to offer! + + Most of my features are disabled by default, view my features with + """.formatted( + DiscordService.JDA.getSelfUser().getAsMention(), + CommandService.INSTANCE.getCommand(HelpCommand.class).getSnowflake(), + featureCommand.getSnowflake(), + listSubCommand.getInfo().getName(), + listSubCommand.getSnowflake() + )) + .build()).queue(); } @Override