Advertisement
Vaerys_Dawn

Aweful bad code

Aug 16th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.01 KB | None | 0 0
  1. private void handleCommand(CommandObject commandObject, String command, String args) {
  2.         IChannel channel = commandObject.channel.get();
  3.         GuildConfig guildconfig = commandObject.guild.config;
  4.         List<Command> commands = commandObject.guild.commands;
  5.         IDiscordClient client = commandObject.client.get();
  6.         for (Command c : commands) {
  7.             for (String name : c.names()) {
  8.                 if (command.equalsIgnoreCase(guildconfig.getPrefixCommand() + name)) {
  9.                     if (c.type().equals(Command.TYPE_CREATOR) && !commandObject.user.stringID.equalsIgnoreCase(Globals.creatorID)) {
  10.                         return;
  11.                     }
  12.  
  13.                     logger.debug(Utility.loggingFormatter("COMMAND", command, args, commandObject));
  14.  
  15.                     //permissions checking
  16.                     if (c.perms().length != 0 && !Utility.canBypass(commandObject.user.get(), commandObject.guild.get())) {
  17.                         if (!Utility.testForPerms(c.perms(), commandObject.user.get(), commandObject.guild.get())) {
  18.                             Utility.sendMessage(commandObject.user.notAllowed, channel);
  19.                             return;
  20.                         }
  21.                     }
  22.  
  23.                     //channel checking
  24.                     if (c.channel() != null && !Utility.canBypass(commandObject.user.get(), commandObject.guild.get())) {
  25.                         boolean channelFound = false;
  26.                         List<String> channelMentions = new ArrayList<>();
  27.                         for (ChannelSetting s : commandObject.guild.channelSettings) {
  28.                             if (s.type().equals(c.channel())) {
  29.                                 if (s.getIDs(commandObject.guild.config) != null) {
  30.                                     for (String id : s.getIDs(commandObject.guild.config)) {
  31.                                         if (id.equals(commandObject.channel.stringID)) {
  32.                                             channelFound = true;
  33.                                         }
  34.                                         IChannel testPerms = client.getChannelByID(id);
  35.                                         EnumSet<Permissions> userPerms = testPerms.getModifiedPermissions(commandObject.user.get());
  36.                                         if (userPerms.contains(Permissions.SEND_MESSAGES) && userPerms.contains(Permissions.READ_MESSAGES)) {
  37.                                             channelMentions.add(commandObject.client.get().getChannelByID(id).mention());
  38.                                         }
  39.                                     }
  40.                                 } else {
  41.                                     channelFound = true;
  42.                                 }
  43.                             }
  44.                         }
  45.                         //correct channel message formatting
  46.                         if (!channelFound) {
  47.                             if (channelMentions.size() == 0) {
  48.                                 Utility.sendMessage("> You do not have access to any channels that you are able to run this command in.", channel);
  49.                             } else if (channelMentions.size() > 1) {
  50.                                 Utility.sendMessage("> Command must be performed in any of the following channels: \n" + Utility.listFormatter(channelMentions, true), channel);
  51.                             } else {
  52.                                 Utility.sendMessage("> Command must be performed in: " + channelMentions.get(0), channel);
  53.                             }
  54.                             return;
  55.                         }
  56.                     }
  57.  
  58.                     //arguments checking.
  59.                     if (c.requiresArgs() && args.isEmpty()) {
  60.                         Utility.sendMessage(Utility.getCommandInfo(c, commandObject), channel);
  61.                         return;
  62.                     }
  63.  
  64.                     //command logging
  65.                     if (c.doAdminLogging()) {
  66.                         if (guildconfig.adminLogging) {
  67.                             handleLogging(commandObject, args, c, true);
  68.                         }
  69.                     } else {
  70.                         if (guildconfig.generalLogging) {
  71.                             handleLogging(commandObject, args, c, false);
  72.                         }
  73.                     }
  74.                     if (!commandObject.channel.get().getTypingStatus()) {
  75.                         commandObject.channel.get().toggleTypingStatus();
  76.                     }
  77.                     try {
  78.                         Utility.sendMessage(c.execute(args, commandObject), channel);
  79.                     } catch (Exception e) {
  80.                         Utility.sendMessage("> I caught an Error, Please send this to my **Direct Messages** so my developer can look at it.\n```\n"
  81.                                 + e.getClass().getName() + ": " + e.getMessage() + "```", channel);
  82.                         Utility.sendStack(e);
  83.                     }
  84.                 }
  85.             }
  86.         }
  87.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement