Beta/superviseur/heuristic.py

47 lines
1.8 KiB
Python
Raw Normal View History

2026-02-06 22:23:20 +01:00
def _assess_heuristic_risk(self, message) -> bool:
"""
Fast Python-side risk assessment to decide if we should AI-analyze fully.
Returns True if message is 'risky' enough to warrant LLM usage.
"""
score = 0
content = message.content
# 1. Social Score Factor (Base scrutiny)
# If user is Suspect (<40), we start with higher risk score
social_data = self.social_manager.get_user_data(message.author.id)
reliability = social_data.get('score', 50)
if reliability < 30: score += 40 # Very suspicious user -> almost auto-check
elif reliability < 50: score += 20
# 2. Pattern Matching (Fast Regex/Keywords)
content_lower = content.lower()
# CAPS LOCK detection (> 60% caps on long messages)
if len(content) > 10:
caps_ratio = sum(1 for c in content if c.isupper()) / len(content)
if caps_ratio > 0.6: score += 30
# Profanity / Trigger words (lightweight list)
triggers = ["raid", "hack", "pute", "connard", "fdp", "tg", "merde", "nazi", "hitler", "suicide", "bomb", "token", "grab", "nitro", "steam", "discord.gift", "free", "@everyone", "@here"]
for t in triggers:
if t in content_lower:
score += 50
break
# Link spam detection
if "http" in content_lower:
score += 15
# Length anomaly (very long messages often rants)
if len(content) > 400:
score += 20
# 3. Mention Spam
if len(message.mentions) > 3:
score += 40
# Threshold decision
# If score > 45, we analyze.
return score >= 45