Skip to content

allthingslinux/atl-wiki-link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 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 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              β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

  • πŸ”— 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

πŸš€ 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:

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
β”‚   β”‚   └── 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

🎯 Commands

User Commands (available to everyone)

  • /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

Admin Commands (require allowed role)

  • /unverify <user|mediawiki_username> - Remove verification for any user by Discord or MediaWiki username
  • /verified - List all verified users

πŸ› οΈ How Autoconfirmed Role Assignment Works

  • 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.

πŸ”§ 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