[+] Fix FS-191

This commit is contained in:
abhiram 2021-04-12 13:57:58 +05:30
parent 37762e5470
commit 4a5a3a1a2d
2 changed files with 15 additions and 3 deletions

View File

@ -296,9 +296,9 @@
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<outputFileName>TotalFreedomMod.jar</outputFileName> <outputFileName>TotalFreedomMod.jar</outputFileName>
<compilerVersion>11</compilerVersion> <compilerVersion>1.8</compilerVersion>
<source>11</source> <source>1.8</source>
<target>11</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -13,6 +13,8 @@ import java.util.Objects;
import java.util.SplittableRandom; import java.util.SplittableRandom;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
@ -60,6 +62,7 @@ public class Discord extends FreedomService
public ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR; public ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR;
public List<CompletableFuture<Message>> sentMessages = new ArrayList<>(); public List<CompletableFuture<Message>> sentMessages = new ArrayList<>();
public Boolean enabled = false; public Boolean enabled = false;
private final Pattern discord_mention_pattern = Pattern.compile("(<@!?([0-9]{16,20})>)");
public static String getMD5(String string) public static String getMD5(String string)
{ {
@ -408,6 +411,15 @@ public class Discord extends FreedomService
message = StringUtils.remove(message, "§"); 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()) if (enabled && !chat_channel_id.isEmpty())
{ {
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true); CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true);