A Discord bot system that verifies Discord users against MediaWiki accounts using OAuth, designed for the All Things Linux community.
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 β
βββββββββββββββββββββββββββββββββββββββ
- π 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
- Docker and Docker Compose
- A Discord application with bot permissions
- MediaWiki OAuth consumer credentials
git clone <repository-url>
cd atl-wiki-bot
cp env.example .env
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.
# Start all services
docker compose up -d
# View logs
docker compose logs -f
# Stop services
docker compose down
- Bot should appear online in Discord
- API accessible at
http://localhost:5000
- Database running on port
5432
# Install Poetry (if not installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Activate virtual environment
poetry shell
# 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
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
/verify
- Start MediaWiki account verification/verify status
- Check your verification status/verify help
- Get help with verification
/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
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and create a bot
- Copy the token to
DISCORD_TOKEN
- Enable required intents:
- Server Members Intent
- Message Content Intent
- Go to
Special:OAuthConsumerRegistration
on your wiki - Create a new OAuth consumer with these grants:
Basic rights
(to access user information)Confirm user identification
(to verify user identity)
- Copy Consumer Key/Secret to environment variables
WIKI_AUTHOR_ROLE_ID
: Role granted to verified usersALLOWED_ROLE_IDS
: Roles that can use admin commands (comma-separated)
-- 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);
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 |
# 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
- π SUCCESS: Verification completed
- βΉοΈ INFO: User actions, general events
β οΈ WARNING: Pending verifications, soft errors- β ERROR: Failed operations, exceptions
- ποΈ DATABASE: Database operations
- π VERIFICATION: Verification flow events
- Database:
pg_isready
checks every 5 seconds - API: Available at
http://localhost:5000/verify
- Bot: Check Discord status
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
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")