Make clear command also delete the sender's message

This commit is contained in:
Bea 2022-12-19 16:47:49 +01:00
parent 1e07ede83e
commit 1f6f23e917
2 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot.commands.base;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageHistory;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@ -46,7 +47,9 @@ public class ClearChat
return null;
}
public static int delete(int toDeleteAmount, long startingMessageId, MessageChannel channel)
public static int delete(int toDeleteAmount,
long startingMessageId,
MessageChannel channel)
{
// int to keep track of how many messages we actually deleted.
int deleted = 0;
@ -155,6 +158,7 @@ public class ClearChat
public static String parseAmount(int deleted)
{
if(deleted < 1)
{
return "\uD83D\uDE22 Couldn't clear any message!";

View File

@ -75,11 +75,16 @@ public class ClearCommand implements MessageCommand
// ^ todo: maybe the dismiss button should also delete the original message sent by the user?
// todo: but then, we need to differentiate between command type in the database, and store
// todo: that message's id too.
botMessage = botMessage.editMessage(content).setActionRow(dismiss).complete();
Message finalMessage = event.getChannel().sendMessage(content).setActionRow(dismiss).complete();
// add the message to database.
Cache.getDatabaseSource().queueDisabling(botMessage);
Cache.getDatabaseSource().trackRanCommandReply(botMessage, event.getAuthor());
Cache.getDatabaseSource().queueDisabling(finalMessage);
Cache.getDatabaseSource().trackRanCommandReply(finalMessage, event.getAuthor());
// delete the sender's message.
event.getMessage().delete().queue();
// delete the "clearing" info message.
botMessage.delete().queue();
}