Project 04 · Python · In progress
loba
A Discord bot that announces Codeforces contests.
It shows up in a server as Kim. A server manager picks a channel and, optionally, a role to ping.
When it posts ↓Kim App
Kim App
Kim App
Kim App
@contest-ping
Sample messages in the bot’s format. The contest is made up.
When it posts
Four messages per contest, at fixed times before it starts. Only the last one pings the role.
when it is listed
New contest
24 hours before
Starts in 24 hours
2 hours before
Starts in 2 hours
15 minutes before
Starts in 15 minutes
@contest-ping
Contest starts
Contest rescheduled
Posted when the start time changes, with the old time and the new one.
Contest cancelled
Posted when a contest leaves the Codeforces schedule before it starts.
- Two minutes before each message is due, the bot checks Codeforces once more, in case the contest moved.
- A message more than five minutes late is skipped instead of posted stale.
How it’s built
Three parts with one job each. The Discord layer uses the other two; the logic touches nothing outside itself.
Discord
bot/cogs/Slash commands, listeners and the timed loops. Kept thin.
Logic
bot/services/What is due and what changed. Pure functions: no Discord, no network, no database.
Storage
bot/db/SQLite through aiosqlite. SQL lives only here.
- Users never trigger a request
- Commands read a cache the bot refreshes every 15 minutes.
- One request per 2 seconds
- The Codeforces API limit, kept with a lock and a timer.
- Backs off
- When Codeforces fails, the refresh interval doubles, up to an hour.
- Stops after repeated failures
- After 3 failed sends in a row, that server’s announcements turn off.
- Restart-safe
- The schema is applied on every start, so every statement is idempotent.
- Old rows are pruned
- Announcement rows go a week after the contest starts.
Commands
/cf setchannel<channel> [role]
Announce Codeforces contests in a channel.
Manage Server/cf upcoming
Show the next Codeforces contests.
/cf settings
Show the current announcement settings.
/cf disable
Stop Codeforces contest announcements.
Manage Server/ping
Check the bot’s latency.
/about
About this bot.