Vaerys_Dawn

Tags system

Sep 19th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. @CommandAnnotation(name = "TagSystem", description = "tests the tag system", usage = "[args]",
  2.         type = Constants.TYPE_ADMIN, channel = Constants.CHANNEL_SHITPOST, requiresArgs = true)
  3. public String testtags() {
  4.     String response = args;
  5.     String tagRandom;
  6.     String tagRegex;
  7.     String prefixRandom = "#random#{";
  8.     String prefixRegex = "#regex#{";
  9.     String lastAttepmt;
  10.     try {
  11.         if (response.contains(prefixRandom)) {
  12.             do {
  13.                 lastAttepmt = response;
  14.                 tagRandom = StringUtils.substringBetween(args, prefixRandom, "}");
  15.                 if (tagRandom != null) {
  16.                     ArrayList<String> splitRandom = new ArrayList<>(Arrays.asList(tagRandom.split(";")));
  17.                     Random random = new Random();
  18.                     String toRegex = "#random#\\{" + tagRandom + "\\}";
  19.                     response = response.replaceFirst(toRegex, splitRandom.get(random.nextInt(splitRandom.size())));
  20.  
  21.                 }
  22.             } while (StringUtils.countMatches(response, prefixRandom) > 0 && (!lastAttepmt.equals(response)));
  23.         }
  24.         if (response.contains(prefixRegex)) {
  25.             do {
  26.                 lastAttepmt = response;
  27.                 tagRegex = StringUtils.substringBetween(args, prefixRegex, "}");
  28.                 if (tagRegex != null) {
  29.                     ArrayList<String> splitRegex = new ArrayList<>(Arrays.asList(tagRegex.split(";")));
  30.                     String toRegex = "#regex#\\{" + tagRegex + "\\}";
  31.                     if (splitRegex.size() == 2) {
  32.                         response = response.replaceAll(toRegex, "");
  33.                         response = response.replaceAll(splitRegex.get(0), splitRegex.get(1));
  34.                     } else {
  35.                         response = response.replaceAll(tagRegex, "#ERROR#");
  36.                     }
  37.                 }
  38.             } while (StringUtils.countMatches(response, prefixRegex) > 0 && (!lastAttepmt.equals(response)));
  39.         }
  40.     } catch (PatternSyntaxException ex) {
  41.         return "> An Error occurred while attempting to run this command.";
  42.     }
  43.     response = response.replaceAll("#author#", author.getDisplayName(guild));
  44.     response = response.replaceAll("#channel#", channel.mention());
  45.     response = response.replaceAll("#guild#", guild.getName());
  46.     response = response.replaceAll("#authorID#", author.getID());
  47.     response = response.replaceAll("#channelID#", channel.getID());
  48.     response = response.replaceAll("#guildID#", guild.getID());
  49.     response = response.replaceAll("@everyone,", "**[REDACTED]**");
  50.     response = response.replaceAll("@here", "**[REDACTED]**");
  51.     return response;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment