Skip to content

allthingslinux/atl-wiki-link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ATL Wiki Bot

A Discord bot system that verifies Discord users against MediaWiki accounts using OAuth, designed for the All Things Linux community.

πŸ—οΈ Architecture

This is a monorepo containing two main components:

  • Discord Bot (bot/) - Handles Discord interactions and user verification
  • Flask API (api/) - Manages OAuth flow and MediaWiki integration
  • PostgreSQL Database - Stores verification data and user links
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Discord Bot   β”‚    β”‚   Flask API     β”‚    β”‚   MediaWiki     β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Commands      │◄──►│ β€’ OAuth Flow    │◄──►│ β€’ User Verify   β”‚
β”‚ β€’ Role Mgmt     β”‚    β”‚ β€’ JWT Tokens    β”‚    β”‚ β€’ Account Link  β”‚
β”‚ β€’ Verification  β”‚    β”‚ β€’ Database      β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚
         └───────────────────────┼────────────────────────────────┐
                                 β”‚                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
                    β”‚    PostgreSQL Database    β”‚                 β”‚
                    β”‚                           β”‚                 β”‚
                    β”‚ β€’ User links              β”‚                 β”‚
                    β”‚ β€’ Verification tokens     β”‚                 β”‚
                    β”‚ β€’ Audit logs              β”‚                 β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
                                                                  β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”
                              β”‚            Docker Network           β”‚
                              β”‚                                     β”‚
                              β”‚ β€’ Service discovery                 β”‚
                              β”‚ β€’ Internal communication            β”‚
                              β”‚ β€’ Isolated environment              β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

  • πŸ”— MediaWiki Integration: OAuth-based verification with MediaWiki
  • πŸ€– Discord Commands: Easy-to-use slash commands for verification
  • πŸ‘₯ Role Management: Automatic role assignment for verified users
  • πŸ“Š Admin Tools: User management and verification statistics
  • πŸ—„οΈ Database Persistence: PostgreSQL for reliable data storage
  • 🐳 Docker Ready: Full containerization with Docker Compose
  • πŸ“ Rich Logging: Comprehensive logging with emoji indicators
  • πŸ”’ Security: JWT tokens, secure OAuth flow, environment-based secrets

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • A Discord application with bot permissions
  • MediaWiki OAuth consumer credentials

1. Clone and Setup

git clone <repository-url>
cd atl-wiki-bot
cp env.example .env

2. Configure Environment

Edit .env with your credentials:

# Discord Configuration
DISCORD_TOKEN=your_discord_bot_token_here
WIKI_AUTHOR_ROLE_ID=123456789012345678
ALLOWED_ROLE_IDS=123456789012345678,987654321098765432
DISCORD_PREFIX="w$"

# MediaWiki OAuth (get from Special:OAuthConsumerRegistration)
MW_CONSUMER_KEY=your_mediawiki_consumer_key
MW_CONSUMER_SECRET=your_mediawiki_consumer_secret
MW_API_URL=https://your.wiki.org/api.php

# API Security Keys (generate random secure strings)
FLASK_SECRET_KEY=your_super_secret_flask_key_here
JWT_SECRET=your_jwt_secret_key_here

# API URLs (adjust for production)
VERIFICATION_URL=http://localhost:5000/verify
CALLBACK_URL=http://localhost:5000/verify/callback

# Database URL (uses Docker service name 'db')
DATABASE_URL=postgresql://wiki-link-user:password@db:5432/wiki-link-db

Note: The database URL is automatically configured for Docker. Only change if using external database.

3. Launch with Docker

# Start all services
docker compose up -d

# View logs
docker compose logs -f

# Stop services
docker compose down

4. Verify Setup

  • Bot should appear online in Discord
  • API accessible at http://localhost:5000
  • Database running on port 5432

πŸ› οΈ Development

Local Development Setup

# Install Poetry (if not installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

# Activate virtual environment
poetry shell

Running Components Individually

# Run Discord bot
poetry run python -m bot.main

# Run Flask API
poetry run python -m api.app

# Run with auto-reload (development)
docker compose up --watch

Project Structure

atl-wiki-bot/
β”œβ”€β”€ bot/                    # Discord Bot
β”‚   β”œβ”€β”€ commands/           # Slash commands
β”‚   β”‚   └── verification.py # Verification commands
β”‚   β”œβ”€β”€ core/              # Core functionality
β”‚   β”‚   β”œβ”€β”€ config.py      # Configuration management
β”‚   β”‚   β”œβ”€β”€ database.py    # Database operations
β”‚   β”‚   β”œβ”€β”€ embeds.py      # Discord embed templates
β”‚   β”‚   β”œβ”€β”€ logger.py      # Logging utilities
β”‚   β”‚   β”œβ”€β”€ pagination.py  # Paginated views
β”‚   β”‚   β”œβ”€β”€ tasks.py       # Background tasks
β”‚   β”‚   └── verification.py# Verification logic
β”‚   β”œβ”€β”€ bot.py             # Main bot class
β”‚   └── main.py            # Entry point
β”œβ”€β”€ api/                   # Flask API
β”‚   β”œβ”€β”€ app.py             # Flask application
β”‚   └── __init__.py
β”œβ”€β”€ docker-compose.yml     # Docker orchestration
β”œβ”€β”€ Dockerfile.bot         # Bot container
β”œβ”€β”€ Dockerfile.api         # API container
β”œβ”€β”€ pyproject.toml         # Python dependencies
└── env.example            # Environment template

🎯 Commands

User Commands

  • /verify - Start MediaWiki account verification
  • /verify status - Check your verification status
  • /verify help - Get help with verification

Admin Commands

  • /verify user <user> - Check another user's verification
  • /verify stats - View verification statistics
  • /verify unlink <user> - Unlink a user's verification
  • /verify list [status] - List verified/unverified users

πŸ”§ Configuration

Discord Bot Setup

  1. Go to Discord Developer Portal
  2. Create a new application
  3. Go to "Bot" section and create a bot
  4. Copy the token to DISCORD_TOKEN
  5. Enable required intents:
    • Server Members Intent
    • Message Content Intent

MediaWiki OAuth Setup

  1. Go to Special:OAuthConsumerRegistration on your wiki
  2. Create a new OAuth consumer with these grants:
    • Basic rights (to access user information)
    • Confirm user identification (to verify user identity)
  3. Copy Consumer Key/Secret to environment variables

Role Configuration

  • WIKI_AUTHOR_ROLE_ID: Role granted to verified users
  • ALLOWED_ROLE_IDS: Roles that can use admin commands (comma-separated)

πŸ—„οΈ Database Schema

-- Verification links table
CREATE TABLE links (
    id SERIAL PRIMARY KEY,
    discord_user_id BIGINT NOT NULL UNIQUE,
    mediawiki_username VARCHAR(255),
    verified BOOLEAN DEFAULT FALSE,
    token VARCHAR(255) UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    verified_at TIMESTAMP
);

-- Indexes for performance
CREATE INDEX idx_discord_user_id ON links(discord_user_id);
CREATE INDEX idx_token ON links(token);
CREATE INDEX idx_verified ON links(verified);

🐳 Docker Services

Service Container Port Description
db wiki-link-db 5432 PostgreSQL database
bot wiki-link-bot - Discord bot
api wiki-link-api 5000 Flask verification API

Docker Commands

# View service status
docker compose ps

# View logs for specific service
docker compose logs -f bot
docker compose logs -f api
docker compose logs -f db

# Rebuild and restart
docker compose up --build -d

# Access database
docker compose exec db psql -U wiki-link-user -d wiki-link-db

# Shell access
docker compose exec bot bash
docker compose exec api bash

πŸ” Monitoring & Logs

Log Levels and Emojis

  • πŸŽ‰ SUCCESS: Verification completed
  • ℹ️ INFO: User actions, general events
  • ⚠️ WARNING: Pending verifications, soft errors
  • ❌ ERROR: Failed operations, exceptions
  • πŸ—„οΈ DATABASE: Database operations
  • πŸ”— VERIFICATION: Verification flow events

Health Checks

  • Database: pg_isready checks every 5 seconds
  • API: Available at http://localhost:5000/verify
  • Bot: Check Discord status

🚨 Troubleshooting

Common Issues

Bot not responding to commands:

# Check bot logs
docker compose logs -f bot

# Verify token and permissions
docker compose exec bot env | grep DISCORD_TOKEN

Database connection errors:

# Check database health
docker compose exec db pg_isready -U wiki-link-user

# Restart database
docker compose restart db

OAuth verification fails:

# Check API logs
docker compose logs -f api

# Verify MediaWiki credentials
docker compose exec api env | grep MW_

Permission errors:

# Check role configuration
docker compose exec bot env | grep ROLE_ID

# Verify bot has role management permissions

Debug Mode

Enable debug logging in development:

# Add to .env
FLASK_DEBUG=1

# Or set logging level in bot/core/logger.py
logger.add(sys.stdout, level="DEBUG")

About

bot for atl.wiki

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages