mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-29 13:05:44 +01:00
Add filtering for which control characters can be sent to Minecraft, add removal of line break spam to default config
This commit is contained in:
parent
6c5064b081
commit
d111fce37b
@ -51,7 +51,9 @@ public class DiscordToMinecraftChatConfig {
|
||||
// TODO: more info on regex pairs (String#replaceAll)
|
||||
@Comment("Regex filters for Discord message contents (this is the %message% part of the \"format\" option)")
|
||||
@Untranslated(Untranslated.Type.VALUE)
|
||||
public Map<Pattern, String> contentRegexFilters = new LinkedHashMap<>();
|
||||
public Map<Pattern, String> contentRegexFilters = new LinkedHashMap<Pattern, String>() {{
|
||||
put(Pattern.compile("\\n{2,}"), "\n");
|
||||
}};
|
||||
|
||||
@Comment("Users, bots, roles and webhooks to ignore")
|
||||
public DiscordIgnoresConfig ignores = new DiscordIgnoresConfig();
|
||||
|
@ -52,9 +52,14 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
|
||||
|
||||
// Filter for ASCII control characters which have no use being displayed, but might be misinterpreted somewhere
|
||||
// Notably this excludes, 0x09 HT (\t), 0x0A LF (\n), 0x0B VT (\v) and 0x0D CR (\r) (which may be used for text formatting)
|
||||
private static final Pattern ASCII_CONTROL_FILTER = Pattern.compile("[\\u0000-\\u0008\\u000C\\u000E-\\u001F\\u007F]");
|
||||
|
||||
private final Map<String, MessageSend> sends = new ConcurrentHashMap<>();
|
||||
|
||||
public DiscordChatMessageModule(DiscordSRV discordSRV) {
|
||||
@ -182,6 +187,7 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
|
||||
}
|
||||
|
||||
Placeholders message = new Placeholders(event.getContent());
|
||||
message.replaceAll(ASCII_CONTROL_FILTER, "");
|
||||
chatConfig.contentRegexFilters.forEach(message::replaceAll);
|
||||
|
||||
Component messageComponent = DiscordSRVMinecraftRenderer.getWithContext(guild, chatConfig, () ->
|
||||
|
Loading…
Reference in New Issue
Block a user