Make bot commands run in separate threads by default
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -31,51 +31,47 @@ public class ClearCommand implements MessageCommand
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
// start a new thread, because we are doing synchronous, thread-blocking operations!
|
||||
new Thread(() ->
|
||||
{
|
||||
String senderId = event.getMessage().getAuthor().getId();
|
||||
String senderId = event.getMessage().getAuthor().getId();
|
||||
|
||||
// check if user is trying to run command in dms.
|
||||
String error = ClearChat.checkDMs(event.getChannel());
|
||||
if (error != null) {
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
// check if user is trying to run command in dms.
|
||||
String error = ClearChat.checkDMs(event.getChannel());
|
||||
if (error != null) {
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// get the amount from the command args.
|
||||
Integer toDeleteAmount;
|
||||
if (args.length == 0) toDeleteAmount = 1;
|
||||
else toDeleteAmount = Integer.parseInt(args[0]);
|
||||
// get the amount from the command args.
|
||||
Integer toDeleteAmount;
|
||||
if (args.length == 0) toDeleteAmount = 1;
|
||||
else toDeleteAmount = Integer.parseInt(args[0]);
|
||||
|
||||
error = ClearChat.checkDeleteAmount(toDeleteAmount);
|
||||
if (error != null) {
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
error = ClearChat.checkDeleteAmount(toDeleteAmount);
|
||||
if (error != null) {
|
||||
event.getMessage().reply(error).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// answer by saying that the operation has begun.
|
||||
String content = "\uD83D\uDEA7 Clearing...";
|
||||
Message botMessage = event.getMessage().reply(content).complete();
|
||||
// answer by saying that the operation has begun.
|
||||
String content = "\uD83D\uDEA7 Clearing...";
|
||||
Message botMessage = event.getMessage().reply(content).complete();
|
||||
|
||||
int deleted = ClearChat.delete(toDeleteAmount,
|
||||
event.getMessageIdLong(),
|
||||
event.getChannel());
|
||||
int deleted = ClearChat.delete(toDeleteAmount,
|
||||
event.getMessageIdLong(),
|
||||
event.getChannel());
|
||||
|
||||
// get a nicely formatted message that logs the deletion of messages.
|
||||
content = ClearChat.parseAmount(deleted);
|
||||
// get a nicely formatted message that logs the deletion of messages.
|
||||
content = ClearChat.parseAmount(deleted);
|
||||
|
||||
// edit the message text and attach a button.
|
||||
Button dismiss = ClearChat.getDismissButton();
|
||||
// ^ 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();
|
||||
// edit the message text and attach a button.
|
||||
Button dismiss = ClearChat.getDismissButton();
|
||||
// ^ 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();
|
||||
|
||||
// add the message to database.
|
||||
Cache.getDatabaseSource().queueDisabling(botMessage);
|
||||
Cache.getDatabaseSource().trackRanCommandReply(botMessage, event.getAuthor());
|
||||
}).start();
|
||||
// add the message to database.
|
||||
Cache.getDatabaseSource().queueDisabling(botMessage);
|
||||
Cache.getDatabaseSource().trackRanCommandReply(botMessage, event.getAuthor());
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user