Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package me.WattMann.RealmGuard.bot.listeners.handlers;
  2.  
  3. import me.WattMann.RealmGuard.bot.RealmClient;
  4. import me.WattMann.RealmGuard.bot.listeners.abs.RealmCommand;
  5. import org.javacord.api.event.message.MessageCreateEvent;
  6.  
  7. public class PurgeCommand extends RealmCommand {
  8.     public PurgeCommand(RealmClient client, String name, String... aliases) {
  9.         super(client, name, aliases);
  10.     }
  11.  
  12.     @Override
  13.     public void execute(MessageCreateEvent event, String[] args) throws NumberFormatException, IllegalArgumentException
  14.     {
  15.  
  16.         if (event.getServer().isPresent())
  17.         {
  18.             if(event.getApi().getUserById(event.getMessageAuthor().getId()).join().getRoles(event.getServer().get())
  19.                     .stream()
  20.                     .noneMatch(role -> role.getIdAsString()
  21.                             .equals(RealmClient.Settings.ADMIN_ROLE.getSetting().getValue().orElseThrow(() -> new IllegalArgumentException("Admin role must exist.")))))
  22.             {
  23.                 event.getChannel().sendMessage((String) RealmClient.Settings.NO_PERMISSION_MESSAGE.getSetting().getValue().get()).join();
  24.                 return;
  25.             }
  26.  
  27.             if (args.length == 0) {
  28.                 event.getChannel().sendMessage(RealmClient.Settings.SYNTAX_ERROR.getSetting().getValue().get() + " `expected argument length >= 1 got = " + args.length + "`").join();
  29.                 return;
  30.             }
  31.             int count = Integer.parseInt(args[0]) + 1;
  32.  
  33.             //basically wait for deletion to end, then send message wait 5000ms and delete it
  34.             event.getChannel().getMessages(count).join().deleteAll()
  35.                     .thenAccept(after -> event.getChannel().sendMessage(String.format((String) RealmClient.Settings.PURGED_MESSAGE.getSetting().getValue().get(), count))
  36.                             .thenAccept(sent ->
  37.                             {
  38.                                 try {
  39.                                     Thread.sleep(5000);
  40.                                 } catch (InterruptedException e) {
  41.                                     e.printStackTrace();
  42.                                 }
  43.                                 sent.delete().join();
  44.                             }).join());
  45.             return;
  46.         }
  47.         event.getChannel().sendMessage((String) RealmClient.Settings.NOT_SUPPORTED_MESSAGE.getSetting().getValue().get()).join();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement