File size: 1,882 Bytes
4a693cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
################################################################################
#FILE: backend/app/services/telegram_mod.py
#VERSION: 1.0.1 | SYSTEM: Jarvis Protocol
################################################################################

import logging
import asyncio
# 🚀 FIX: Added 'app.' prefix
from app.core.config import settings

logger = logging.getLogger("Telegram-Bouncer")

class TelegramModerator:
    def __init__(self):
        self.bot_token = getattr(settings, "TELEGRAM_BOT_TOKEN", None)
        self.banned_words = ["spoonfeed", "leak", "exam answers", "buy signal", "crypto pump"]

        if self.bot_token:
            logger.info("Telegram Bouncer is at the door. Checking IDs.")
        else:
            logger.warning("No Telegram bot token. The group chat is currently the Wild West.")

    async def check_message(self, user_id: str, message_text: str) -> dict:
        logger.info(f"Scanning message from user {user_id}...")
        message_lower = message_text.lower()

        for word in self.banned_words:
            if word in message_lower:
                logger.warning(f"Opp detected! User {user_id} used banned word: {word}")
                return {
                    "action": "DELETE_AND_WARN",
                    "message": f"Bro, we don't do '{word}' here. Lock in and study. Strike 1."
                }

        if "anatomy" in message_lower or "usmle" in message_lower:
            return {"action": "REACT", "emoji": "🧠", "message": "Valid academic discussion. Let him cook."}

        return {"action": "NONE", "message": "Message clean. Vibe check passed."}

    async def start_polling(self):
        if not self.bot_token:
            return

        logger.info("Starting Telegram polling loop... Watchlist active.")
        while True:
            await asyncio.sleep(5)

telegram_bouncer = TelegramModerator()