diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index c645f78..ba95186 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -16,7 +16,8 @@ import java.util.List; public class HidekoBot { private static String botToken; - private static String standardInviteLink = "https://discord.com/oauth2/authorize?client_id=%userid%&scope=bot&permissions=8"; + private static String standardInviteLink = + "https://discord.com/oauth2/authorize?client_id=%userid%&scope=bot&permissions=8"; private static String botUserId; private static final String version = "0.0.1"; // we should probably find a way to make this consistent with Maven diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java index 32887a3..8be6a8d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java @@ -3,11 +3,17 @@ package wtf.beatrice.hidekobot.listeners; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.requests.RestAction; import org.jetbrains.annotations.NotNull; import wtf.beatrice.hidekobot.Configuration; import wtf.beatrice.hidekobot.utils.Logger; import wtf.beatrice.hidekobot.utils.RandomUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + public class MessageListener extends ListenerAdapter { @@ -39,5 +45,32 @@ public class MessageListener extends ListenerAdapter channel.sendMessage(msg).queue(); } + + + if(event.getMessage().getContentDisplay().equalsIgnoreCase("clear the chat")) + { + MessageChannel channel = event.getChannel(); + int count = 10; + int delay = 300; + + Message warn = channel.sendMessage("Clearing...").complete(); + + MessageHistory.MessageRetrieveAction action = channel.getHistoryBefore(event.getMessage().getIdLong(), count); + List messagesUnmodifiable = action.complete().getRetrievedHistory(); + List messages = new ArrayList<>(messagesUnmodifiable); + messages.add(warn); + messages.add(event.getMessage()); + for(Message msg : messages) + { + //... after waiting X seconds. + Executors.newSingleThreadScheduledExecutor().schedule(() -> + { + logger.log(msg.getContentDisplay()); + msg.delete().complete(); + }, delay, TimeUnit.MILLISECONDS); + + delay += 500; + } + } } }