Skip to content

Commit

Permalink
Added the Clear Chat Command
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Jul 12, 2024
1 parent ac204c8 commit 445e2ed
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/beanbeanjuice/cafebot/CafeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -240,7 +241,10 @@ private void setupCommands() {
new VentCommand(this),

// Twitch
new TwitchCommand(this)
new TwitchCommand(this),

// Moderation
new ClearChatCommand(this)

// new EmbedCommand(this)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 445e2ed

Please sign in to comment.