Vaerys_Dawn

Sail v1 command system

Aug 25th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 44.16 KB | None | 0 0
  1. import org.apache.commons.lang3.text.WordUtils;
  2. import org.slf4j.LoggerFactory;
  3. import sx.blah.discord.handle.impl.obj.Channel;
  4. import sx.blah.discord.handle.impl.obj.Guild;
  5. import sx.blah.discord.handle.impl.obj.Message;
  6. import sx.blah.discord.handle.obj.*;
  7. import sx.blah.discord.util.DiscordException;
  8. import sx.blah.discord.util.MissingPermissionsException;
  9. import sx.blah.discord.util.RateLimitException;
  10.  
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.lang.reflect.Method;
  14. import java.nio.file.Paths;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. import java.util.Random;
  18.  
  19. /**
  20.  * Created by Vaerys on 19/05/2016.
  21.  */
  22. public class Commands {
  23.  
  24.     final static org.slf4j.Logger logger = LoggerFactory.getLogger(AnnotationListener.class);
  25.     private FileHandler handler = new FileHandler();
  26.  
  27.     Guild guild;
  28.     Channel channel;
  29.     Message message;
  30.     IUser author;
  31.     String guildID;
  32.  
  33.     private GuildConfig guildConfig;
  34.     private CustomCommands customCommands;
  35.     private Characters characters;
  36.     private String guildConfigFile;
  37.     private String CCFile;
  38.     private String charFile;
  39.  
  40.     boolean isOwner;
  41.     boolean isAdmin;
  42.     boolean isMod;
  43.     boolean isCF;
  44.     boolean isCreator;
  45.     boolean pogosLoaded = false;
  46.  
  47.     private String notAllowed;
  48.     private String errorMessage;
  49.  
  50.  
  51.     public Commands(Message message) {
  52.         this.message = message;
  53.         guild = (Guild) message.getGuild();
  54.         channel = (Channel) message.getChannel();
  55.         author = message.getAuthor();
  56.         guildID = message.getGuild().getID();
  57.         notAllowed = "I'm Sorry " + author.getName() + " I'm afraid I can't do that.";
  58.         guildConfigFile = "GuildConfigs/" + guildID + "_config.json";
  59.         CCFile = "CommandLists/" + guildID + "_CustomCommands.json";
  60.         charFile = "Characters/" + guildID + "_CharList.json";
  61.         errorMessage = "You have Found an error, please Mention this bot or " + guild.getUserByID(Globals.creatorID).getName() + " to let them know of this error";
  62.  
  63.  
  64.         if (author.getID().equals(Globals.creatorID)) {
  65.             isCreator = true;
  66.         }
  67.         if (guild.getOwner().equals(author)) {
  68.             isOwner = true;
  69.         }
  70.         for (int i = 0; i < author.getRolesForGuild(guild).size(); i++) {
  71.             IRole role = author.getRolesForGuild(guild).get(i);
  72.             if (role.getPermissions().contains(Permissions.ADMINISTRATOR)) {
  73.                 isAdmin = true;
  74.             }
  75.             if (role.getPermissions().contains(Permissions.MANAGE_ROLES)) {
  76.                 isMod = true;
  77.             }
  78.             if (role.getName().toLowerCase().contains("chucklefish")) {
  79.                 isCF = true;
  80.             }
  81.         }
  82.     }
  83.  
  84.     public void setPOGOS(GuildConfig guildConfig, CustomCommands customCommands, Characters characters) {
  85.         this.guildConfig = guildConfig;
  86.         this.customCommands = customCommands;
  87.         this.characters = characters;
  88.         characters.loadFile();
  89.         pogosLoaded = true;
  90.     }
  91.  
  92.     public void flushFiles() {
  93.         if (pogosLoaded) {
  94.             if (guildConfig.getDoLoginMessage() == guildConfig.getDoLoginMessage()) {
  95.                 handler.writetoJson(guildConfigFile, guildConfig);
  96.             }
  97.             if (customCommands.getCommand("cc.echo", guild.getUserByID(Globals.creatorID), guild).equalsIgnoreCase("Nothing")) {
  98.                 handler.writetoJson(CCFile, customCommands);
  99.             }
  100.             if (characters.wasLoaded) {
  101.                 characters.unloadFile();
  102.                 handler.writetoJson(charFile, characters);
  103.             }
  104.         }
  105.     }
  106.  
  107.     public String channelNotInit(String channelType) {
  108.         return "The " + channelType + " Channel has not been set up yet please have an admin perform the command `" + Globals.COMMAND_PREFIX + channelType + "Here` in the appropriate channel";
  109.     }
  110.  
  111.     public String wrongChannel(String channelID) {
  112.         return "Command must be performed in " + guild.getChannelByID(channelID).toString();
  113.     }
  114.  
  115.     private String getDescription(String name) {
  116.         try {
  117.             CommandAnnotation Ca = this.getClass().getMethod(name).getAnnotation(CommandAnnotation.class);
  118.             return Globals.COMMAND_PREFIX + Ca.name() + "\n" + Ca.description() + "\nUsage: `" + getUsage(name) + "`";
  119.         } catch (NoSuchMethodException e) {
  120.             e.printStackTrace();
  121.         }
  122.         return "Failed to Find Method";
  123.     }
  124.  
  125.     private String getName(String name) {
  126.         try {
  127.             CommandAnnotation Ca = this.getClass().getMethod(name).getAnnotation(CommandAnnotation.class);
  128.             return Globals.COMMAND_PREFIX + Ca.name();
  129.         } catch (NoSuchMethodException e) {
  130.             e.printStackTrace();
  131.         }
  132.         return "Failed to Find Method";
  133.     }
  134.  
  135.     private String getUsage(String name) {
  136.         try {
  137.             CommandAnnotation Ca = this.getClass().getMethod(name).getAnnotation(CommandAnnotation.class);
  138.             return getName(name) + " " + Ca.usage();
  139.         } catch (NoSuchMethodException e) {
  140.             e.printStackTrace();
  141.         }
  142.         return "Failed to Find Method";
  143.     }
  144.  
  145.     private String helpHandler(String type) {
  146.         Method[] methods = this.getClass().getMethods();
  147.         StringBuilder builder = new StringBuilder();
  148.         builder.append("Here are all of the " + WordUtils.capitalize(type) + " Commands:");
  149.         for (Method m : methods) {
  150.             if (m.isAnnotationPresent(CommandAnnotation.class)) {
  151.                 CommandAnnotation anno = m.getAnnotation(CommandAnnotation.class);
  152.                 if (anno.type().equalsIgnoreCase(type)) {
  153.                     builder.append("\n   " + Globals.COMMAND_PREFIX + anno.name());
  154.                 }
  155.             }
  156.         }
  157.         return builder.toString();
  158.     }
  159.  
  160.     public String handleInvites() {
  161.         String build = "Cleared";
  162.         for (IRole r : author.getRolesForGuild(guild)) {
  163.             for (String s : guildConfig.getClearedRoles()) {
  164.                 if (s.equals(r.getID())) {
  165.                     return build;
  166.                 }
  167.             }
  168.         }
  169.         try {
  170.             message.delete();
  171.             if (AnnotationListener.adminMentionCooldown == 0) {
  172.                 build = guild.getRoleByID(Utility.GetRoleIDFromName("Admin", guild)).mention() + ", " + author.mention() + " Has attempted to post a Discord invite link.";
  173.                 AnnotationListener.adminMentionCooldown = 60;
  174.             }
  175.         } catch (MissingPermissionsException e) {
  176.             e.printStackTrace();
  177.         } catch (RateLimitException e) {
  178.             e.printStackTrace();
  179.         } catch (DiscordException e) {
  180.             e.printStackTrace();
  181.         }
  182.         return build;
  183.     }
  184.  
  185.     @AliasAnnotation(alias = {"Hi", "Hello", "Greeting", "Hai", "Hoi"})
  186.     @CommandAnnotation(name = "Hello", description = "Says Hello")
  187.     public String helloSail() {
  188.         if (isCreator) {
  189.             return "> Hello Creator";
  190.         } else if (isOwner) {
  191.             return "> Hello Server Owner";
  192.         } else if (isAdmin) {
  193.             return "> Hello Admin";
  194.         } else if (isMod) {
  195.             return "> Hello Moderator";
  196.         } else if (isCF) {
  197.             return "> Hello Chucklefish Staff Member";
  198.         } else {
  199.             String[] lock;
  200.  
  201.             String roles = "nothing";
  202.             ArrayList<IRole> rolelist = (ArrayList) author.getRolesForGuild(guild);
  203.             for (IRole r : rolelist) {
  204.                 if (r.getName().equalsIgnoreCase("apex")) roles = r.getName();
  205.                 if (r.getName().equalsIgnoreCase("avian")) roles = r.getName();
  206.                 if (r.getName().equalsIgnoreCase("floran")) roles = r.getName();
  207.                 if (r.getName().equalsIgnoreCase("glitch")) roles = r.getName();
  208.                 if (r.getName().equalsIgnoreCase("human")) roles = r.getName();
  209.                 if (r.getName().equalsIgnoreCase("hylotl")) roles = r.getName();
  210.                 if (r.getName().equalsIgnoreCase("novakid")) roles = r.getName();
  211.                 if (r.getName().equalsIgnoreCase("penguin")) roles = r.getName();
  212.                 if (r.getName().equalsIgnoreCase("agaran")) roles = r.getName();
  213.                 if (r.getName().equalsIgnoreCase("avali")) roles = r.getName();
  214.                 if (r.getName().equalsIgnoreCase("felin")) roles = r.getName();
  215.             }
  216.             Random r = new Random();
  217.             int randomInt = r.nextInt(10);
  218.             if (message.toString().length() > 10) {
  219.                 lock = message.toString().split(" ");
  220.                 randomInt = Integer.parseInt(lock[1]);
  221.             }
  222.             if (randomInt == 0) {
  223.                 return "> Hello " + author.getName() + ", How was your day?";
  224.             } else if (randomInt == 1) {
  225.                 return "> Hello... " + author.getName();
  226.             } else if (randomInt == 2) {
  227.                 return "> Greetings " + author.getName() + ", I am S.A.I.L";
  228.             } else if (randomInt == 3) {
  229.                 return "> Hi " + author.getName() + ", That's an interesting name.";
  230.             } else if (randomInt == 4) {
  231.                 return "> Goodbye " + author.getName();
  232.             } else if (randomInt == 5) {
  233.                 return "> 0100 1000 0110 0101 0110 1100 0110 1100 0110 1111 0010 1110";
  234.             } else if (randomInt == 6) {
  235.                 return "> Initiating greeting protocol... Hello " + author.getName();
  236.             } else if (randomInt == 7) {
  237.                 return "> ERROR: CANNOT PARSE COMMAND 'HELLO'";
  238.             } else if (randomInt == 8) {
  239.                 return "> Glad to see you escaped the black hole, " + author.getName();
  240.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("apex")) {
  241.                 return "> Hello there, " + author.getName() + " , Miniknog Smiles on you today.";
  242.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("avian")) {
  243.                 return "> My, my, " + author.getName() + " , your plumage is looking extraordinary today.";
  244.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("floran")) {
  245.                 return "> Greetingsssss " + author.getName() + ", Does Floran want to go huntingsss later?";
  246.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("glitch")) {
  247.                 return "> Happy. Hello " + author.getName() + ", You seem especially well polished today.";
  248.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("human")) {
  249.                 return "> Another day alive, congratulations " + author.getName();
  250.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("hylotl")) {
  251.                 return "> Have a peaceful day " + author.getName() + " may you experience tranquility.";
  252.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("novakid")) {
  253.                 return "> " + author.getName() + "! the Sheriff has been shot, I need your... oooo~ whats that?";
  254.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("penguin")) {
  255.                 return "> Dreadwing will not find you here " + author.getName() + " you are safe.";
  256.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("agaran")) {
  257.                 return "> Hoom Shroom Nab Nab Agaran " + author.getName() + " Click Clack Flap Flap.";
  258.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("avali")) {
  259.                 return "> Did you get the get the new message from the Local network " + author.getName() + "?";
  260.             } else if ((randomInt == 9) && roles.equalsIgnoreCase("felin")) {
  261.                 return "> All we are is cats in the wind " + author.getName();
  262.             } else if ((randomInt == 9)) {
  263.                 return "> Ello " + author.getName() + "Ain't Seen you around much";
  264.             } else {
  265.                 return "> How did you get this message " + author.getName();
  266.             }
  267.         }
  268.     }
  269.  
  270.     @CommandAnnotation(name = "GeneralHere", type = Globals.TYPE_ADMIN, description = "Sets the current Channel as the Server's 'General' Channel")
  271.     public String setGeneral() {
  272.         if (isAdmin || isOwner) {
  273.             guildConfig.setGeneralChannel(channel.getID());
  274.             return "> This Channel is now the Server's 'General' Channel.";
  275.         } else {
  276.             return notAllowed;
  277.         }
  278.     }
  279.  
  280.     @CommandAnnotation(name = "ServersHere", type = Globals.TYPE_ADMIN, description = "Sets the current Channel as the Server's 'Servers' Channel")
  281.     public String setServersChannel() {
  282.         if (isAdmin || isOwner) {
  283.             guildConfig.setServersChannel(channel.getID());
  284.             return "> This Channel is now the Server's 'Servers' Channel.";
  285.         } else {
  286.             return notAllowed;
  287.         }
  288.     }
  289.  
  290.     @CommandAnnotation(name = "RaceSelectHere", type = Globals.TYPE_ADMIN, description = "Sets the current Channel as the Server's 'Race Select' Channel")
  291.     public String setRaceSelect() {
  292.         if (isAdmin || isOwner) {
  293.             guildConfig.setRaceSelectChannel(channel.getID());
  294.             return "> This Channel is now the Server's 'Race Select' Channel.";
  295.         } else {
  296.             return notAllowed;
  297.         }
  298.     }
  299.  
  300.     @CommandAnnotation(name = "Help", description = "Lists all of the Commands Sail can run", usage = "[Type]")
  301.     public String sailHelp() {
  302.         Method[] methods = this.getClass().getMethods();
  303.         String[] splitMessage = message.toString().split(" ");
  304.         StringBuilder commandList = new StringBuilder();
  305.         ArrayList<String> types = new ArrayList<>();
  306.         if (message.toString().length() == getName("sailHelp").length()) {
  307.             for (Method m : methods) {
  308.                 if (m.isAnnotationPresent(CommandAnnotation.class)) {
  309.                     boolean typeFound = false;
  310.                     CommandAnnotation anno = m.getAnnotation(CommandAnnotation.class);
  311.                     for (String s : types) {
  312.                         if (s.equalsIgnoreCase(anno.type())) {
  313.                             typeFound = true;
  314.                         }
  315.                     }
  316.                     if (!typeFound) {
  317.                         types.add(anno.type());
  318.                     }
  319.                 }
  320.             }
  321.             commandList.append("Here are the command types you can search from:");
  322.             for (String s : types) {
  323.                 commandList.append("\n   " + s);
  324.             }
  325.             commandList.append("\nYou can search for commands with those types by doing \n`" + getUsage("sailHelp") + "`");
  326.             commandList.append("\nGitHub Page: <https://github.com/Vaerys-Dawn/S.A.I.L>");
  327.         } else if (splitMessage[1].equalsIgnoreCase("Admin")) {
  328.             if (isMod || isAdmin) {
  329.                 commandList.append(helpHandler("Admin"));
  330.             } else {
  331.                 return notAllowed;
  332.             }
  333.         } else if (splitMessage[1].equalsIgnoreCase(Globals.TYPE_RACE)) {
  334.             commandList.append(helpHandler(Globals.TYPE_RACE));
  335.         } else if (splitMessage[1].equalsIgnoreCase(Globals.TYPE_SERVERS)) {
  336.             commandList.append(helpHandler(Globals.TYPE_SERVERS));
  337.         } else if (splitMessage[1].equalsIgnoreCase(Globals.TYPE_GENERAL)) {
  338.             commandList.append(helpHandler(Globals.TYPE_GENERAL));
  339.         } else if (splitMessage[1].equalsIgnoreCase(Globals.TYPE_CC)) {
  340.             commandList.append(helpHandler(Globals.TYPE_CC));
  341.         } else {
  342.             return getDescription("sailHelp");
  343.         }
  344.         return commandList.toString();
  345.     }
  346.  
  347.     @CommandAnnotation(name = "Info", description = "Gives information about a specific command", usage = "[Command]")
  348.     public String sailInfo() {
  349.         Method[] methods = this.getClass().getMethods();
  350.         String buildMessage = message.toString();
  351.         if (message.toString().toLowerCase().equals("sail.info")) {
  352.             return getDescription("sailInfo");
  353.         }
  354.         String[] splitMessage = buildMessage.split(" ");
  355.         for (Method m : methods) {
  356.             if (m.isAnnotationPresent(CommandAnnotation.class) && !splitMessage[1].equals("")) {
  357.                 CommandAnnotation commandAnno = m.getAnnotation(CommandAnnotation.class);
  358.                 String testMessage = splitMessage[1].toLowerCase();
  359.                 String testTo = commandAnno.name().toLowerCase();
  360.                 if ((testMessage.startsWith(testTo)) && (testMessage.length() == testTo.length())) {
  361.                     StringBuilder builder = new StringBuilder();
  362.                     builder.append(getDescription(m.getName()));
  363.                     if (m.isAnnotationPresent(AliasAnnotation.class)) {
  364.                         AliasAnnotation aliasAnno = m.getAnnotation(AliasAnnotation.class);
  365.                         String[] alias = aliasAnno.alias();
  366.                         builder.append("\nAliases: ");
  367.                         for (int i = 0; i < alias.length; i++) {
  368.                             builder.append(alias[i] + ", ");
  369.                         }
  370.                     }
  371.                     return builder.toString();
  372.                 }
  373.             }
  374.         }
  375.         return "> That command does not exist.";
  376.     }
  377.  
  378.     @CommandAnnotation(name = "doLoginMessage", type = Globals.TYPE_ADMIN, description = "Toggles the login mesaage")
  379.     public String setLoginMessage() {
  380.         if (isAdmin || isOwner) {
  381.             if (guildConfig.getDoLoginMessage()) {
  382.                 guildConfig.setDoLoginMessage(false);
  383.             } else {
  384.                 guildConfig.setDoLoginMessage(true);
  385.             }
  386.             return "> Toggled the Login Message";
  387.         } else {
  388.             return notAllowed;
  389.         }
  390.     }
  391.  
  392.     @AliasAnnotation(alias = {"ListRaces", "Races", "RaceList", "RoleList", "ListRoles", "Roles"})
  393.     @CommandAnnotation(name = "ListRaces", type = "Race", channel = Globals.CHANNEL_RACE_SELECT, description = "Lists the Available races that you can choose from")
  394.     public String listRaces() {
  395.         StringBuilder response = new StringBuilder();
  396.         ArrayList<String> races = guildConfig.getRaces();
  397.         response.append("> Here are the Races you can choose from:\n`");
  398.         for (String s : races) {
  399.             response.append(guild.getRoleByID(s).getName() + ", ");
  400.         }
  401.         response.append("`");
  402.         return response.toString();
  403.     }
  404.  
  405.     @AliasAnnotation(alias = {"AddRace", "AddRole"})
  406.     @CommandAnnotation(name = "AddRace", type = Globals.TYPE_ADMIN, channel = Globals.CHANNEL_RACE_SELECT, description = "Adds role to selectable races", usage = "[Role name]")
  407.     public String addRace() {
  408.         if (isAdmin || isOwner || isMod) {
  409.             String[] testMessage = message.toString().split(" ");
  410.             if (message.toString().length() == getName("addRace").length() || testMessage[1].equals("")) {
  411.                 return "> Could not add race because you did not tell me which one you wanted to add. I'm a bot not a wizard.\n" + getUsage("addRace");
  412.             }
  413.             ArrayList<IRole> roles = (ArrayList) guild.getRoles();
  414.             String raceID;
  415.             for (IRole r : roles) {
  416.                 if (r.getName().toLowerCase().equals(testMessage[1].toLowerCase()) && !testMessage[1].equals("")) {
  417.                     raceID = r.getID();
  418.                     guildConfig.addRace(raceID);
  419.                     return "> Race added.";
  420.                 }
  421.             }
  422.             return "> role not found";
  423.         } else {
  424.             return notAllowed;
  425.         }
  426.     }
  427.  
  428.     @AliasAnnotation(alias = {"RemoveRace", "DelRace", "DeleteRace", "DeleteRole", "RemoveRole", "DelRole"})
  429.     @CommandAnnotation(name = "RemoveRace", type = Globals.TYPE_ADMIN, channel = Globals.CHANNEL_RACE_SELECT, description = "Removes the role from the selectable races", usage = "[Role name]")
  430.     public String removeRace() {
  431.         if (isAdmin || isOwner || isMod) {
  432.             String[] testMessage = message.toString().split(" ");
  433.             if (message.toString().length() == getName("removeRace").length() || testMessage[1].equals("")) {
  434.                 return "> ERROR: USER SPECIFIED NOTHING AS A PARAMETER, CANNOT REMOVE NOTHING FROM RACE LIST.\n" + getUsage("removeRace");
  435.             }
  436.             ArrayList<IRole> roles = (ArrayList) guild.getRoles();
  437.             String raceID;
  438.             for (IRole r : roles) {
  439.                 if (r.getName().toLowerCase().equals(testMessage[1].toLowerCase()) && !testMessage[1].equals("")) {
  440.                     raceID = r.getID();
  441.                     if (guildConfig.removeRace(raceID)) {
  442.                         return "> Race removed.";
  443.                     } else {
  444.                         return errorMessage;
  445.                     }
  446.                 }
  447.             }
  448.             return "> race not found";
  449.         } else {
  450.             return notAllowed;
  451.         }
  452.     }
  453.  
  454.     @AliasAnnotation(alias = {"Race", "Iam", "Role"})
  455.     @CommandAnnotation(name = "Race", type = "Race", channel = Globals.CHANNEL_RACE_SELECT, description = "Gives you a race.", usage = "[Race]")
  456.     public String race() {
  457.         List<IRole> roles = author.getRolesForGuild(guild);
  458.         ArrayList<String> races = guildConfig.getRaces();
  459.         List<IRole> guildRoles = guild.getRoles();
  460.         String response = "";
  461.         String newRace = "";
  462.         for (int i = 0; i < roles.size(); i++) {
  463.             for (String r : races) {
  464.                 if (roles.get(i).equals(guild.getRoleByID(r))) {
  465.                     roles.remove(i);
  466.                 }
  467.             }
  468.         }
  469.         boolean racefound = false;
  470.         String[] newRole = message.toString().split(" ");
  471.  
  472.         if (message.toString().length() == getName("race").length()) {
  473.             return getDescription("race");
  474.         }
  475.         if (newRole[1].equalsIgnoreCase("remove")) {
  476.             racefound = true;
  477.             response = "> Your race was removed, Congrats Normie.";
  478.         }
  479.         for (String r : races) {
  480.             if (newRole[1].equalsIgnoreCase(guild.getRoleByID(r).getName())) {
  481.                 roles.add(guild.getRoleByID(r));
  482.                 racefound = true;
  483.                 newRace = guild.getRoleByID(r).getName();
  484.             }
  485.         }
  486.         IRole[] newRoleList;
  487.         newRoleList = roles.stream().toArray(IRole[]::new);
  488.         try {
  489.             StringBuilder stringBuilder = new StringBuilder();
  490.             stringBuilder.append(message.toString());
  491.             stringBuilder.delete(0, newRole[0].length());
  492.             if (racefound) {
  493.                 guild.editUserRoles(author, newRoleList);
  494.                 if (response.equals("")) {
  495.                     return "> You have selected race: **" + newRace + "**.";
  496.                 }
  497.             } else {
  498.                 response = "> You cannot have the race:" + stringBuilder.toString() + " as that race does not exist";
  499.             }
  500.             return response;
  501.         } catch (MissingPermissionsException e) {
  502.             e.printStackTrace();
  503.         } catch (DiscordException e) {
  504.             e.printStackTrace();
  505.         } catch (RateLimitException e) {
  506.             e.printStackTrace();
  507.         }
  508.         return "> Error 502, Try again.";
  509.     }
  510.  
  511.     @CommandAnnotation(name = "AddServer", type = Globals.TYPE_SERVERS, channel = Globals.CHANNEL_SERVERS, description = "Adds a sever to the server list.", usage = "[ServerName]")
  512.     public String addServer() {
  513.         String[] testMessage = message.toString().split(" ");
  514.         boolean isUsed = false;
  515.         if (testMessage.length == 2) {
  516.             for (String[] sa : guildConfig.getServerList()) {
  517.                 if (sa[1].equalsIgnoreCase(testMessage[1])) {
  518.                     isUsed = true;
  519.                 }
  520.             }
  521.             if (!isUsed) {
  522.                 guildConfig.addServer(author.getID(), testMessage[1]);
  523.                 return "> Server Added";
  524.             } else {
  525.                 return "> Server name has already been used";
  526.             }
  527.         } else if (testMessage.length == 1) {
  528.             return "> You must Specify a Server Name\n" + getUsage("addServer");
  529.         } else {
  530.             return "> Server name cannot have spaces";
  531.         }
  532.     }
  533.  
  534.     @AliasAnnotation(alias = {"ListServers", "Servers", "ServerList"})
  535.     @CommandAnnotation(name = "ListServers", type = Globals.TYPE_SERVERS, channel = Globals.CHANNEL_SERVERS, description = "Lists all of the servers")
  536.     public String listServers() {
  537.         StringBuilder response = new StringBuilder();
  538.         response.append("Here are the Servers Currently Saved to my list\n");
  539.         for (String[] sa : guildConfig.getServerList()) {
  540.             response.append("   " + sa[1] + "\n");
  541.         }
  542.         response.append("You can get the server information of each server by performing\n`" + getUsage("serverInfo") + "`");
  543.         return response.toString();
  544.     }
  545.  
  546.     @CommandAnnotation(name = "Server", type = Globals.TYPE_SERVERS, channel = Globals.CHANNEL_SERVERS, description = "Gives the server's Details", usage = "[ServerName]")
  547.     public String serverInfo() {
  548.         String[] testMessage = message.toString().split(" ");
  549.         StringBuilder response = new StringBuilder();
  550.         response.append("Server does not exist");
  551.         if (message.toString().length() == getName("serverInfo").length()) {
  552.             return getDescription("serverInfo");
  553.         }
  554.         for (String[] sa : guildConfig.getServerList()) {
  555.             if (testMessage[1].equalsIgnoreCase(sa[1])) {
  556.                 response.delete(0, response.length());
  557.                 response.append(sa[1]);
  558.                 response.append("\n**Listing Creator:** " + guild.getUserByID(sa[0]).getName());
  559.                 response.append("\n**Server IP:** " + sa[2] + " **Port:** " + sa[3]);
  560.                 response.append("\n" + sa[4]);
  561.             }
  562.         }
  563.         return response.toString();
  564.     }
  565.  
  566.     @CommandAnnotation(name = "EditServer", type = Globals.TYPE_SERVERS, channel = Globals.CHANNEL_SERVERS, description = "Edits the server", usage = "[ServerName] Ip, Port, or Desc")
  567.     public String editServer() {
  568.         String[] testMessage = message.toString().split(" ");
  569.         if (guildConfig.getEditingServer()) {
  570.             if (guildConfig.getServerEditor().equals(author.getID())) {
  571.                 for (String[] sa : guildConfig.getServerList()) {
  572.                     if (sa[1].equalsIgnoreCase(guildConfig.getServerToEdit())) {
  573.                         if (guildConfig.getServerEditingType().equalsIgnoreCase("IP")) {
  574.                             sa[2] = testMessage[1];
  575.                             stopServerEdit();
  576.                             return "> IP Edited";
  577.                         } else if (guildConfig.getServerEditingType().equalsIgnoreCase("Port")) {
  578.                             sa[3] = testMessage[1];
  579.                             stopServerEdit();
  580.                             return "> Port Edited";
  581.                         } else if (guildConfig.getServerEditingType().equalsIgnoreCase("Desc")) {
  582.                             StringBuilder stringBuilder = new StringBuilder();
  583.                             stringBuilder.append(message.toString());
  584.                             stringBuilder.delete(0, testMessage[0].length() + 1);
  585.                             sa[4] = stringBuilder.toString();
  586.                             stopServerEdit();
  587.                             return "> Description Edited";
  588.                         } else {
  589.                             stopServerEdit();
  590.                             return errorMessage;
  591.                         }
  592.                     }
  593.                 }
  594.                 stopServerEdit();
  595.             } else {
  596.                 return "> A Server Listing is currently being edited.\n> An admin or Moderator will have to perform  " + Globals.COMMAND_PREFIX + "AbandonEdit` to allow for another edit.";
  597.             }
  598.         } else {
  599.             if (testMessage.length == 3) {
  600.                 for (String[] sa : guildConfig.getServerList()) {
  601.                     if (testMessage[1].equalsIgnoreCase(sa[1])) {
  602.                         if (author.getID().equals(sa[0]) || isOwner || isAdmin) {
  603.                             if (testMessage[2].equalsIgnoreCase("desc") || testMessage[2].equalsIgnoreCase("IP") || testMessage[2].equalsIgnoreCase("port")) {
  604.                                 guildConfig.setEditingServer(true);
  605.                                 guildConfig.setServerEditor(author.getID());
  606.                                 guildConfig.setServerEditingType(testMessage[2]);
  607.                                 guildConfig.setServerToEdit(testMessage[1]);
  608.                                 return "You are now Editing the Server " + testMessage[2] + "\nPerform `" + getName("editServer") + " [Contents]` to change the server properties,\nOr  " + Globals.COMMAND_PREFIX + "AbandonEdit` to cancel editing\n" +
  609.                                         "❗*IMPORTANT: Please Surround links with* `<>`❗";
  610.                             } else {
  611.                                 return "Cannot edit " + testMessage[2];
  612.                             }
  613.                         } else {
  614.                             return "> You do not have permission to edit this server listing.";
  615.                         }
  616.                     }
  617.                 }
  618.                 return "> server does not exist";
  619.             } else if (testMessage.length == 2) {
  620.                 return "> You must specify a channel, this channel is either IP, Port or Desc";
  621.             } else if (testMessage.length == 1) {
  622.                 return "> You must specify a server to edit\n" + getUsage("editServer");
  623.             } else {
  624.                 return "> Too many or too few arguments\n" + getUsage("editServer");
  625.             }
  626.         }
  627.         return errorMessage;
  628.     }
  629.  
  630.     @CommandAnnotation(name = "AbandonEdit", type = Globals.TYPE_SERVERS, channel = Globals.CHANNEL_SERVERS, description = "Stops the Server Listing Editing process")
  631.     public String stopServerEdit() {
  632.         if (isAdmin || isMod || isOwner || author.equals(guild.getUserByID(guildConfig.getServerEditor()))) {
  633.             guildConfig.setEditingServer(false);
  634.             guildConfig.setServerEditor("");
  635.             guildConfig.setServerEditingType("");
  636.             guildConfig.setServerToEdit("");
  637.             return "> Stopped the Server Listing Editing process";
  638.         } else {
  639.             return notAllowed;
  640.         }
  641.     }
  642.  
  643.     @AliasAnnotation(alias = {"Wiki", "Starbounder", "SBWIKI", "Search"})
  644.     @CommandAnnotation(name = "Wiki", description = "Links a Page From Starbounder based on your message", usage = "[Search]")
  645.     public String sailWiki() {
  646.         if (message.toString().length() == getName("sailWiki").length()) {
  647.             return getUsage("sailWiki");
  648.         }
  649.         String[] splitMessage = message.toString().split(" ");
  650.         StringBuilder response = new StringBuilder();
  651.         StringBuilder newMessage = new StringBuilder();
  652.         newMessage.append(message.toString());
  653.         newMessage.delete(0, splitMessage[0].length() + 1);
  654.         String regexedMessage = WordUtils.capitalize(newMessage.toString());
  655.         regexedMessage = regexedMessage.replaceAll(" ", "_");
  656.         response.append("> Here is Your Search\n<http://starbounder.org/Special:Search/");
  657.         response.append(regexedMessage);
  658.         response.append(">");
  659.         return response.toString();
  660.     }
  661.  
  662.     @AliasAnnotation(alias = {"NewCC", "CCnew", "CCmake", "CreateCC", "MakeCC"})
  663.     @CommandAnnotation(name = "NewCC", type = Globals.TYPE_CC, description = "Creates a custom command", usage = "[CommandName] [Message]")
  664.     public String newCC() {
  665.         if (!guild.getID().equals("176434793674833920")) {
  666.             if (message.toString().length() == getName("newCC").length()) {
  667.                 return getUsage("newCC");
  668.             }
  669.             String[] splitString = message.toString().split(" ");
  670.             StringBuilder command = new StringBuilder();
  671.             command.append(message.toString());
  672.             command.delete(0, (splitString[0].length() + splitString[1].length() + 2));
  673.             return customCommands.createCommand(author.getID(), splitString[1], command.toString());
  674.         }else {
  675.             return "> Please use `$NewCC [Name] [Content]` instead.";
  676.         }
  677.     }
  678.  
  679.     @AliasAnnotation(alias = {"DelCC", "CCDel", "RemoveCC"})
  680.     @CommandAnnotation(name = "DelCC", type = Globals.TYPE_CC, description = "Removes the Command", usage = "[CommandName]")
  681.     public String delCC() {
  682.         if (message.toString().length() == getName("delCC").length()) {
  683.             return getUsage("delCC");
  684.         }
  685.         String[] splitString = message.toString().split(" ");
  686.         return customCommands.removeCommand(isMod, author.getID(), splitString[1]);
  687.     }
  688.  
  689.     @AliasAnnotation(alias = {"CClist", "ListCCs"})
  690.     @CommandAnnotation(name = "CCList", type = Globals.TYPE_CC, description = "Lists the Server's Custom Commands", usage = "[Page number]")
  691.     public String listCCs() {
  692.         if (message.getMentions().size() > 0) {
  693.             return customCommands.getUserCommands(message.getMentions().get(0).getID());
  694.         }
  695.         int args = 1;
  696.         boolean isfound = false;
  697.         String[] splitString = message.toString().split(" ");
  698.         if ((splitString.length == 1) || splitString[1].equals("")) {
  699.             args = 1;
  700.         } else {
  701.             char[] chars = splitString[1].toCharArray();
  702.             for (char c : chars) {
  703.                 if (Character.isLetter(c)) {
  704.                     isfound = true;
  705.                 }
  706.             }
  707.             if (!isfound) {
  708.                 args = Integer.parseInt(splitString[1]);
  709.             }
  710.         }
  711.         if (isfound) {
  712.             return "> what are you doing, why are you trying to search for the " + splitString[1] + " page... \n" +
  713.                     "> pretty sure you cant do that...";
  714.         } else {
  715.             return customCommands.listCommands(args);
  716.         }
  717.     }
  718.  
  719.     @CommandAnnotation(name = "GetCCsByID", type = Globals.TYPE_ADMIN, description = "List custom commands of a user using their userID")
  720.     public String listCCbyID() {
  721.         if (isAdmin || isMod) {
  722.             String[] splitString = message.toString().split(" ");
  723.             if ((splitString.length == 1) || splitString[1].equals("")) {
  724.                 return "> Missing Args [Role Name]";
  725.             }
  726.             return customCommands.getUserCommands(splitString[1]);
  727.         } else return notAllowed;
  728.     }
  729.  
  730.     @CommandAnnotation(name = "WhoMadeCC", type = Globals.TYPE_CC, description = "Tells you who made a command.", usage = "[Command]")
  731.     public String whoDunit() {
  732.         String[] splitString = message.toString().split(" ");
  733.         if ((splitString.length == 1) || splitString[1].equals("")) {
  734.             return "> Missing Args [Command]";
  735.         }
  736.         String creator = customCommands.getCreator(splitString[1]);
  737.         if (creator.equals("-1")) {
  738.             return "> Command not found";
  739.         }
  740.         if (creator.equals("locked")) {
  741.             return "> An Admin.";
  742.         }
  743.         return "> " + guild.getUserByID(creator).getDisplayName(guild);
  744.     }
  745.  
  746.     @CommandAnnotation(name = "CCTags", type = Globals.TYPE_CC, description = "List all of the tags available to use in a custom command")
  747.     public String tagsCC() {
  748.         return "You can add any of the following tags to a Custom command to \n" +
  749.                 "get a special responce:\n" +
  750.                 " #author# - replaces with the senders nickname\n" +
  751.                 " #author!# - replaces with the senders username\n" +
  752.                 " #args# - replaces with any text after the command";
  753.     }
  754.  
  755.     @CommandAnnotation(name = "isStreaming", type = Globals.TYPE_ADMIN, description = "Sets The Bot To streaming Mode", usage = "[StreamLink] [Message]", responseGeneral = true)
  756.     public String isStreaming() {
  757.         if (isAdmin || isMod || isOwner) {
  758.             String streamLink;
  759.             String[] splitMessage = message.toString().split(" ");
  760.             StringBuilder builder = new StringBuilder();
  761.             if (message.toString().length() == getName("isStreaming").length()) {
  762.                 message.getClient().changeStatus(Status.game("Starbound"));
  763.                 return "> Stream has stopped thank you all for coming";
  764.             } else streamLink = splitMessage[1];
  765.             builder.append(message.toString());
  766.             builder.delete(0, splitMessage[0].length() + splitMessage[1].length() + 2);
  767.             message.getClient().changeStatus(Status.stream(builder.toString(), splitMessage[1]));
  768.             return "> Check out the stream at: " + streamLink;
  769.         }
  770.         return notAllowed;
  771.     }
  772.  
  773.     @CommandAnnotation(name = "UpdateInfo", type = Globals.TYPE_ADMIN, description = "Posts the info channel contents")
  774.     public String Thinger() {
  775.         if (isOwner) {
  776.             InfoChannel infoChannel = new InfoChannel();
  777.             infoChannel.updateInfo(channel, guild);
  778.             return "";
  779.         } else return notAllowed;
  780.     }
  781.  
  782.     @CommandAnnotation(name = "SaveChar", channel = Globals.CHANNEL_RACE_SELECT, description = "Saves character settings to your current user settings", usage = "[Character Name]")
  783.     public String saveCharacter() {
  784.         String[] splitString = message.toString().split(" ");
  785.         if ((splitString.length == 1) || splitString[1].equals("")) {
  786.             return "> Missing Args [Character Name]";
  787.         }
  788.         return characters.saveChar(author, guild, splitString[1]);
  789.     }
  790.  
  791.     @CommandAnnotation(name = "DelChar", channel = Globals.CHANNEL_RACE_SELECT, description = "Deleted the selected character", usage = "[Character name]")
  792.     public String deleteCharacter() {
  793.         String[] splitString = message.toString().split(" ");
  794.         if ((splitString.length == 1) || splitString[1].equals("")) {
  795.             return "> Missing Args [Character Name]";
  796.         }
  797.         return characters.delChar(author, splitString[1]);
  798.     }
  799.  
  800.     @CommandAnnotation(name = "Char", channel = Globals.CHANNEL_RACE_SELECT, description = "Sets you user settings to the character's Settings", usage = "[Character name]")
  801.     public String selectcharacter() {
  802.         String[] splitString = message.toString().split(" ");
  803.         if ((splitString.length == 1) || splitString[1].equals("")) {
  804.             return "> Missing Args [Character Name]";
  805.         }
  806.         return characters.selChar(author, guild, splitString[1]);
  807.     }
  808.  
  809.     @AliasAnnotation(alias = {"GroupUp", "GU", "Waiting", "Group"})
  810.     @CommandAnnotation(name = "GroupUp", channel = Globals.CHANNEL_SERVERS, description = "Adds you to a Waiting list for grouping up for a game")
  811.     public String groupUp() {
  812.         String response;
  813.         String userID = author.getID();
  814.         response = guildConfig.toggleWaiting(userID, guild);
  815.         return response;
  816.     }
  817.  
  818.     @CommandAnnotation(name = "AddRoleClearance", type = Globals.TYPE_ADMIN, description = "Clears a Role to be able to post Discord Invites", usage = "[Role Name]")
  819.     public String addClearedRole() {
  820.         if (isAdmin) {
  821.             String[] splitString = message.toString().split(" ");
  822.             if ((splitString.length == 1) || splitString[1].equals("")) {
  823.                 return "> Missing Args [Role Name]";
  824.             }
  825.             String roleID = Utility.GetRoleIDFromName(splitString[1], guild);
  826.             if (roleID.equals(Utility.ROLE_NOT_FOUND_ERROR)) {
  827.                 return roleID;
  828.             }
  829.             guildConfig.getClearedRoles();
  830.             guildConfig.addClearedRole(roleID);
  831.             return "> Role Added";
  832.         } else {
  833.             return notAllowed;
  834.         }
  835.     }
  836.  
  837.     @CommandAnnotation(name = "RemoveRoleClearance", type = Globals.TYPE_ADMIN, description = "Removes the role from the roles alowed to post discord invites", usage = "[Role Name]")
  838.     public String removecClearedRole() {
  839.         if (isAdmin) {
  840.             String[] splitString = message.toString().split(" ");
  841.             if ((splitString.length == 1) || splitString[1].equals("")) {
  842.                 return "> Missing Args [Role Name]";
  843.             }
  844.             String roleID = Utility.GetRoleIDFromName(splitString[1], guild);
  845.             if (roleID.equals(Utility.ROLE_NOT_FOUND_ERROR)) {
  846.                 return roleID;
  847.             }
  848.             guildConfig.removeClearedRole(roleID);
  849.             return "Role Removed";
  850.         } else {
  851.             return notAllowed;
  852.         }
  853.     }
  854.  
  855.     @CommandAnnotation(name = "v2Comp", description = "Posts the Comp details to the current channel.")
  856.     public String letsDoThis() {
  857.         if (isCreator) {
  858.             try {
  859.                 channel.sendMessage("@everyone the competition if finally over\n" +
  860.                         "the votes have been tallied and the results are in.\n" +
  861.                         "93 people voted for a total of 277 votes.\n\n" +
  862.                         "The person with the highest total votes is:");
  863.                 Thread.sleep(500);
  864.                 channel.sendFile(new File("Icons/Entry #7.png"), guild.getUserByID("130893885126868992").mention() +
  865.                         " with **74** votes.\n");
  866.                 Thread.sleep(500);
  867.                 channel.sendMessage("\n\u200B" +
  868.                         "\n" +
  869.                         "The next highest total votes is:");
  870.                 Thread.sleep(500);
  871.                 channel.sendFile(new File("Icons/Entry #6.png"), guild.getUserByID("153159020528533505").mention() +
  872.                         " with **63** votes.");
  873.                 Thread.sleep(500);
  874.                 channel.sendMessage("\n\u200B" +
  875.                         "\n" +
  876.                         "Then the third highest vote tally is:");
  877.                 Thread.sleep(500);
  878.                 channel.sendFile(new File("Icons/Entry #4.png"), guild.getUserByID("92401975777333248").mention() +
  879.                         " with **51** votes.");
  880.                 Thread.sleep(500);
  881.                 channel.sendMessage("\n\u200B" +
  882.                         "\n" +
  883.                         "Finally the last of the winners is:");
  884.                 Thread.sleep(500);
  885.                 channel.sendFile(new File("Icons/Entry #9.png"), guild.getUserByID("108341540161646592").mention() +
  886.                         " with **22** votes.");
  887.                 Thread.sleep(500);
  888.                 channel.sendMessage("\n\u200B" +
  889.                         "\n" +
  890.                         "The rest of the votes are as follows.\n" +
  891.                         "5th place: " + guild.getUserByID("142843483923677184").mention() + " with **20** votes.\n" +
  892.                         "6th place: " + guild.getUserByID("197799618984017921").mention() + " with **17** votes.\n" +
  893.                         "7th place: " + guild.getUserByID("99140862579073024").mention() + " with **12** votes.\n" +
  894.                         "8th place: " + guild.getUserByID("119202877372760064").mention() + " with **11** votes.\n" +
  895.                         "9th place: " + guild.getUserByID("186859815673397248").mention() + " with **7** votes.\n" +
  896.                         "Last place: " + guild.getUserByID("108145548736860160").mention() + " with **0** votes. :c\n" +
  897.                         "\n" +
  898.                         "I will be sending a DM to all of the winners and one of my choosing (Because I actually got a winning vote) " +
  899.                         "shortly after this post to organise their prizes which are as follows:\n" +
  900.                         "Access to the " + guild.getChannelByID("201659686116786176").mention() + " and a special role colour of their choosing.\n" +
  901.                         "\n" +
  902.                         "Thank you all for participating in this competition, you will start to see the avatar rotations happen some time within the next" +
  903.                         " couple of days.\n" +
  904.                         "\n" +
  905.                         "- Dawn Felstar.");
  906.             } catch (DiscordException e) {
  907.                 e.printStackTrace();
  908.             } catch (RateLimitException e) {
  909.                 e.printStackTrace();
  910.             } catch (MissingPermissionsException e) {
  911.                 e.printStackTrace();
  912.             } catch (IOException e) {
  913.                 e.printStackTrace();
  914.             } catch (InterruptedException e) {
  915.                 e.printStackTrace();
  916.             }
  917.         }
  918.         return "";
  919.     }
  920. }
Advertisement
Add Comment
Please, Sign In to add comment