A Discord bot that tracks and provides statistics about Wikipedia changes in real-time, with language-specific filtering capabilities. The bot connects to Wikipedia's Recent Changes Stream and allows users to view recent changes and daily statistics for different languages.
- Real-time monitoring of Wikipedia changes
- Language-specific filtering
- Daily statistics tracking
- Discord commands for interaction
- PostgreSQL for persistent storage
- Go 1.24 or higher
- PostgreSQL
- Discord Bot Token
- Clone the repository:
git clone git@github.com:heinsmit06/wikipedia-discord-bot.git
cd wikipedia-discord-bot- Create a
.envfile in the root directory with the following variables:
DISCORD_TOKEN=your_discord_bot_token
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DB=your_database_name- Set up the PostgreSQL database:
CREATE TABLE daily_stats (
date DATE NOT NULL,
language VARCHAR(10) NOT NULL,
change_count INTEGER NOT NULL DEFAULT 0,
last_updated TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (date, language)
);The bot consists of two services that need to be run separately:
- Stats Collector Service (collects and stores statistics):
go run cmd/stats/main.go- Discord Bot Service (handles Discord interactions):
go run cmd/bot/main.goImportant Note: The stats collector service needs to be running to collect daily statistics. If you want accurate statistics, you should deploy this service to run 24/7 on a server. Otherwise, statistics will only be collected while the service is running.
!wikibot help- Show available commands!wikibot recent- Show recent changes in English!wikibot recent [code]- Show recent changes in specified language!wikibot setLang [code]- Set channel default language!wikibot getLang- Show current channel language!wikibot stats [yyyy-mm-dd]- Show statistics for the specified date in current language!wikibot stats [yyyy-mm-dd] [code]- Show statistics for the specified date and language
The project uses a two-service architecture:
- Stats Service: Connects to Wikipedia SSE stream, processes events, and stores statistics in PostgreSQL
- Discord Bot: Handles user interactions and queries the database for statistics
While the current architecture is sufficient for basic usage, it could be enhanced using Kafka for better scalability. Here are two possible Kafka integration approaches:
- Simple Kafka Integration:
[SSE Stream from Wikipedia] -> [Bot] -> [Kafka Topic] -> [Analytics Service]
\-> [Discord Notifications]
- Multi-Source Kafka Integration:
[Wikipedia EN] \
[Wikipedia RU] -> [Bot] -> [Kafka Topic] -> [Discord Bot Instance 1]
[Other source] / \-> [Discord Bot Instance 2]
\-> [Analytics Service]
\-> [Monitoring Service]
In this architecture:
- Multiple sources (Wikipedia EN, RU, Other) send events to your bot
- Bot acts as a producer and sends all events to Kafka
- Multiple consumers (bot instances, analytics, monitoring) independently read events from Kafka
This enhanced architecture would provide:
- Better scalability for high-volume events
- Fault tolerance and data replay capabilities
- More sophisticated analytics possibilities
- Easier integration with other services
💡 When to Use Kafka
Currently, there is no need for Kafka because the event volume is low, and the setup is simple.
Consider implementing Kafka if:
- You start adding more event sources
- You need more than just your bot to consume the data
- You face scalability issues, such as Discord API rate limits
This project is a work in progress and will be updated as time goes on, specifically the architecture and organization of the code.