Advertisement
Guest User

old vs new mute

a guest
Jul 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.24 KB | None | 0 0
  1.     @Override
  2.     public String execute(String args, CommandObject command) {
  3.         //init vars
  4.         SplitFirstObject userCall = new SplitFirstObject(args);
  5.         IRole mutedRole = command.guild.getMutedRole();
  6.         UserObject mutedUser = Utility.getUser(command, userCall.getFirstWord(), false, false);
  7.         StringHandler response = new StringHandler("> %s was %s%s.");
  8.         StringHandler responseAdmin = new StringHandler("> %s was %s%s by %s in %s with reason `%s`.");
  9.         StringHandler modNote = new StringHandler("> %s by %s. Reason: `%s`. Time: %s. Channel: %s.");
  10.         boolean isMute = UN_MUTE.isSubCommand(command);
  11.         String mode = isMute ? "**Muted**" : "**UnMuted**";
  12.         StringHandler reason = new StringHandler(userCall.getRest());
  13.         long timeSecs = Utility.getRepeatTimeValue(reason);
  14.         StringHandler timeValue = new StringHandler();
  15.         if (timeSecs >= 0) timeValue.setContent(Utility.formatTime(timeSecs, true));
  16.         IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
  17.  
  18.         //check for user and muted role
  19.         if (mutedUser == null || mutedUser.get() == null) return "> Could not find user";
  20.         if (mutedUser.getProfile(command.guild) == null) mutedUser.addProfile(command.guild);
  21.         if (mutedRole == null) return "> Muted role is not configured.";
  22.  
  23.         if (mutedUser.longID == command.user.longID && isMute) return "> Don't try to mute yourself you numpty.";
  24.         if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
  25.             return String.format("> Cannot %s %s. The **%s** role has a higher hierarchy than me.", mode, mutedUser.displayName, mutedRole.getName());
  26.         if (!Utility.testUserHierarchy(command.user.get(), mutedUser.get(), command.guild.get()))
  27.             return String.format("> Cannot %s %s. User hierarchy higher than yours.", mode, mutedUser.displayName);
  28.  
  29.         if (!isMute && timeSecs == -1) {
  30.             command.guild.users.unMuteUser(mutedUser, command.guild);
  31.         } else {
  32.             command.guild.users.muteUser(mutedUser, command.guild, timeSecs);
  33.         }
  34.  
  35.         if (isMute) {
  36.             boolean isStrike = false;
  37.             if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
  38.                 reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
  39.                 isStrike = true;
  40.             }
  41.             modNote.format(mode, command.user.displayName, reason, timeValue, command.channel.mention);
  42.             mutedUser.getProfile(command).addSailModNote(modNote.toString(), command, isStrike);
  43.         }
  44.  
  45.         if (adminChannel != null) {
  46.             responseAdmin.format(mutedUser.mention(), mode, command.user.displayName, command.channel.mention, reason);
  47.             RequestHandler.sendMessage(responseAdmin.toString(), adminChannel);
  48.         }
  49.  
  50.         response.format(mutedUser.mention(), mode);
  51.         return response.toString();
  52.     }
  53.  
  54.  
  55.     @Override
  56.     public String execute(String args, CommandObject command) {
  57.         SplitFirstObject userCall = new SplitFirstObject(args);
  58.         IRole mutedRole = command.guild.getMutedRole();
  59.         UserObject muted = Utility.getUser(command, userCall.getFirstWord(), false, false);
  60.         if (muted == null || muted.get() == null) return "> Could not find user";
  61.         if (muted.getProfile(command.guild) == null) muted.addProfile(command.guild);
  62.         if (mutedRole == null) return "> Muted role is not configured.";
  63.  
  64.         // Un mute subtype
  65.         if (UN_MUTE.isSubCommand(command)) {
  66.             command.guild.users.unMuteUser(muted.longID, command.guild.longID);
  67.             if (!muted.roles.contains(mutedRole)) {
  68.                 return "> " + muted.displayName + " is not muted.";
  69.             }
  70.             return "> " + muted.displayName + " was UnMuted.";
  71.         }
  72.  
  73.         if (muted.longID == command.user.longID) return "> Don't try to mute yourself you numpty.";
  74.         if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
  75.             return "> Cannot Mute " + muted.displayName + ". **" + mutedRole.getName() + "** role has a higher hierarchy than me.";
  76.         if (!Utility.testUserHierarchy(command.user.get(), muted.get(), command.guild.get()))
  77.             return "> Cannot Mute/UnMute " + muted.displayName + ". User hierarchy higher than yours.";
  78.         StringHandler reason = new StringHandler(userCall.getRest());
  79.         long timeSecs = Utility.getRepeatTimeValue(reason);
  80.         boolean isStrike = false;
  81. //        if (reason.toString().isEmpty()) return "> Reason Cannot be empty";
  82.  
  83.         //mute the offender
  84.         command.guild.users.muteUser(muted.longID, command.guild.longID, timeSecs);
  85.  
  86.         //build the response
  87.         //time value
  88.         String timeValue = "";
  89.  
  90.         if (timeSecs >= 0) {
  91.             timeValue = Utility.formatTime(timeSecs, true);
  92.         }
  93.  
  94.         if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
  95.             reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
  96.             isStrike = true;
  97.         }
  98.  
  99.         // setup muted messages
  100.         String msgFormat = "> **%s** was muted%s"; // name was muted for timevalue;
  101.         String adminMsg = " by %s in %s with reason `%s`."; // > name was muted for timevalue by mod in channel with `reason`;
  102.         String modnote = "Muted by %s. Reason: `%s`. Time: %s. Channel: %s."; //name muted with reason `reason` for timevalue in channel;
  103.         IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
  104.  
  105.  
  106.         if (reason.toString().isEmpty()) reason.setContent("No reason given");
  107.         // final responses:
  108.         String responseTime = !timeValue.isEmpty() ? " for " + timeValue : "";
  109.         String response = String.format(msgFormat, muted.mention(), responseTime);
  110.  
  111.         if (adminChannel != null) {
  112.             RequestHandler.sendMessage(response + String.format(adminMsg, command.user.displayName,
  113.                     command.channel.mention, reason), adminChannel);
  114.         }
  115.  
  116.         muted.getProfile(command.guild).addSailModNote(String.format(modnote, command.user.displayName, reason, timeValue, command.channel.mention), command, isStrike);
  117.         return response + ".";
  118.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement