Skip to content

Commit 65b9e0b

Browse files
committed
Remove Discord formatting from perspective messages
1 parent 1c9993f commit 65b9e0b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

extensions/automod.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
from utils.ratelimiter import BucketType
2020

2121
INVITE_REGEX = re.compile(r"(?:https?://)?discord(?:app)?\.(?:com/invite|gg)/[a-zA-Z0-9]+/?")
22+
"""Used to detect and handle Discord invites."""
2223
URL_REGEX = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
24+
"""Used to detect and handle link spam."""
25+
DISCORD_FORMATTING_REGEX = re.compile(r"<\S+>")
26+
"""Remove Discord-specific formatting. Performance is key so some false-positives are acceptable here."""
2327

2428
logger = logging.getLogger(__name__)
2529

@@ -393,6 +397,13 @@ async def scan_messages(
393397
kosu.Attribute(kosu.AttributeName.INSULT),
394398
kosu.Attribute(kosu.AttributeName.THREAT),
395399
]
400+
401+
# Remove custom emojis, mentions, and other Discord-specific formatting
402+
analysis_str = DISCORD_FORMATTING_REGEX.sub("", message.content).strip()
403+
404+
if len(analysis_str) < 3:
405+
return
406+
396407
try:
397408
resp: kosu.AnalysisResponse = await plugin.app.perspective.analyze(message.content, persp_attribs)
398409
except kosu.PerspectiveException as e:

0 commit comments

Comments
 (0)