From 8e1f32bdeb7107288624575cd9176b036d915f48 Mon Sep 17 00:00:00 2001 From: General-Mudkip Date: Sun, 8 Aug 2021 16:05:44 +0100 Subject: [PATCH 1/4] Added a purge command --- .../helpbot/bot/HelpBotInstance.java | 3 +- .../command/impl/other/mod/PurgeCommand.java | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 6a44cae5..e91da1ae 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -127,7 +127,8 @@ public static void initialize() throws LoginException { new EightBallCommand(), new OcrCommand(), new JoinsCommand(), - new TagCommand() + new TagCommand(), + new PurgeCommand() ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java new file mode 100644 index 00000000..c7851521 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java @@ -0,0 +1,59 @@ +package com.diamondfire.helpbot.bot.command.impl.other.mod; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import net.dv8tion.jda.api.entities.*; + +import java.util.List; + +public class PurgeCommand extends Command { + + @Override public String getName() { return "purge"; } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Removes the most recent messages sent in a channel. Maxiumum 100 messages.") + .category(CommandCategory.OTHER) + .addArgument( + new HelpContextArgument() + .name("count") + ); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet() + .addArgument("count", + new IntegerArgument()); + } + + @Override + public Permission getPermission() { + return Permission.MODERATION; + } + + @Override + public void run(CommandEvent event) { + PresetBuilder builder = new PresetBuilder(); + + int messagesToRemove = event.getArgument("count"); + + if (messagesToRemove > 100 || messagesToRemove < 0) { + builder.withPreset( + new InformativeReply(InformativeReplyType.ERROR, "Message count not within 0 to 100.") + ); + event.reply(builder); + } else { + TextChannel channel = event.getChannel(); + List messages = channel.getHistory().retrievePast(messagesToRemove).complete(); + channel.deleteMessages(messages).complete(); + } + } +} From 7d50ca788aa999f610952d179b2975c7f3808b66 Mon Sep 17 00:00:00 2001 From: General-Mudkip Date: Mon, 9 Aug 2021 20:02:22 +0100 Subject: [PATCH 2/4] Reformatted the command so that the author's tag is now in the title and the executor is in the footer. --- src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java index 1bd17f95..7ad5ba67 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java @@ -71,14 +71,14 @@ public JsonObject asJson() { return json; } - public void sendResponse(TextChannel channel) { + public void sendResponse(TextChannel channel, User requester) { User user = channel.getJDA().retrieveUserById(getAuthorId()).complete(); EmbedBuilder embed = new EmbedBuilder() - .setTitle(getTitle()) + .setTitle(getTitle()+" (*"+user.getAsTag()+"*)") .setDescription(getResponse()+"\n\u200b") .setColor(0x969dba) - .setFooter("Written by "+user.getAsTag(), user.getAvatarUrl()); + .setFooter("Executed by "+requester.getAsTag(), user.getAvatarUrl()); if (!getImage().equals("")) embed.setImage(getImage()); channel.sendMessageEmbeds(embed.build()).queue(); From 75160a52f754fef0511a4fff1fdb26dc4d27fbaa Mon Sep 17 00:00:00 2001 From: General-Mudkip Date: Mon, 9 Aug 2021 20:03:59 +0100 Subject: [PATCH 3/4] forgot a file --- .../diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java index 09f886de..6733b7fc 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java @@ -17,7 +17,7 @@ public boolean accept(Message message) { try { // Get Tag and send response Tag tag = TagHandler.getTag(parsedText); - tag.sendResponse(message.getTextChannel()); + tag.sendResponse(message.getTextChannel(), message.getAuthor()); // Delete origin message message.delete().queue(); From aacb01eece66b90ce276744657ccf1101eaa8a9d Mon Sep 17 00:00:00 2001 From: General-Mudkip Date: Mon, 9 Aug 2021 22:50:56 +0100 Subject: [PATCH 4/4] Requested changes --- .../bot/command/impl/other/mod/PurgeCommand.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java index c7851521..5519aecb 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java @@ -10,8 +10,6 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.entities.*; -import java.util.List; - public class PurgeCommand extends Command { @Override public String getName() { return "purge"; } @@ -19,7 +17,7 @@ public class PurgeCommand extends Command { @Override public HelpContext getHelpContext() { return new HelpContext() - .description("Removes the most recent messages sent in a channel. Maxiumum 100 messages.") + .description("Removes the most recent messages sent in a channel. Maximum 100 messages.") .category(CommandCategory.OTHER) .addArgument( new HelpContextArgument() @@ -45,15 +43,16 @@ public void run(CommandEvent event) { int messagesToRemove = event.getArgument("count"); - if (messagesToRemove > 100 || messagesToRemove < 0) { + if (messagesToRemove > 100 || messagesToRemove < 2) { builder.withPreset( - new InformativeReply(InformativeReplyType.ERROR, "Message count not within 0 to 100.") + new InformativeReply(InformativeReplyType.ERROR, "Message count not within 2 to 100.") ); event.reply(builder); } else { TextChannel channel = event.getChannel(); - List messages = channel.getHistory().retrievePast(messagesToRemove).complete(); - channel.deleteMessages(messages).complete(); + channel.getHistory().retrievePast(messagesToRemove).queue((messages) -> { + channel.deleteMessages(messages).queue(); + }); } } }