dtek-discord-bot

A Discord bot with slash commands and interactive group-selection buttons.

Environment variables

VariableRequiredDefaultDescription
DISCORD_TOKENBot token from Discord Developer Portal
DATABASE_URLsqlite:discord_bot.db?mode=rwcLocal SQLite for user favourite groups
CACHE_DURATION_MINUTES30Cache TTL in minutes
SCHEDULE_DB_URL(not set)Shared schedule DB path

Slash commands

CommandDescription
/dtekShow group buttons (interactive)
/dtek_група <group>Show schedule for a specific group
/dtek_встановити <group>Set your favourite group
/dtek_мояShow schedule for your favourite group
/dtek_статусCache status
/dtek_очиститиForce cache refresh (admins only)

Local database schema

CREATE TABLE user_groups (
    user_id        INTEGER PRIMARY KEY,
    favorite_group TEXT NOT NULL
);

Cache behaviour

The Discord bot uses an atomic refresh_in_progress flag to prevent multiple simultaneous refresh operations. When a cache miss occurs:

  1. First caller wins the compare_exchange lock and performs the fetch.
  2. Other concurrent callers wait by polling until is_refreshing() returns false.
  3. Expired cache triggers a background refresh — the stale data is served immediately while the refresh runs.

Running

DISCORD_TOKEN=MTI3... \
DATABASE_URL=sqlite:ds_bot.db \
./dtek-discord-bot