From 4a5a3a1a2d20da8b9bb9a1aa88885c847ebfdf1c Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 13:57:58 +0530 Subject: [PATCH 1/7] [+] Fix FS-191 --- pom.xml | 6 +++--- .../totalfreedommod/discord/Discord.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 99eb47d3..efac5a86 100644 --- a/pom.xml +++ b/pom.xml @@ -296,9 +296,9 @@ 3.8.1 TotalFreedomMod.jar - 11 - 11 - 11 + 1.8 + 1.8 + 1.8 diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 05155cec..b38160be 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -13,6 +13,8 @@ import java.util.Objects; import java.util.SplittableRandom; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.security.auth.login.LoginException; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.admin.Admin; @@ -60,6 +62,7 @@ public class Discord extends FreedomService public ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR; public List> sentMessages = new ArrayList<>(); public Boolean enabled = false; + private final Pattern discord_mention_pattern = Pattern.compile("(<@!?([0-9]{16,20})>)"); public static String getMD5(String string) { @@ -408,6 +411,15 @@ public class Discord extends FreedomService message = StringUtils.remove(message, "§"); } + // Patch FS-191 start + Matcher mention_matcher = this.discord_mention_pattern.matcher(message); + + while (mention_matcher.find()) { + String mention = mention_matcher.group(1); + message = message.replace(mention, "[UserMention-redacted]"); + } + // Patch FS-191 end + if (enabled && !chat_channel_id.isEmpty()) { CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true); From b852ea18228b4fdb7f778665347536c7a66b9922 Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 14:44:27 +0530 Subject: [PATCH 2/7] [+] Update my account in developers list --- src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index b6e5390f..7db66b08 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -72,10 +72,10 @@ public class FUtil "c8e5af82-6aba-4dd7-83e8-474381380cc9", // Paldiu "38ea7c82-7bdc-4f48-b7fd-0e93fc26813d", // AwesomePinch "ba5aafba-9012-418f-9819-a7020d591068", // TFTWPhoenix - "b051abdf-66d1-48c0-96ef-67fb8af96f2a", // Abhi + "d6dd9740-40db-45f5-ab16-4ee16a633009", // Abhi "2e06e049-24c8-42e4-8bcf-d35372af31e6" // unsuperiordev ); - public static final List DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "CoolJWB", "elmon_", "speednt", "SupItsDillon", "Paldiu", "AwesomePinch", "TFTWPhoenix","Spigot_Abhiram", "unsuperiordev"); + public static final List DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "CoolJWB", "elmon_", "speednt", "SupItsDillon", "Paldiu", "AwesomePinch", "TFTWPhoenix","abhithedev", "unsuperiordev"); public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList( ChatColor.DARK_RED, From 385fc777718ab5d61494c897d3cea53e972c4d4f Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 15:44:51 +0530 Subject: [PATCH 3/7] [+] Done all the requested changes! --- pom.xml | 6 +++--- .../totalfreedommod/discord/Discord.java | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index efac5a86..99eb47d3 100644 --- a/pom.xml +++ b/pom.xml @@ -296,9 +296,9 @@ 3.8.1 TotalFreedomMod.jar - 1.8 - 1.8 - 1.8 + 11 + 11 + 11 diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index b38160be..40f47ebf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -62,7 +62,7 @@ public class Discord extends FreedomService public ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR; public List> sentMessages = new ArrayList<>(); public Boolean enabled = false; - private final Pattern discord_mention_pattern = Pattern.compile("(<@!?([0-9]{16,20})>)"); + private final Pattern DISCORD_MENTION_PATTERN = Pattern.compile("(<@!?([0-9]{16,20})>)"); public static String getMD5(String string) { @@ -412,11 +412,11 @@ public class Discord extends FreedomService } // Patch FS-191 start - Matcher mention_matcher = this.discord_mention_pattern.matcher(message); + Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); - while (mention_matcher.find()) { - String mention = mention_matcher.group(1); - message = message.replace(mention, "[UserMention-redacted]"); + while (DISCORD_MENTION_MATCHER.find()) { + String mention = DISCORD_MENTION_MATCHER.group(1); + message = message.replace(mention, mention.replace('@',' ')); } // Patch FS-191 end @@ -445,6 +445,15 @@ public class Discord extends FreedomService message = StringUtils.remove(message, "§"); } + // Patch FS-191 start + Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); + + while (DISCORD_MENTION_MATCHER.find()) { + String mention = DISCORD_MENTION_MATCHER.group(1); + message = message.replace(mention, mention.replace('@',' ')); + } + // Patch FS-191 end + if (enabled && !chat_channel_id.isEmpty()) { CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true); From f7556a486141d7f1c200bb1721a4c9e0c9746792 Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 15:59:27 +0530 Subject: [PATCH 4/7] [+] Remove redundant comments --- .../me/totalfreedom/totalfreedommod/discord/Discord.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 40f47ebf..c90ed31a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -411,14 +411,13 @@ public class Discord extends FreedomService message = StringUtils.remove(message, "§"); } - // Patch FS-191 start + Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); message = message.replace(mention, mention.replace('@',' ')); } - // Patch FS-191 end if (enabled && !chat_channel_id.isEmpty()) { @@ -445,15 +444,14 @@ public class Discord extends FreedomService message = StringUtils.remove(message, "§"); } - // Patch FS-191 start + Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); message = message.replace(mention, mention.replace('@',' ')); } - // Patch FS-191 end - + if (enabled && !chat_channel_id.isEmpty()) { CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true); From ffab5e3c12a531b9dc95682085b9d3525443e4b9 Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 16:01:31 +0530 Subject: [PATCH 5/7] [+] Allman style formating --- .../me/totalfreedom/totalfreedommod/discord/Discord.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index c90ed31a..7cb4c078 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -411,10 +411,11 @@ public class Discord extends FreedomService message = StringUtils.remove(message, "§"); } - + Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); - while (DISCORD_MENTION_MATCHER.find()) { + while (DISCORD_MENTION_MATCHER.find()) + { String mention = DISCORD_MENTION_MATCHER.group(1); message = message.replace(mention, mention.replace('@',' ')); } @@ -447,7 +448,8 @@ public class Discord extends FreedomService Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); - while (DISCORD_MENTION_MATCHER.find()) { + while (DISCORD_MENTION_MATCHER.find()) + { String mention = DISCORD_MENTION_MATCHER.group(1); message = message.replace(mention, mention.replace('@',' ')); } From 4c67553bddad22287f459c29371cd3bad6f32385 Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 16:26:06 +0530 Subject: [PATCH 6/7] [+] Whitespace change! --- .../java/me/totalfreedom/totalfreedommod/discord/Discord.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 7cb4c078..e656868a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -417,7 +417,7 @@ public class Discord extends FreedomService while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); - message = message.replace(mention, mention.replace('@',' ')); + message = message.replace(mention, mention.replace('@','')); } if (enabled && !chat_channel_id.isEmpty()) @@ -451,7 +451,7 @@ public class Discord extends FreedomService while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); - message = message.replace(mention, mention.replace('@',' ')); + message = message.replace(mention, mention.replace('@','')); } if (enabled && !chat_channel_id.isEmpty()) From 0c2f0a714c90e35e3bdf77a231509debc8b13cdf Mon Sep 17 00:00:00 2001 From: abhiram Date: Mon, 12 Apr 2021 16:31:48 +0530 Subject: [PATCH 7/7] [+] Fix #replace() --- .../me/totalfreedom/totalfreedommod/discord/Discord.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index e656868a..484d6016 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -412,12 +412,12 @@ public class Discord extends FreedomService } - Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); + Matcher DISCORD_MENTION_MATCHER = DISCORD_MENTION_PATTERN.matcher(message); while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); - message = message.replace(mention, mention.replace('@','')); + message = message.replace(mention, mention.replace("@","")); } if (enabled && !chat_channel_id.isEmpty()) @@ -446,12 +446,12 @@ public class Discord extends FreedomService } - Matcher DISCORD_MENTION_MATCHER = this.DISCORD_MENTION_PATTERN.matcher(message); + Matcher DISCORD_MENTION_MATCHER = DISCORD_MENTION_PATTERN.matcher(message); while (DISCORD_MENTION_MATCHER.find()) { String mention = DISCORD_MENTION_MATCHER.group(1); - message = message.replace(mention, mention.replace('@','')); + message = message.replace(mention, mention.replace("@","")); } if (enabled && !chat_channel_id.isEmpty())