Skip to content

xtoor/Discord-Link-Guardian

Repository files navigation

🛡️ Discord Link Guardian Bot

Discord Link Guardian Banner

🔒 Advanced AI-Powered Link Security for Discord Servers

Protect your Discord community from phishing, crypto scams, and malicious links with intelligent real-time analysis

Python Discord.py Docker AI

License Stars Forks Issues PRs Welcome Ubuntu

FeaturesQuick StartInstallationConfigurationUsageAI ProvidersContributing


🌟 Features

🤖 AI-Powered Analysis

  • 🧠 Multiple AI Provider Support (OpenAI, Anthropic, Local LLMs)
  • 🔍 Content Analysis for phishing detection
  • 📊 Reputation Scoring from web searches
  • 🎯 Smart Threat Classification

🛡️ Security Checks

  • 🔐 SSL Certificate Validation
  • 📅 Domain Age Verification
  • 🌐 Blacklist Database Checking
  • 🔗 URL Shortener Resolution
  • 🎭 Homograph Attack Detection

Automated Moderation

  • ⚠️ 3-Strike Warning System
  • 🔇 Auto-mute (15 days) after warnings
  • 🔨 Permanent Ban for repeat offenders
  • 👮 Admin Notifications for threats

🐳 Easy Deployment

  • 📦 100% Dockerized
  • 🚀 Interactive Installer Script
  • 🔧 Auto-dependency Management
  • 📝 Comprehensive Logging

🚀 Quick Start

# Clone the repository
git clone https://github.com/xtoor/discord-link-guardian.git
cd discord-link-guardian

# Run the interactive installer
sudo chmod +x installer.sh
sudo ./installer.sh

# Follow the prompts to configure your bot

📋 Prerequisites

Ubuntu
Ubuntu 20.04+
Docker
Docker 20.10+
Python
Python 3.11+
Discord
Discord Bot Token

🔧 Installation

Option 1: Automated Installation (Recommended) 🎯

# Download and run the installer
wget https://raw.githubusercontent.com/xtoor/discord-link-guardian/main/installer.sh
sudo chmod +x installer.sh
sudo ./installer.sh

The installer will:

  • ✅ Check system compatibility
  • ✅ Install Docker & Docker Compose
  • ✅ Configure the bot interactively
  • ✅ Build Docker images
  • ✅ Test the installation
  • ✅ Set up systemd service (optional)

Option 2: Manual Installation 🔨

Click to expand manual installation steps

1️⃣ Install Docker

# Update package index
sudo apt update

# Install prerequisites
sudo apt install -y ca-certificates curl gnupg lsb-release

# Add Docker's GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Set up repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2️⃣ Clone Repository

git clone https://github.com/yourusername/discord-link-guardian.git
cd discord-link-guardian

3️⃣ Configure Environment

# Copy example environment file
cp .env.example .env

# Edit with your settings
nano .env

4️⃣ Build and Run

# Build Docker image
docker build -t discord-link-guardian -f docker/Dockerfile .

# Start the bot
docker-compose -f docker/docker-compose.yml up -d

⚙️ Configuration

🔑 Environment Variables

Create a .env file in the project root:

# Discord Configuration
DISCORD_TOKEN=your_bot_token_here

# AI Provider (choose one)
OPENAI_API_KEY=your_openai_key      # For ChatGPT
ANTHROPIC_API_KEY=your_claude_key   # For Claude
LOCAL_MODEL=llama2                   # For Ollama

# Search API (optional but recommended)
SEARCH_API_KEY=your_serpapi_key     # For web reputation checks

📝 Configuration File

Edit configs/config.yaml:

bot:
  prefix: "!"                        # Command prefix
  status: "Protecting your server"   # Bot status message
  
moderation:
  warnings_before_mute: 3            # Warnings before auto-mute
  mute_duration_days: 15             # Mute duration in days
  warnings_before_ban: 5             # Total warnings before ban
  
ai:
  provider: "openai"                 # openai, anthropic, or local
  model: "gpt-4"                     # Model to use
  
security:
  threat_thresholds:
    safe: 0.2                        # Below = safe
    suspicious: 0.5                  # Below = caution
    danger: 0.8                      # Above = danger

🎮 Usage

🤖 Bot Commands

Command Description Permission
!warnings [@user] Check warnings for a user Everyone
!unmute @user Manually unmute a user Admin
!linkstats View link analysis statistics Admin
!config View current configuration Admin
!test <url> Test a URL without action Admin

🔍 Link Analysis Process

graph LR
    A[Link Posted] --> B{Analysis Engine}
    B --> C[Domain Check]
    B --> D[SSL Validation]
    B --> E[AI Analysis]
    B --> F[Web Reputation]
    
    C --> G{Threat Level}
    D --> G
    E --> G
    F --> G
    
    G -->|Safe| H[✅ Allow]
    G -->|Suspicious| I[⚠️ Warning]
    G -->|Danger| J[🚫 Remove & Warn]
    
    J --> K{Warning Count}
    K -->|< 3| L[Log Warning]
    K -->|= 3| M[🔇 Mute 15 Days]
    K -->|> 5| N[🔨 Ban User]
Loading

📊 Threat Levels

Level Score Action Description
✅ Safe 0.0 - 0.2 Allow Link appears legitimate
ℹ️ Caution 0.2 - 0.5 Info Message Limited information available
⚠️ Suspicious 0.5 - 0.8 Public Warning Potential threat detected
🚫 Danger 0.8 - 1.0 Remove & Warn High confidence threat

🧠 AI Providers

OpenAI (ChatGPT) 🤖

ai:
  provider: "openai"
  model: "gpt-4"  # or gpt-3.5-turbo

Anthropic (Claude) 🎭

ai:
  provider: "anthropic"
  model: "claude-3-opus-20240229"

Local LLM (Ollama) 🏠

ai:
  provider: "local"
  model: "llama2"  # or mistral, codellama, etc.
Setting up Ollama for Local AI
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh

# Pull a model
ollama pull llama2

# The installer will handle the rest!

📁 Project Structure

discord-link-guardian/
│
├── 🐳 docker/
│   ├── Dockerfile              # Container configuration
│   └── docker-compose.yml      # Service orchestration
│
├── 🤖 src/
│   ├── bot.py                 # Main bot logic
│   ├── link_analyzer.py       # URL analysis engine
│   ├── ai_analyzer.py         # AI integration
│   ├── moderation.py          # User moderation system
│   ├── database.py            # SQLite database handler
│   └── config.py              # Configuration manager
│
├── ⚙️ configs/
│   ├── config.yaml            # Bot configuration
│   └── blacklists/            # Domain blacklists
│
├── 📊 data/
│   └── bot.db                 # SQLite database
│
├── 📝 logs/
│   └── bot.log                # Application logs
│
├── 📚 docs/
│   ├── API.md                 # API documentation
│   └── CONTRIBUTING.md        # Contribution guidelines
│
├── 🔧 scripts/
│   ├── installer.sh           # Interactive installer
│   └── update.sh              # Update script
│
├── 📋 requirements.txt        # Python dependencies
├── 🔑 .env.example           # Environment template
├── 📜 LICENSE                # MIT License
└── 📖 README.md              # This file

🐳 Docker Management

🎯 Common Commands

# Start the bot
docker-compose up -d

# View logs
docker logs -f discord-link-guardian

# Stop the bot
docker-compose down

# Restart the bot
docker-compose restart

# Update and rebuild
git pull
docker-compose build
docker-compose up -d

# View resource usage
docker stats discord-link-guardian

🔄 Auto-restart with Systemd

# Enable auto-start on boot
sudo systemctl enable discord-link-guardian

# Service management
sudo systemctl start discord-link-guardian
sudo systemctl stop discord-link-guardian
sudo systemctl status discord-link-guardian

# View logs
journalctl -u discord-link-guardian -f

🔒 Security Features

🛡️ Domain Analysis

  • ✅ Reputation checking
  • ✅ Age verification
  • ✅ SSL/TLS validation
  • ✅ WHOIS lookup

🔍 Pattern Detection

  • ✅ Phishing patterns
  • ✅ URL shorteners
  • ✅ Suspicious TLDs
  • ✅ Homograph attacks

🤖 AI Detection

  • ✅ Content analysis
  • ✅ Scam detection
  • ✅ Credential harvesting
  • ✅ Social engineering

📈 Monitoring & Analytics

📊 Dashboard Metrics

The bot tracks and logs:

  • 📌 Total links analyzed
  • ⚠️ Threats detected
  • 👥 Users warned/muted/banned
  • 📈 Detection accuracy
  • 🕐 Response times

📝 Log Files

# View real-time logs
tail -f logs/bot.log

# Search for specific events
grep "THREAT" logs/bot.log
grep "WARNING" logs/bot.log

# View Docker logs
docker logs discord-link-guardian --tail 100 -f

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

🐛 Found a Bug?

  1. Check existing issues
  2. Create a new issue with:
    • Clear description
    • Steps to reproduce
    • Expected behavior
    • Logs/screenshots

💡 Feature Requests

Open an issue with the enhancement label!

🔧 Pull Requests

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Discord Link Guardian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

🌟 Star History

Star History Chart


👥 Support

Need Help? 💬

Discord GitHub Issues Email

Acknowledgments 🙏


Made with ❤️ by the Discord Link Guardian Team
Keeping Discord communities safe, one link at a time

Status Maintained

About

Checks for links on discord for potential scam sites/apps

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors