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 three 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
- π€ Slash Commands: Easy-to-use slash commands for verification
- π₯ Role Management: Automatic role assignment for users who are autoconfirmed on MediaWiki
- β³ Delayed Role Granting: Users who are not yet autoconfirmed are linked, and a background task will grant the role once they become autoconfirmed
- π Admin Tools: User management
- ποΈ 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:
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
β β βββ lookup.py # Lookup commands
β β βββ verification.py# Verification logic
β βββ 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. Note: Only users in the MediaWiki autoconfirmed group will be granted the Discord role immediately. If you are not autoconfirmed, you will be linked, and the role will be granted automatically once you become autoconfirmed./unverify
- Remove your own verification link/lookup
- Look up Discord user from MediaWiki username or vice versa
/unverify <user|mediawiki_username>
- Remove verification for any user by Discord or MediaWiki username/verified
- List all verified users
- When you verify, the bot checks if your MediaWiki account is in the
autoconfirmed
group (this usually requires a few days and/or edits on the wiki). - If you are autoconfirmed, you are immediately granted the Discord role.
- If you are not autoconfirmed, you are linked, but the role is not granted yet.
- A background task runs periodically and checks all linked users who do not have the role. If you become autoconfirmed, the role is granted automatically.
- 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")