Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ SentinelBot β€” Telegram Moderation Bot for Web3 Communities

A production-ready, self-hosted Telegram group moderation bot built specifically for crypto/Web3 communities. Combines the best features from 10+ analyzed open-source bots into a single, configurable solution.

✨ Features

πŸ”’ Anti-Spam & Scam Detection

  • Pattern-based spam detection β€” 30+ crypto-specific spam patterns
  • CAS integration β€” Combot Anti-Spam System checks against known spammer database
  • Crypto scam detection β€” Wallet phishing, fake airdrops, seed phrase scams
  • Crypto address spam β€” Detects unsolicited ETH/BTC/SOL/TRON addresses
  • Phishing URL detection β€” Catches fake DEX, wallet, and DeFi sites
  • Heuristic analysis β€” Excessive caps, emojis, repeated chars

πŸ”‘ Captcha Verification

  • Math captcha β€” Solve a math problem to verify
  • Button captcha β€” Tap the correct emoji
  • Configurable timeout β€” Auto-kick if not solved in time
  • Auto-restriction β€” New members can't post until verified

πŸ”— Link Filtering

  • Whitelist mode β€” Only approved domains allowed
  • Blacklist mode β€” Block specific domains
  • URL shortener blocking β€” bit.ly, tinyurl, etc. auto-blocked
  • Telegram invite filtering β€” Block group invite links
  • Admin-configurable β€” Add/remove domains via commands

🌊 Flood Protection

  • Rate limiting β€” Max messages per time window
  • Duplicate detection β€” Blocks repeated identical messages
  • Minimum interval β€” Prevents rapid-fire messages
  • Configurable actions β€” Warn, mute, or ban

⚠️ Warning System

  • Progressive warnings β€” 1st warn β†’ 2nd mute β†’ 3rd ban (configurable)
  • Expiring warnings β€” Warnings auto-expire after 30 days
  • Admin tracking β€” All warnings logged with reason and admin
  • Self-check β€” Users can check their own warnings

πŸ“‹ Audit Logging

  • Database logging β€” Every moderation action recorded
  • Channel logging β€” Optional Telegram channel for audit trail
  • File logging β€” Application logs to data/sentinel.log
  • Admin stats β€” View action statistics per chat

πŸ‘‹ Welcome System

  • Customizable messages β€” Template variables ({mention}, {group_name}, etc.)
  • Auto-delete β€” Join/leave messages auto-deleted
  • Scam warnings β€” Built-in "admins never DM first" warning

πŸš€ Quick Start

Prerequisites

  • Python 3.10+ (or Docker)
  • A Telegram Bot Token from @BotFather

1. Clone & Setup

git clone <your-repo-url>
cd telegram-mod-bot

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

2. Configure

cp .env.example .env
nano .env  # or your editor of choice

Required settings:

BOT_TOKEN=your_bot_token_here
OWNER_ID=your_telegram_user_id

Optional but recommended:

LOG_CHANNEL_ID=-1001234567890  # Private channel for audit logs
ADMIN_IDS=123456789,987654321  # Additional admin IDs
CAS_ENABLED=true               # Combot Anti-Spam checking

3. Run

# Development (polling mode)
python -m bot.main

# Or with Docker
docker-compose up -d

4. Add to Your Group

  1. Add the bot to your Telegram group
  2. Promote it to admin with these permissions:
    • βœ… Delete messages
    • βœ… Ban users
    • βœ… Invite users (for captcha)
    • βœ… Restrict members
    • βœ… Pin messages (optional)
  3. Send /help in the group to verify it's working

πŸ“‹ Commands

User Commands

Command Description
/help Show all available commands
/rules Show group rules
/report Report a message (reply to it)
/mywarns Check your warning count

Admin Commands

Command Description
/ban [reason] Ban a user (reply or ID)
/unban Unban a user
/kick [reason] Kick a user (can rejoin)
/mute [duration] Mute a user (e.g., /mute 1h)
/unmute Unmute a user
/warn [reason] Warn a user
/warns Check a user's warnings
/clearwarns Clear a user's warnings
/purge [n] Delete last n messages

Settings Commands (Admin)

Command Description
/settings View current moderation settings
/setcaptcha on|off Toggle captcha verification
/setlinks on|off Toggle link filtering
/addlink domain.com Add domain to whitelist
/rmlink domain.com Remove domain from whitelist

Owner Commands

Command Description
/stats View moderation statistics
/auditlog View recent audit log entries

βš™οΈ Configuration

Environment Variables

Variable Required Default Description
BOT_TOKEN βœ… β€” Telegram bot token
OWNER_ID βœ… β€” Your Telegram user ID
ADMIN_IDS ❌ β€” Additional admin IDs (comma-separated)
LOG_CHANNEL_ID ❌ β€” Channel ID for audit logs
DATABASE_URL ❌ SQLite Database connection string
CAS_ENABLED ❌ true Enable CAS spam checking
WEBHOOK_URL ❌ β€” Webhook URL (production)
WEBHOOK_PORT ❌ 8443 Webhook port
OPENAI_API_KEY ❌ β€” OpenAI key for AI spam detection

Per-Group Configuration

Copy config/default_config.yaml and customize for each group. Place configs in data/groups/<group_id>.yaml.

Pre-configured Whitelisted Domains

The following domains are whitelisted by default:

  • telegram.org, t.me
  • github.com, twitter.com, x.com
  • sonic.game, soniclabs.com
  • ethereum.org, etherscan.io
  • coingecko.com, coinmarketcap.com
  • dexscreener.com, defillama.com

Modify in /config/settings.py or via /addlink and /rmlink commands.


🐳 Docker Deployment

Build and Run

# Build image
docker build -t sentinel-bot .

# Run with docker-compose
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

Production Deployment (Webhook Mode)

For production, use webhook mode with a reverse proxy:

WEBHOOK_URL=https://your-domain.com
WEBHOOK_PORT=8443
WEBHOOK_PATH=/webhook

Nginx config example:

server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location /webhook {
        proxy_pass http://localhost:8443;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

VPS Deployment (systemd)

# Copy files to server
scp -r . user@server:/opt/sentinel-bot

# Create systemd service
sudo cat > /etc/systemd/system/sentinel-bot.service << 'EOF'
[Unit]
Description=SentinelBot Telegram Moderation
After=network.target

[Service]
Type=simple
User=sentinel
WorkingDirectory=/opt/sentinel-bot
ExecStart=/opt/sentinel-bot/.venv/bin/python -m bot.main
Restart=always
RestartSec=10
EnvironmentFile=/opt/sentinel-bot/.env

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable --now sentinel-bot

πŸ—οΈ Architecture

telegram-mod-bot/
β”œβ”€β”€ bot/
β”‚   β”œβ”€β”€ main.py              # Entry point, handler registration
β”‚   β”œβ”€β”€ handlers/
β”‚   β”‚   β”œβ”€β”€ commands.py       # All slash commands
β”‚   β”‚   β”œβ”€β”€ moderation.py     # Core message processing pipeline
β”‚   β”‚   β”œβ”€β”€ welcome.py        # New member handling & captcha
β”‚   β”‚   └── callbacks.py      # Inline button handlers
β”‚   β”œβ”€β”€ filters/
β”‚   β”‚   β”œβ”€β”€ spam.py           # Pattern-based spam detection
β”‚   β”‚   β”œβ”€β”€ crypto_scam.py    # Crypto-specific scam detection
β”‚   β”‚   β”œβ”€β”€ links.py          # URL/domain filtering
β”‚   β”‚   └── flood.py          # Flood/rate limit detection
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ cas.py            # CAS integration
β”‚   β”‚   β”œβ”€β”€ captcha_generator.py  # Captcha generation
β”‚   β”‚   └── audit_log.py      # Audit logging service
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   └── db.py             # SQLite database layer
β”‚   └── utils/
β”‚       β”œβ”€β”€ permissions.py    # Admin/owner permission checks
β”‚       └── helpers.py        # Utility functions
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ settings.py           # Configuration management
β”‚   └── default_config.yaml   # Per-group config template
β”œβ”€β”€ data/                     # Runtime data (DB, logs)
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ requirements.txt
└── .env.example

Moderation Pipeline

Every group message flows through this pipeline:

Message β†’ Admin Check (skip) β†’ Verified Check β†’ Flood β†’ Spam β†’ Scam β†’ Links β†’ βœ… Pass
                                    ↓              ↓       ↓       ↓       ↓
                                  Delete         Mute    Warn+Del Ban+Del Warn+Del

πŸ”§ Customization

Adding Custom Spam Patterns

Edit bot/filters/spam.py β€” add patterns to SPAM_PATTERNS:

SPAM_PATTERNS = [
    # Your custom patterns
    (r"(?i)your_regex_pattern_here", "Description"),
    ...
]

Adding Custom Scam Patterns

Edit bot/filters/crypto_scam.py β€” add to SCAM_PATTERNS:

SCAM_PATTERNS = [
    (re.compile(r'your_pattern'), "scam_type", "Description"),
    ...
]

Whitelisting Domains

Either edit config/settings.py or use commands:

/addlink sonic.game
/addlink soniclabs.com
/rmlink suspicious-site.xyz

πŸ“Š Compared To

This bot was designed by analyzing 10+ open-source Telegram moderation bots. See RESEARCH.md for the full analysis.

Feature SentinelBot tg-spam JoinCaptcha Samurai Origin
Anti-Spam βœ… βœ… ❌ βœ… βœ…
CAS Integration βœ… βœ… ❌ ❌ ❌
Captcha βœ… ❌ βœ… ❌ ❌
Crypto Scam Detection βœ… ❌ ❌ ❌ Partial
Link Filter βœ… βœ… βœ… ❌ βœ…
Flood Protection βœ… ❌ ❌ βœ… ❌
Warning System βœ… ❌ ❌ ❌ ❌
Audit Log βœ… βœ… ❌ βœ… βœ…
Docker βœ… βœ… βœ… βœ… βœ…
Lightweight (<100MB RAM) βœ… βœ… βœ… ❌ (800MB) βœ…

πŸ“œ License

MIT β€” Use freely for your Web3 community.


Built with ❀️ for the Web3 community.

About

Production-ready Telegram moderation bot for Web3 communities. Crypto scam detection, CAPTCHA verification, anti-spam, and comprehensive moderation tools.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages