diff --git a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java index 77d388fd..0b43ec12 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java +++ b/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java @@ -17,6 +17,7 @@ import com.beanbeanjuice.cafebot.commands.generic.PingCommand; import com.beanbeanjuice.cafebot.commands.generic.*; import com.beanbeanjuice.cafebot.commands.interaction.*; +import com.beanbeanjuice.cafebot.commands.moderation.ClearChatCommand; import com.beanbeanjuice.cafebot.commands.social.MemberCountCommand; import com.beanbeanjuice.cafebot.commands.social.vent.VentCommand; import com.beanbeanjuice.cafebot.commands.twitch.TwitchCommand; @@ -240,7 +241,10 @@ private void setupCommands() { new VentCommand(this), // Twitch - new TwitchCommand(this) + new TwitchCommand(this), + + // Moderation + new ClearChatCommand(this) // new EmbedCommand(this) ); diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java new file mode 100644 index 00000000..cd08af99 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java @@ -0,0 +1,87 @@ +package com.beanbeanjuice.cafebot.commands.moderation; + +import com.beanbeanjuice.cafebot.CafeBot; +import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.ICommand; +import com.beanbeanjuice.cafebot.utility.helper.Helper; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; + +import java.util.concurrent.CompletableFuture; + +public class ClearChatCommand extends Command implements ICommand { + + public ClearChatCommand(final CafeBot cafeBot) { + super(cafeBot); + } + + @Override + public void handle(SlashCommandInteractionEvent event) { + int amount = event.getOption("amount").getAsInt(); + MessageChannel channel = event.getChannel(); + + channel.getHistory().retrievePast(amount).queue((messages) -> { + event.getHook().sendMessageEmbeds(Helper.successEmbed( + "Deleting Messages...", + String.format("Attempting to delete **%d** messages.", amount) + )).queue(); + + CompletableFuture.allOf(channel.purgeMessages(messages).toArray(new CompletableFuture[0])).thenAcceptAsync((ignored) -> { + event.getHook().editOriginalEmbeds(Helper.successEmbed( + "Messages Deleted", + String.format("**%d** messages have been successfully deleted.", amount) + )).setReplace(true).queue(); + }); + }); + } + + @Override + public String getName() { + return "clearchat"; + } + + @Override + public String getDescription() { + return "Clear the chat!"; + } + + @Override + public CommandCategory getCategory() { + return CommandCategory.MODERATION; + } + + @Override + public OptionData[] getOptions() { + return new OptionData[] { + new OptionData(OptionType.INTEGER, "amount", "The amount of messages you want to clear.", true) + .setRequiredRange(1, 100) + }; + } + + @Override + public Permission[] getPermissions() { + return new Permission[] { + Permission.MESSAGE_MANAGE + }; + } + + @Override + public boolean isEphemeral() { + return true; + } + + @Override + public boolean isNSFW() { + return false; + } + + @Override + public boolean allowDM() { + return false; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandCategory.java b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandCategory.java index 35b244e7..f7269114 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandCategory.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandCategory.java @@ -10,7 +10,8 @@ public enum CommandCategory { GENERIC("Very basic...", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/generic.png"), INTERACTION("Hugs, waves, slaps, and more!", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/interaction.png"), TWITCH("Commands used for twitch.", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/twitch.jpg"), - SOCIAL("Hmm... I just need to let it out... you know?", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/social.gif"); + SOCIAL("Hmm... I just need to let it out... you know?", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/social.gif"), + MODERATION("Commands used for moderation.", "https://cdn.beanbeanjuice.com/images/cafeBot/category_type/moderation.png"); @Getter private final String description; @Getter private final String link;