File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 1919from utils .ratelimiter import BucketType
2020
2121INVITE_REGEX = re .compile (r"(?:https?://)?discord(?:app)?\.(?:com/invite|gg)/[a-zA-Z0-9]+/?" )
22+ """Used to detect and handle Discord invites."""
2223URL_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
2428logger = 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 :
You can’t perform that action at this time.
0 commit comments