Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.WattMann.RealmGuard.bot.listeners.handlers;
- import me.WattMann.RealmGuard.bot.RealmClient;
- import me.WattMann.RealmGuard.bot.listeners.abs.RealmCommand;
- import org.javacord.api.event.message.MessageCreateEvent;
- public class PurgeCommand extends RealmCommand {
- public PurgeCommand(RealmClient client, String name, String... aliases) {
- super(client, name, aliases);
- }
- @Override
- public void execute(MessageCreateEvent event, String[] args) throws NumberFormatException, IllegalArgumentException
- {
- if (event.getServer().isPresent())
- {
- if(event.getApi().getUserById(event.getMessageAuthor().getId()).join().getRoles(event.getServer().get())
- .stream()
- .noneMatch(role -> role.getIdAsString()
- .equals(RealmClient.Settings.ADMIN_ROLE.getSetting().getValue().orElseThrow(() -> new IllegalArgumentException("Admin role must exist.")))))
- {
- event.getChannel().sendMessage((String) RealmClient.Settings.NO_PERMISSION_MESSAGE.getSetting().getValue().get()).join();
- return;
- }
- if (args.length == 0) {
- event.getChannel().sendMessage(RealmClient.Settings.SYNTAX_ERROR.getSetting().getValue().get() + " `expected argument length >= 1 got = " + args.length + "`").join();
- return;
- }
- int count = Integer.parseInt(args[0]) + 1;
- //basically wait for deletion to end, then send message wait 5000ms and delete it
- event.getChannel().getMessages(count).join().deleteAll()
- .thenAccept(after -> event.getChannel().sendMessage(String.format((String) RealmClient.Settings.PURGED_MESSAGE.getSetting().getValue().get(), count))
- .thenAccept(sent ->
- {
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- sent.delete().join();
- }).join());
- return;
- }
- event.getChannel().sendMessage((String) RealmClient.Settings.NOT_SUPPORTED_MESSAGE.getSetting().getValue().get()).join();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement