Advertisement
Vaerys_Dawn

Evil mess of a command

Aug 21st, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.19 KB | None | 0 0
  1. package com.github.vaerys.commands.cc;
  2.  
  3. import com.github.vaerys.commands.CommandObject;
  4. import com.github.vaerys.interfaces.Command;
  5. import com.github.vaerys.main.Constants;
  6. import com.github.vaerys.main.Globals;
  7. import com.github.vaerys.main.Utility;
  8. import com.github.vaerys.objects.CCommandObject;
  9. import com.github.vaerys.objects.XEmbedBuilder;
  10. import sx.blah.discord.handle.obj.IMessage;
  11. import sx.blah.discord.handle.obj.IUser;
  12. import sx.blah.discord.handle.obj.Permissions;
  13.  
  14. import java.util.ArrayList;
  15.  
  16. /**
  17.  * Created by Vaerys on 01/02/2017.
  18.  */
  19. public class ListCCs implements Command {
  20.     @Override
  21.     public String execute(String args, CommandObject command) {
  22.         IMessage message = command.message.get();
  23.         long uID;
  24.         IUser mentionedUser = null;
  25.         if (message.getMentions().size() > 0) {
  26.             return getUserCommands(command, command.message.get().getMentions().get(0).getLongID());
  27.         }
  28.         try {
  29.             uID = Long.parseLong(args);
  30.             mentionedUser = Globals.getClient().getUserByID(uID);
  31.         } catch (NumberFormatException e) {
  32.             //do nothing
  33.         }
  34.         if (mentionedUser != null) {
  35.             return getUserCommands(command, mentionedUser.getLongID());
  36.         }
  37.         try {
  38.             int page;
  39.             if (args == null || args.isEmpty()) {
  40.                 page = 1;
  41.             } else {
  42.                 page = Integer.parseInt(args.split(" ")[0]);
  43.             }
  44.             return listCommands(page, command);
  45.         } catch (NumberFormatException e) {
  46.             return "> what are you doing, why are you trying to search for the " + args + " page... \n" +
  47.                     Constants.PREFIX_INDENT + "pretty sure you cant do that...";
  48.         }
  49.     }
  50.  
  51.     public String getUserCommands(CommandObject command, long userID) {
  52.         IUser user = Globals.getClient().getUserByID(userID);
  53.         int total = 0;
  54.         command.setAuthor(user);
  55.         int max = command.guild.customCommands.maxCCs(command.user, command.guild);
  56.         XEmbedBuilder builder = new XEmbedBuilder();
  57.         String title = "> Here are the custom commands for user: **@" + user.getName() + "#" + user.getDiscriminator() + "**.";
  58.         ArrayList<String> list = new ArrayList<>();
  59.         for (CCommandObject c : command.guild.customCommands.getCommandList()) {
  60.             if (c.getUserID().equals(userID + "")) {
  61.                 list.add(command.guild.config.getPrefixCC() + c.getName());
  62.                 total++;
  63.             }
  64.         }
  65.         Utility.listFormatterEmbed(title, builder, list, true);
  66.         builder.withColor(command.client.color);
  67.         builder.withFooterText("Total Custom commands: " + total + "/" + max + ".");
  68.         Utility.sendEmbedMessage("", builder, command.channel.get());
  69.         return null;
  70.     }
  71.  
  72.     public String listCommands(int page, CommandObject command) {
  73.         ArrayList<String> pages = new ArrayList<>();
  74.         int counter = 0;
  75.         int totalCCs = 0;
  76.         ArrayList<String> list = new ArrayList<>();
  77.         XEmbedBuilder builder = new XEmbedBuilder();
  78.         builder.withColor(command.client.color);
  79.  
  80.         for (CCommandObject c : command.guild.customCommands.getCommandList()) {
  81.             if (counter > 15) {
  82.                 pages.add("```" + Utility.listFormatter(list, true) + "```");
  83.                 list.clear();
  84.                 counter = 0;
  85.             }
  86.             list.add(command.guild.config.getPrefixCC() + c.getName());
  87.             totalCCs++;
  88.             counter++;
  89.         }
  90.         pages.add("`" + Utility.listFormatter(list, true) + "`");
  91.         try {
  92.             String title = "> Here is Page **" + page + "/" + pages.size() + "** of Custom Commands:";
  93.             builder.appendField(title, pages.get(page - 1), false);
  94.             builder.withFooterText("Total Custom Commands stored on this Server: " + totalCCs);
  95.             Utility.sendEmbedMessage("", builder, command.channel.get());
  96.             return null;
  97.         } catch (IndexOutOfBoundsException e) {
  98.             return "> That Page does not exist.";
  99.         }
  100.     }
  101.  
  102.     @Override
  103.     public String[] names() {
  104.         return new String[]{"CClist", "ListCCs"};
  105.     }
  106.  
  107.     @Override
  108.     public String description() {
  109.         return "Generates a list of custom commands based on parameters.";
  110.     }
  111.  
  112.     @Override
  113.     public String usage() {
  114.         return "(Page Number/@User)";
  115.     }
  116.  
  117.     @Override
  118.     public String type() {
  119.         return TYPE_CC;
  120.     }
  121.  
  122.     @Override
  123.     public String channel() {
  124.         return CHANNEL_BOT_COMMANDS;
  125.     }
  126.  
  127.     @Override
  128.     public Permissions[] perms() {
  129.         return new Permissions[0];
  130.     }
  131.  
  132.     @Override
  133.     public boolean requiresArgs() {
  134.         return false;
  135.     }
  136.  
  137.     @Override
  138.     public boolean doAdminLogging() {
  139.         return false;
  140.     }
  141.  
  142.     @Override
  143.     public String dualDescription() {
  144.         return null;
  145.     }
  146.  
  147.     @Override
  148.     public String dualUsage() {
  149.         return null;
  150.     }
  151.  
  152.     @Override
  153.     public String dualType() {
  154.         return null;
  155.     }
  156.  
  157.     @Override
  158.     public Permissions[] dualPerms() {
  159.         return new Permissions[0];
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement