diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index f466360..1b40ac5 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -13,19 +13,6 @@ import org.springframework.context.ConfigurableApplicationContext; import wtf.beatrice.hidekobot.commands.completer.ProfileImageCommandCompleter; import wtf.beatrice.hidekobot.commands.message.*; import wtf.beatrice.hidekobot.commands.slash.*; -import wtf.beatrice.hidekobot.commands.slash.SlashBanCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashBannerCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashClearCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashCoinFlipCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashDiceRollCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashInviteCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashKickCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashLoveCalculatorCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashMagicBallCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashSayCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashTimeoutCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashTriviaCommand; -import wtf.beatrice.hidekobot.commands.slash.SlashUrbanDictionaryCommand; import wtf.beatrice.hidekobot.datasources.ConfigurationSource; import wtf.beatrice.hidekobot.datasources.PropertiesSource; import wtf.beatrice.hidekobot.listeners.*; @@ -163,48 +150,48 @@ public class HidekoBot MessageCommandListener messageCommandListener = context.getBean(MessageCommandListener.class); ButtonInteractionListener buttonInteractionListener = context.getBean(ButtonInteractionListener.class); SelectMenuInteractionListener selectMenuInteractionListener = context.getBean(SelectMenuInteractionListener.class); - SlashAvatarCommand slashAvatarCommand = new SlashAvatarCommand(); + SlashAvatarCommand slashAvatarCommand = context.getBean(SlashAvatarCommand.class); ProfileImageCommandCompleter avatarCommandCompleter = new ProfileImageCommandCompleter(slashAvatarCommand); slashCommandListener.registerCommand(slashAvatarCommand); slashCommandCompletionListener.registerCommandCompleter(avatarCommandCompleter); - slashCommandListener.registerCommand(new SlashBanCommand()); - SlashBannerCommand slashBannerCommand = new SlashBannerCommand(); + slashCommandListener.registerCommand(context.getBean(SlashBanCommand.class)); + SlashBannerCommand slashBannerCommand = context.getBean(SlashBannerCommand.class); ProfileImageCommandCompleter bannerCommandCompleter = new ProfileImageCommandCompleter(slashBannerCommand); slashCommandListener.registerCommand(slashBannerCommand); slashCommandCompletionListener.registerCommandCompleter(bannerCommandCompleter); slashCommandListener.registerCommand(context.getBean(SlashBotInfoCommand.class)); - slashCommandListener.registerCommand(new SlashClearCommand()); - slashCommandListener.registerCommand(new SlashCoinFlipCommand()); - slashCommandListener.registerCommand(new SlashDiceRollCommand()); + slashCommandListener.registerCommand(context.getBean(SlashClearCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashCoinFlipCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashDiceRollCommand.class)); slashCommandListener.registerCommand(new SlashDieCommand()); slashCommandListener.registerCommand(new SlashHelpCommand()); - slashCommandListener.registerCommand(new SlashInviteCommand()); - slashCommandListener.registerCommand(new SlashKickCommand()); - slashCommandListener.registerCommand(new SlashLoveCalculatorCommand()); - slashCommandListener.registerCommand(new SlashMagicBallCommand()); + slashCommandListener.registerCommand(context.getBean(SlashInviteCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashKickCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashLoveCalculatorCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashMagicBallCommand.class)); slashCommandListener.registerCommand(new SlashPingCommand()); - slashCommandListener.registerCommand(new SlashSayCommand()); - slashCommandListener.registerCommand(new SlashTimeoutCommand()); + slashCommandListener.registerCommand(context.getBean(SlashSayCommand.class)); + slashCommandListener.registerCommand(context.getBean(SlashTimeoutCommand.class)); slashCommandListener.registerCommand(new SlashTriviaCommand()); slashCommandListener.registerCommand(new SlashUrbanDictionaryCommand()); // register message commands messageCommandListener.registerCommand(new MessageHelloCommand()); messageCommandListener.registerCommand(context.getBean(MessageAliasCommand.class)); - messageCommandListener.registerCommand(new MessageAvatarCommand()); - messageCommandListener.registerCommand(new MessageBanCommand()); - messageCommandListener.registerCommand(new MessageBannerCommand()); + messageCommandListener.registerCommand(context.getBean(MessageAvatarCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageBanCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageBannerCommand.class)); messageCommandListener.registerCommand(context.getBean(MessageBotInfoCommand.class)); - messageCommandListener.registerCommand(new MessageCoinFlipCommand()); - messageCommandListener.registerCommand(new MessageClearCommand()); - messageCommandListener.registerCommand(new MessageDiceRollCommand()); + messageCommandListener.registerCommand(context.getBean(MessageCoinFlipCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageClearCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageDiceRollCommand.class)); messageCommandListener.registerCommand(context.getBean(MessageHelpCommand.class)); - messageCommandListener.registerCommand(new MessageInviteCommand()); - messageCommandListener.registerCommand(new MessageKickCommand()); - messageCommandListener.registerCommand(new MessageLoveCalculatorCommand()); - messageCommandListener.registerCommand(new MessageMagicBallCommand()); - messageCommandListener.registerCommand(new MessageSayCommand()); - messageCommandListener.registerCommand(new MessageTimeoutCommand()); + messageCommandListener.registerCommand(context.getBean(MessageInviteCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageKickCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageLoveCalculatorCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageMagicBallCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageSayCommand.class)); + messageCommandListener.registerCommand(context.getBean(MessageTimeoutCommand.class)); messageCommandListener.registerCommand(new MessageTriviaCommand()); messageCommandListener.registerCommand(new MessageUrbanDictionaryCommand()); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java index 09b57cc..2dfdb9c 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java @@ -8,33 +8,30 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; +@Component public class ClearChat { - private ClearChat() - { - throw new IllegalStateException("Utility class"); - } - - public static String getLabel() + public String getLabel() { return "clear"; } - public static String getDescription() + public String getDescription() { return "Clear the current channel's chat."; } - public static Permission getPermission() + public Permission getPermission() { return Permission.MESSAGE_MANAGE; } - public static String checkDMs(Channel channel) + public String checkDMs(Channel channel) { if (!(channel instanceof TextChannel)) { @@ -44,7 +41,7 @@ public class ClearChat return null; } - public static String checkDeleteAmount(int toDeleteAmount) + public String checkDeleteAmount(int toDeleteAmount) { if (toDeleteAmount <= 0) { @@ -54,9 +51,9 @@ public class ClearChat return null; } - public static int delete(int toDeleteAmount, - long startingMessageId, - MessageChannel channel) + public int delete(int toDeleteAmount, + long startingMessageId, + MessageChannel channel) { // int to keep track of how many messages we actually deleted. int deleted = 0; @@ -158,13 +155,13 @@ public class ClearChat return deleted; } - public static Button getDismissButton() + public Button getDismissButton() { return Button.primary("generic_dismiss", "Dismiss") .withEmoji(Emoji.fromUnicode("❌")); } - public static String parseAmount(int deleted) + public String parseAmount(int deleted) { if (deleted < 1) @@ -180,7 +177,7 @@ public class ClearChat } // cap the amount to avoid abuse. - public static int getMaxAmount() + public int getMaxAmount() { return 1000; } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java index 5715179..67c9412 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java @@ -6,27 +6,23 @@ import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.util.RandomUtil; import java.util.ArrayList; import java.util.List; +@Component public class CoinFlip { - - private CoinFlip() - { - throw new IllegalStateException("Utility class"); - } - - public static Button getReflipButton() + public Button getReflipButton() { return Button.primary("coinflip_reflip", "Flip again") .withEmoji(Emoji.fromUnicode("\uD83E\uDE99")); } - public static String genRandom() + public String genRandom() { int rand = RandomUtil.getRandomNumber(0, 1); String msg; @@ -42,7 +38,7 @@ public class CoinFlip return msg; } - public static void buttonReFlip(ButtonInteractionEvent event) + public void buttonReFlip(ButtonInteractionEvent event) { // Ack ASAP to avoid 3s timeout event.deferEdit().queue(hook -> { @@ -86,7 +82,7 @@ public class CoinFlip }); } - public static void trackAndRestrict(Message replyMessage, User user) + public void trackAndRestrict(Message replyMessage, User user) { Cache.getServices().databaseService().queueDisabling(replyMessage); Cache.getServices().databaseService().trackRanCommandReply(replyMessage, user); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java index 29ece0d..6da4bbd 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java @@ -2,6 +2,7 @@ package wtf.beatrice.hidekobot.commands.base; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.objects.MessageResponse; import wtf.beatrice.hidekobot.objects.fun.Dice; @@ -12,15 +13,11 @@ import java.util.LinkedList; import java.util.Map; import java.util.UUID; +@Component public class DiceRoll { - private DiceRoll() - { - throw new IllegalStateException("Utility class"); - } - - public static MessageResponse buildResponse(User author, String[] args) + public MessageResponse buildResponse(User author, String[] args) { LinkedHashMap dicesToRoll = new LinkedHashMap<>(); String diceRegex = "d\\d+"; diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java index 1ad237d..8aa1bb2 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java @@ -4,18 +4,15 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.HidekoBot; +@Component public class Invite { - private Invite() - { - throw new IllegalStateException("Utility class"); - } - - public static MessageEmbed generateEmbed() + public MessageEmbed generateEmbed() { EmbedBuilder embedBuilder = new EmbedBuilder(); @@ -33,7 +30,7 @@ public class Invite return embedBuilder.build(); } - public static Button getInviteButton() + public Button getInviteButton() { String inviteUrl = Cache.getInviteUrl(); return Button.link(inviteUrl, "Invite " + Cache.getBotName()) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java index edea6bc..ae33739 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java @@ -3,20 +3,17 @@ package wtf.beatrice.hidekobot.commands.base; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.util.RandomUtil; import java.util.concurrent.TimeUnit; +@Component public class LoveCalculator { - private LoveCalculator() - { - throw new IllegalStateException("Utility class"); - } - - public static MessageEmbed buildEmbedAndCacheResult(User author, User user1, User user2) + public MessageEmbed buildEmbedAndCacheResult(User author, User user1, User user2) { String userId1 = user1.getId(); String userId2 = user2.getId(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java index e78a784..0a694ba 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java @@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot.commands.base; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.util.RandomUtil; @@ -11,20 +12,16 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +@Component public class MagicBall { - private MagicBall() - { - throw new IllegalStateException("Utility class"); - } - - public static LinkedList getLabels() + public LinkedList getLabels() { return new LinkedList<>(Arrays.asList("8ball", "8b", "eightball", "magicball")); } - private static final List answers = new ArrayList<>( + private final List answers = new ArrayList<>( Arrays.asList("It is certain.", "It is decidedly so.", "Without a doubt.", @@ -46,13 +43,13 @@ public class MagicBall "Outlook not so good.", "Very doubtful.")); - public static String getRandomAnswer() + public String getRandomAnswer() { int answerPos = RandomUtil.getRandomNumber(0, answers.size() - 1); return answers.get(answerPos); } - public static MessageEmbed generateEmbed(String question, User author) + public MessageEmbed generateEmbed(String question, User author) { // add a question mark at the end, if missing. // this might not always apply but it's fun diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java index afa79f0..9ad9e15 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java @@ -3,18 +3,15 @@ package wtf.beatrice.hidekobot.commands.base; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.utils.ImageProxy; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.objects.MessageResponse; +@Component public class ProfileImage { - private ProfileImage() - { - throw new IllegalStateException("Utility class"); - } - - public static int parseResolution(int resolution) + public int parseResolution(int resolution) { int[] acceptedSizes = Cache.getSupportedAvatarResolutions(); @@ -34,7 +31,7 @@ public class ProfileImage return acceptedSizes[idx]; } - public static MessageResponse buildResponse(int resolution, User user, ImageType imageType) + public MessageResponse buildResponse(int resolution, User user, ImageType imageType) { String imageTypeName = imageType.name().toLowerCase(); String resolutionString; diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java index a758ab5..3448826 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java @@ -1,16 +1,12 @@ package wtf.beatrice.hidekobot.commands.base; import net.dv8tion.jda.api.Permission; +import org.springframework.stereotype.Component; +@Component public class Say { - - private Say() - { - throw new IllegalStateException("Utility class"); - } - - public static Permission getPermission() + public Permission getPermission() { return Permission.MESSAGE_MANAGE; } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java index ec6be63..28c4457 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.requests.restaction.AuditableRestAction; import org.apache.commons.lang3.ArrayUtils; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.objects.MessageResponse; @@ -24,18 +25,14 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; +@Component public class UserPunishment { - private UserPunishment() - { - throw new IllegalStateException("Utility class"); - } - private static final Duration maxTimeoutDuration = Duration.of(28, ChronoUnit.DAYS); private static final Duration minTimeoutDuration = Duration.of(30, ChronoUnit.SECONDS); - public static void handle(SlashCommandInteractionEvent event, PunishmentType punishmentType) + public void handle(SlashCommandInteractionEvent event, PunishmentType punishmentType) { // this might take a sec event.deferReply().queue(); @@ -92,7 +89,7 @@ public class UserPunishment event.getHook().editOriginal(response.content()).queue(); } - public static void handle(MessageReceivedEvent event, String[] args, PunishmentType punishmentType) + public void handle(MessageReceivedEvent event, String[] args, PunishmentType punishmentType) { Mentions msgMentions = event.getMessage().getMentions(); List mentions = msgMentions.getMentions(); @@ -109,11 +106,11 @@ public class UserPunishment event.getMessage().reply(response.content()).queue(); } - public static MessageResponse getResponse(User author, - PunishmentType punishmentType, - MessageChannelUnion channel, - List mentions, - String[] args) + public MessageResponse getResponse(User author, + PunishmentType punishmentType, + MessageChannelUnion channel, + List mentions, + String[] args) { String punishmentTypeName = punishmentType.name().toLowerCase(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageAvatarCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageAvatarCommand.java index 60989c4..4cfca03 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageAvatarCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageAvatarCommand.java @@ -6,6 +6,8 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.commands.base.ProfileImage; import wtf.beatrice.hidekobot.objects.MessageResponse; @@ -16,8 +18,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageAvatarCommand implements MessageCommand { + private final ProfileImage profileImage; + + public MessageAvatarCommand(@Autowired ProfileImage profileImage) + { + this.profileImage = profileImage; + } @Override public LinkedList getCommandLabels() @@ -74,7 +83,7 @@ public class MessageAvatarCommand implements MessageCommand try { int givenRes = Integer.parseInt(arg); - resolution = ProfileImage.parseResolution(givenRes); + resolution = profileImage.parseResolution(givenRes); resFound = true; break; } catch (NumberFormatException ignored) @@ -84,7 +93,7 @@ public class MessageAvatarCommand implements MessageCommand } // fallback in case we didn't find any specified resolution - if (!resFound) resolution = ProfileImage.parseResolution(512); + if (!resFound) resolution = profileImage.parseResolution(512); // check if someone is mentioned Mentions mentions = event.getMessage().getMentions(); @@ -101,7 +110,7 @@ public class MessageAvatarCommand implements MessageCommand if (user == null) user = event.getAuthor(); // send a response - MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR); + MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR); if (response.content() != null) { event.getMessage().reply(response.content()).queue(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBanCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBanCommand.java index 8e97326..36c4864 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBanCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBanCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -13,8 +15,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageBanCommand implements MessageCommand { + private final UserPunishment userPunishment; + + public MessageBanCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } @Override public LinkedList getCommandLabels() @@ -59,6 +68,6 @@ public class MessageBanCommand implements MessageCommand @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { - UserPunishment.handle(event, args, UserPunishment.PunishmentType.BAN); + userPunishment.handle(event, args, UserPunishment.PunishmentType.BAN); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBannerCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBannerCommand.java index f191ebd..e5dd3b7 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBannerCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageBannerCommand.java @@ -6,6 +6,8 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.commands.base.ProfileImage; import wtf.beatrice.hidekobot.objects.MessageResponse; @@ -16,8 +18,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageBannerCommand implements MessageCommand { + private final ProfileImage profileImage; + + public MessageBannerCommand(@Autowired ProfileImage profileImage) + { + this.profileImage = profileImage; + } @Override public LinkedList getCommandLabels() @@ -74,7 +83,7 @@ public class MessageBannerCommand implements MessageCommand try { int givenRes = Integer.parseInt(arg); - resolution = ProfileImage.parseResolution(givenRes); + resolution = profileImage.parseResolution(givenRes); resFound = true; break; } catch (NumberFormatException ignored) @@ -84,7 +93,7 @@ public class MessageBannerCommand implements MessageCommand } // fallback in case we didn't find any specified resolution - if (!resFound) resolution = ProfileImage.parseResolution(512); + if (!resFound) resolution = profileImage.parseResolution(512); // check if someone is mentioned Mentions mentions = event.getMessage().getMentions(); @@ -101,7 +110,7 @@ public class MessageBannerCommand implements MessageCommand if (user == null) user = event.getAuthor(); // send a response - MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER); + MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER); if (response.content() != null) { event.getMessage().reply(response.content()).queue(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageClearCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageClearCommand.java index cc6a878..2047cb7 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageClearCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageClearCommand.java @@ -6,6 +6,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.commands.base.ClearChat; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; @@ -15,19 +17,27 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageClearCommand implements MessageCommand { + private final ClearChat clearChat; + + public MessageClearCommand(@Autowired ClearChat clearChat) + { + this.clearChat = clearChat; + } + @Override public LinkedList getCommandLabels() { - return new LinkedList<>(Collections.singletonList(ClearChat.getLabel())); + return new LinkedList<>(Collections.singletonList(clearChat.getLabel())); } @Override public List getPermissions() { - return Collections.singletonList(ClearChat.getPermission()); + return Collections.singletonList(clearChat.getPermission()); } @Override @@ -61,7 +71,7 @@ public class MessageClearCommand implements MessageCommand public void runCommand(MessageReceivedEvent event, String label, String[] args) { // check if user is trying to run command in dms. - String error = ClearChat.checkDMs(event.getChannel()); + String error = clearChat.checkDMs(event.getChannel()); if (error != null) { event.getMessage().reply(error).queue(); @@ -83,9 +93,9 @@ public class MessageClearCommand implements MessageCommand } // cap the amount to avoid abuse. - if (toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0; + if (toDeleteAmount > clearChat.getMaxAmount()) toDeleteAmount = 0; - error = ClearChat.checkDeleteAmount(toDeleteAmount); + error = clearChat.checkDeleteAmount(toDeleteAmount); if (error != null) { event.getMessage().reply(error).queue(); @@ -96,15 +106,15 @@ public class MessageClearCommand implements MessageCommand String content = "\uD83D\uDEA7 Clearing..."; Message botMessage = event.getMessage().reply(content).complete(); - int deleted = ClearChat.delete(toDeleteAmount, + int deleted = clearChat.delete(toDeleteAmount, event.getMessageIdLong(), event.getChannel()); // get a nicely formatted message that logs the deletion of messages. - content = ClearChat.parseAmount(deleted); + content = clearChat.parseAmount(deleted); // edit the message text and attach a button. - Button dismiss = ClearChat.getDismissButton(); + Button dismiss = clearChat.getDismissButton(); Message finalMessage = event.getChannel().sendMessage(content).setActionRow(dismiss).complete(); // add the message to database. diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageCoinFlipCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageCoinFlipCommand.java index 64ae492..659c0d6 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageCoinFlipCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageCoinFlipCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.CoinFlip; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -12,9 +14,17 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +@Component public class MessageCoinFlipCommand implements MessageCommand { + private final CoinFlip coinFlip; + + public MessageCoinFlipCommand(@Autowired CoinFlip coinFlip) + { + this.coinFlip = coinFlip; + } + @Override public LinkedList getCommandLabels() { @@ -60,12 +70,12 @@ public class MessageCoinFlipCommand implements MessageCommand { // perform coin flip - event.getMessage().reply(CoinFlip.genRandom()) - .addActionRow(CoinFlip.getReflipButton()) + event.getMessage().reply(coinFlip.genRandom()) + .addActionRow(coinFlip.getReflipButton()) .queue((message) -> { // set the command as expiring and restrict it to the user who ran it - CoinFlip.trackAndRestrict(message, event.getAuthor()); + coinFlip.trackAndRestrict(message, event.getAuthor()); }, (error) -> { }); } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageDiceRollCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageDiceRollCommand.java index 72552e1..072c3ba 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageDiceRollCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageDiceRollCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.DiceRoll; import wtf.beatrice.hidekobot.objects.MessageResponse; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; @@ -13,8 +15,16 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +@Component public class MessageDiceRollCommand implements MessageCommand { + private final DiceRoll diceRoll; + + public MessageDiceRollCommand(@Autowired DiceRoll diceRoll) + { + this.diceRoll = diceRoll; + } + @Override public LinkedList getCommandLabels() { @@ -66,7 +76,7 @@ public class MessageDiceRollCommand implements MessageCommand public void runCommand(MessageReceivedEvent event, String label, String[] args) { - MessageResponse response = DiceRoll.buildResponse(event.getAuthor(), args); + MessageResponse response = diceRoll.buildResponse(event.getAuthor(), args); if (response.content() != null) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageInviteCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageInviteCommand.java index 517c1b4..56b313d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageInviteCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageInviteCommand.java @@ -7,6 +7,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.Invite; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -15,8 +17,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageInviteCommand implements MessageCommand { + private final Invite invite; + + public MessageInviteCommand(@Autowired Invite invite) + { + this.invite = invite; + } @Override public LinkedList getCommandLabels() @@ -63,8 +72,8 @@ public class MessageInviteCommand implements MessageCommand { - MessageEmbed inviteEmbed = Invite.generateEmbed(); - Button inviteButton = Invite.getInviteButton(); + MessageEmbed inviteEmbed = invite.generateEmbed(); + Button inviteButton = invite.getInviteButton(); // if this is a guild, don't spam the invite in public but DM it if (event.getChannelType().isGuild()) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageKickCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageKickCommand.java index 1353d29..445e6d2 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageKickCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageKickCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -13,8 +15,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageKickCommand implements MessageCommand { + private final UserPunishment userPunishment; + + public MessageKickCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } @Override public LinkedList getCommandLabels() @@ -59,6 +68,6 @@ public class MessageKickCommand implements MessageCommand @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { - UserPunishment.handle(event, args, UserPunishment.PunishmentType.KICK); + userPunishment.handle(event, args, UserPunishment.PunishmentType.KICK); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageLoveCalculatorCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageLoveCalculatorCommand.java index 5f62762..b087cb3 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageLoveCalculatorCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageLoveCalculatorCommand.java @@ -8,6 +8,8 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.commands.base.LoveCalculator; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; @@ -17,8 +19,15 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +@Component public class MessageLoveCalculatorCommand implements MessageCommand { + private final LoveCalculator loveCalculator; + + public MessageLoveCalculatorCommand(@Autowired LoveCalculator loveCalculator) + { + this.loveCalculator = loveCalculator; + } @Override @@ -91,7 +100,7 @@ public class MessageLoveCalculatorCommand implements MessageCommand user2 = HidekoBot.getAPI().retrieveUserById(mentionedUserId).complete(); } - MessageEmbed embed = LoveCalculator.buildEmbedAndCacheResult(event.getAuthor(), user1, user2); + MessageEmbed embed = loveCalculator.buildEmbedAndCacheResult(event.getAuthor(), user1, user2); event.getChannel().sendMessageEmbeds(embed).queue(); } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageMagicBallCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageMagicBallCommand.java index a2222aa..3659601 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageMagicBallCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageMagicBallCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.MagicBall; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -11,13 +13,20 @@ import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.LinkedList; import java.util.List; +@Component public class MessageMagicBallCommand implements MessageCommand { + private final MagicBall magicBall; + + public MessageMagicBallCommand(@Autowired MagicBall magicBall) + { + this.magicBall = magicBall; + } @Override public LinkedList getCommandLabels() { - return MagicBall.getLabels(); + return magicBall.getLabels(); } @Nullable @@ -75,6 +84,6 @@ public class MessageMagicBallCommand implements MessageCommand String question = questionBuilder.toString(); - event.getChannel().sendMessageEmbeds(MagicBall.generateEmbed(question, event.getAuthor())).queue(); + event.getChannel().sendMessageEmbeds(magicBall.generateEmbed(question, event.getAuthor())).queue(); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageSayCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageSayCommand.java index 9cc3181..54dd2bd 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageSayCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageSayCommand.java @@ -5,6 +5,8 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.Say; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -13,9 +15,16 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageSayCommand implements MessageCommand { + private final Say say; + + public MessageSayCommand(@Autowired Say say) + { + this.say = say; + } @Override public LinkedList getCommandLabels() @@ -27,7 +36,7 @@ public class MessageSayCommand implements MessageCommand @Override public List getPermissions() { - return Collections.singletonList(Say.getPermission()); + return Collections.singletonList(say.getPermission()); } @Override diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageTimeoutCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageTimeoutCommand.java index bcaa6e9..a31bb58 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageTimeoutCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MessageTimeoutCommand.java @@ -4,6 +4,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; @@ -13,8 +15,15 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +@Component public class MessageTimeoutCommand implements MessageCommand { + private final UserPunishment userPunishment; + + public MessageTimeoutCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } @Override public LinkedList getCommandLabels() @@ -59,6 +68,6 @@ public class MessageTimeoutCommand implements MessageCommand @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { - UserPunishment.handle(event, args, UserPunishment.PunishmentType.TIMEOUT); + userPunishment.handle(event, args, UserPunishment.PunishmentType.TIMEOUT); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashAvatarCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashAvatarCommand.java index 2b6947b..fab3092 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashAvatarCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashAvatarCommand.java @@ -7,12 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.ProfileImage; import wtf.beatrice.hidekobot.objects.MessageResponse; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashAvatarCommand extends SlashCommandImpl { + private final ProfileImage profileImage; + + public SlashAvatarCommand(@NotNull ProfileImage profileImage) + { + this.profileImage = profileImage; + } + @Override public CommandData getSlashCommandData() { @@ -44,13 +53,13 @@ public class SlashAvatarCommand extends SlashCommandImpl OptionMapping sizeArg = event.getOption("size"); if (sizeArg != null) { - resolution = ProfileImage.parseResolution(sizeArg.getAsInt()); + resolution = profileImage.parseResolution(sizeArg.getAsInt()); } else { - resolution = ProfileImage.parseResolution(512); + resolution = profileImage.parseResolution(512); } - MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR); + MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR); if (response.content() != null) { event.getHook().editOriginal(response.content()).queue(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBanCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBanCommand.java index d34bdcf..81d331a 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBanCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBanCommand.java @@ -7,11 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashBanCommand extends SlashCommandImpl { + private final UserPunishment userPunishment; + + public SlashBanCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } + @Override public CommandData getSlashCommandData() { @@ -31,6 +41,6 @@ public class SlashBanCommand extends SlashCommandImpl @Override public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) { - UserPunishment.handle(event, UserPunishment.PunishmentType.BAN); + userPunishment.handle(event, UserPunishment.PunishmentType.BAN); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBannerCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBannerCommand.java index 9352d55..2b229cf 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBannerCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashBannerCommand.java @@ -7,12 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.ProfileImage; import wtf.beatrice.hidekobot.objects.MessageResponse; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashBannerCommand extends SlashCommandImpl { + private final ProfileImage profileImage; + + public SlashBannerCommand(@NotNull ProfileImage profileImage) + { + this.profileImage = profileImage; + } + @Override public CommandData getSlashCommandData() { @@ -44,13 +53,13 @@ public class SlashBannerCommand extends SlashCommandImpl OptionMapping sizeArg = event.getOption("size"); if (sizeArg != null) { - resolution = ProfileImage.parseResolution(sizeArg.getAsInt()); + resolution = profileImage.parseResolution(sizeArg.getAsInt()); } else { - resolution = ProfileImage.parseResolution(512); + resolution = profileImage.parseResolution(512); } - MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER); + MessageResponse response = profileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER); if (response.content() != null) { event.getHook().editOriginal(response.content()).queue(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashClearCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashClearCommand.java index a39f613..de67ba2 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashClearCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashClearCommand.java @@ -9,20 +9,29 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.commands.base.ClearChat; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashClearCommand extends SlashCommandImpl { + private final ClearChat clearChat; + + public SlashClearCommand(@Autowired ClearChat clearChat) + { + this.clearChat = clearChat; + } @Override public CommandData getSlashCommandData() { - return Commands.slash(ClearChat.getLabel(), - ClearChat.getDescription()) + return Commands.slash(clearChat.getLabel(), + clearChat.getDescription()) .addOption(OptionType.INTEGER, "amount", "The amount of messages to delete.") - .setDefaultPermissions(DefaultMemberPermissions.enabledFor(ClearChat.getPermission())); + .setDefaultPermissions(DefaultMemberPermissions.enabledFor(clearChat.getPermission())); } @Override @@ -32,7 +41,7 @@ public class SlashClearCommand extends SlashCommandImpl event.deferReply().queue(); // check if user is trying to run command in dms. - String error = ClearChat.checkDMs(event.getChannel()); + String error = clearChat.checkDMs(event.getChannel()); if (error != null) { event.getHook().editOriginal(error).queue(); @@ -46,9 +55,9 @@ public class SlashClearCommand extends SlashCommandImpl int toDeleteAmount = amountOption == null ? 1 : amountOption.getAsInt(); // cap the amount to avoid abuse. - if (toDeleteAmount > ClearChat.getMaxAmount()) toDeleteAmount = 0; + if (toDeleteAmount > clearChat.getMaxAmount()) toDeleteAmount = 0; - error = ClearChat.checkDeleteAmount(toDeleteAmount); + error = clearChat.checkDeleteAmount(toDeleteAmount); if (error != null) { event.getHook().editOriginal(error).queue(); @@ -60,15 +69,15 @@ public class SlashClearCommand extends SlashCommandImpl Message botMessage = event.getHook().editOriginal(content).complete(); // actually delete the messages. - int deleted = ClearChat.delete(toDeleteAmount, + int deleted = clearChat.delete(toDeleteAmount, event.getInteraction().getIdLong(), event.getChannel()); // get a nicely formatted message that logs the deletion of messages. - content = ClearChat.parseAmount(deleted); + content = clearChat.parseAmount(deleted); // edit the message text and attach a button. - Button dismiss = ClearChat.getDismissButton(); + Button dismiss = clearChat.getDismissButton(); botMessage = botMessage.editMessage(content).setActionRow(dismiss).complete(); // add the message to database. diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashCoinFlipCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashCoinFlipCommand.java index 4789f86..949a96a 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashCoinFlipCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashCoinFlipCommand.java @@ -4,11 +4,20 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.CoinFlip; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashCoinFlipCommand extends SlashCommandImpl { + private final CoinFlip coinFlip; + + public SlashCoinFlipCommand(@Autowired CoinFlip coinFlip) + { + this.coinFlip = coinFlip; + } @Override public CommandData getSlashCommandData() @@ -21,14 +30,14 @@ public class SlashCoinFlipCommand extends SlashCommandImpl public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) { // perform coin flip - event.reply(CoinFlip.genRandom()) - .addActionRow(CoinFlip.getReflipButton()) + event.reply(coinFlip.genRandom()) + .addActionRow(coinFlip.getReflipButton()) .queue((interaction) -> { // set the command as expiring and restrict it to the user who ran it interaction.retrieveOriginal().queue((message) -> { - CoinFlip.trackAndRestrict(message, event.getUser()); + coinFlip.trackAndRestrict(message, event.getUser()); }, (error) -> { }); }, (error) -> { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashDiceRollCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashDiceRollCommand.java index 3124d94..1c164b2 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashDiceRollCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashDiceRollCommand.java @@ -6,12 +6,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.DiceRoll; import wtf.beatrice.hidekobot.objects.MessageResponse; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashDiceRollCommand extends SlashCommandImpl { + private final DiceRoll diceRoll; + + public SlashDiceRollCommand(@NotNull DiceRoll diceRoll) + { + this.diceRoll = diceRoll; + } + @Override public CommandData getSlashCommandData() { @@ -37,7 +46,7 @@ public class SlashDiceRollCommand extends SlashCommandImpl String[] args = messageContent.split("\\s"); - MessageResponse response = DiceRoll.buildResponse(event.getUser(), args); + MessageResponse response = diceRoll.buildResponse(event.getUser(), args); if (response.content() != null) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashInviteCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashInviteCommand.java index 2101b1b..0b776b1 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashInviteCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashInviteCommand.java @@ -10,11 +10,19 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.Invite; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashInviteCommand extends SlashCommandImpl { + private final Invite invite; + + public SlashInviteCommand(@NotNull Invite invite) + { + this.invite = invite; + } @Override public CommandData getSlashCommandData() @@ -36,8 +44,8 @@ public class SlashInviteCommand extends SlashCommandImpl } replyCallbackAction.queue(); - MessageEmbed inviteEmbed = Invite.generateEmbed(); - Button inviteButton = Invite.getInviteButton(); + MessageEmbed inviteEmbed = invite.generateEmbed(); + Button inviteButton = invite.getInviteButton(); WebhookMessageEditAction reply = event.getHook() diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashKickCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashKickCommand.java index 507cdba..b69373d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashKickCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashKickCommand.java @@ -7,11 +7,22 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashKickCommand extends SlashCommandImpl { + + private final UserPunishment userPunishment; + + public SlashKickCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } + @Override public CommandData getSlashCommandData() { @@ -31,6 +42,6 @@ public class SlashKickCommand extends SlashCommandImpl @Override public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) { - UserPunishment.handle(event, UserPunishment.PunishmentType.KICK); + userPunishment.handle(event, UserPunishment.PunishmentType.KICK); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashLoveCalculatorCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashLoveCalculatorCommand.java index ecd349b..6316121 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashLoveCalculatorCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashLoveCalculatorCommand.java @@ -8,11 +8,20 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.LoveCalculator; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashLoveCalculatorCommand extends SlashCommandImpl { + private final LoveCalculator loveCalculator; + + public SlashLoveCalculatorCommand(@NotNull LoveCalculator loveCalculator) + { + this.loveCalculator = loveCalculator; + } + @Override public CommandData getSlashCommandData() { @@ -57,7 +66,7 @@ public class SlashLoveCalculatorCommand extends SlashCommandImpl secondUser = event.getUser(); } - MessageEmbed embed = LoveCalculator.buildEmbedAndCacheResult(event.getUser(), firstUser, secondUser); + MessageEmbed embed = loveCalculator.buildEmbedAndCacheResult(event.getUser(), firstUser, secondUser); event.replyEmbeds(embed).queue(); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashMagicBallCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashMagicBallCommand.java index 13bf001..4513766 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashMagicBallCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashMagicBallCommand.java @@ -7,16 +7,25 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.MagicBall; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashMagicBallCommand extends SlashCommandImpl { + private final MagicBall magicBall; + + public SlashMagicBallCommand(@NotNull MagicBall magicBall) + { + this.magicBall = magicBall; + } + @Override public CommandData getSlashCommandData() { - return Commands.slash(MagicBall.getLabels().get(0), + return Commands.slash(magicBall.getLabels().get(0), "Ask a question to the magic ball.") .addOption(OptionType.STRING, "question", "The question to ask.", @@ -43,7 +52,7 @@ public class SlashMagicBallCommand extends SlashCommandImpl return; } - MessageEmbed response = MagicBall.generateEmbed(question, event.getUser()); + MessageEmbed response = magicBall.generateEmbed(question, event.getUser()); event.replyEmbeds(response).queue(); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashSayCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashSayCommand.java index 22c140e..f8f16eb 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashSayCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashSayCommand.java @@ -8,11 +8,20 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.Say; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashSayCommand extends SlashCommandImpl { + private final Say say; + + public SlashSayCommand(@NotNull Say say) + { + this.say = say; + } + @Override public CommandData getSlashCommandData() { @@ -22,7 +31,7 @@ public class SlashSayCommand extends SlashCommandImpl "The message to send.", true, false) - .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Say.getPermission())); + .setDefaultPermissions(DefaultMemberPermissions.enabledFor(say.getPermission())); } @Override diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashTimeoutCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashTimeoutCommand.java index b67544b..40eb5da 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashTimeoutCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/slash/SlashTimeoutCommand.java @@ -7,11 +7,22 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.UserPunishment; import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl; +@Component public class SlashTimeoutCommand extends SlashCommandImpl { + + private final UserPunishment userPunishment; + + public SlashTimeoutCommand(@Autowired UserPunishment userPunishment) + { + this.userPunishment = userPunishment; + } + @Override public CommandData getSlashCommandData() { @@ -35,6 +46,6 @@ public class SlashTimeoutCommand extends SlashCommandImpl @Override public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) { - UserPunishment.handle(event, UserPunishment.PunishmentType.TIMEOUT); + userPunishment.handle(event, UserPunishment.PunishmentType.TIMEOUT); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java index 0f2e97a..7de3f99 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import wtf.beatrice.hidekobot.commands.base.CoinFlip; import wtf.beatrice.hidekobot.commands.base.Trivia; @@ -16,10 +17,13 @@ public class ButtonInteractionListener extends ListenerAdapter private static final Logger LOGGER = LoggerFactory.getLogger(ButtonInteractionListener.class); private final CommandService commandService; + private final CoinFlip coinFlip; - public ButtonInteractionListener(CommandService commandService) + public ButtonInteractionListener(@Autowired CommandService commandService, + @Autowired CoinFlip coinFlip) { this.commandService = commandService; + this.coinFlip = coinFlip; } @Override @@ -30,7 +34,7 @@ public class ButtonInteractionListener extends ListenerAdapter { // coinflip - case "coinflip_reflip" -> CoinFlip.buttonReFlip(event); + case "coinflip_reflip" -> coinFlip.buttonReFlip(event); // generic dismiss button case "generic_dismiss" -> commandService.deleteUserLinkedMessage(event);