Добавление работы с конфликтными частями и исправление вайтлиста

This commit is contained in:
2026-02-25 17:50:11 +07:00
parent 6a4e56c367
commit 54125b82ac
15 changed files with 463 additions and 329 deletions

View File

@@ -105,7 +105,7 @@ class UserSpamStats:
self.total_blocks += 1
self.reputation = max(0.5, self.reputation - 0.3)
def detect_spam_patterns(self, time_window: float = 10.0) -> Dict[str, Any]:
def detect_spam_patterns(self, time_window: float = 2.0) -> Dict[str, Any]:
"""
Умная детекция спама на основе паттернов.
УЛУЧШЕНО: учитывает скорость отправки сообщений.
@@ -120,7 +120,7 @@ class UserSpamStats:
current_time = time()
# 1. КРИТИЧНО: Экстремально быстрая отправка (флуд-бот)
very_recent = [ctx for ctx in recent_contexts if (current_time - ctx.timestamp) < 2.0]
very_recent = [ctx for ctx in recent_contexts if (current_time - ctx.timestamp) < time_window]
if len(very_recent) >= 5:
return {
'is_spam': True,
@@ -133,7 +133,7 @@ class UserSpamStats:
# 2. КРИТИЧНО: 8+ сообщений за 5 секунд => агрессивный флуд
recent_5s = [ctx for ctx in recent_contexts if (current_time - ctx.timestamp) < 5.0]
if len(recent_5s) >= 8:
if len(recent_5s) >= 15:
return {
'is_spam': True,
'reason': 'aggressive_flood',
@@ -145,7 +145,7 @@ class UserSpamStats:
# 3. Медиа-флуд
media_contexts = [ctx for ctx in recent_contexts if ctx.media_type]
if len(media_contexts) >= 7:
if len(media_contexts) >= 15:
media_recent = [ctx for ctx in media_contexts if (current_time - ctx.timestamp) < 5.0]
if len(media_recent) >= 6:
return {
@@ -303,7 +303,8 @@ class AntiSpamMiddleware(BaseMiddleware):
self.enable_reputation = enable_reputation
self.log_all = log_all
def _extract_context(self, event: TelegramObject) -> MessageContext:
@staticmethod
def _extract_context(event: TelegramObject) -> MessageContext:
"""Извлекает контекст из события"""
context = MessageContext()