Skip to content

Fix Deployment (Docker/Pillow/Fonts) & Implement Advanced Alerts Cog#542

Closed
soadmahmud wants to merge 17 commits intocheran-senthil:masterfrom
soadmahmud:master
Closed

Fix Deployment (Docker/Pillow/Fonts) & Implement Advanced Alerts Cog#542
soadmahmud wants to merge 17 commits intocheran-senthil:masterfrom
soadmahmud:master

Conversation

@soadmahmud
Copy link
Contributor

@soadmahmud soadmahmud commented Jan 20, 2026

Summary

This PR fixes critical deployment issues preventing the bot from running on modern Docker environments (Debian 12/Ubuntu 24.04). It also completely re-implements the missing alerts module with robust contest reminders, ranklists, and milestone celebrations.

🔧 Infrastructure & Bug Fixes

  • Dockerfile Fixes:

    • Updated system dependencies (libcairo2-dev, pkg-config, libgirepository1.0-dev) to allow pycairo and PyGObject to compile correctly on Python 3.11.

    • Fixed AttributeError: 'FreeTypeFont' object has no attribute 'getsize' by pinning Pillow<10.0.0.

  • Font Downloader Fix:

    • Replaced broken Google Storage links (403 Forbidden) with direct GitHub raw links for NotoSansCJK.

    • Removed zip extraction logic as the new source provides raw .ttc files.

  • Configuration (constants.py):

    • Added logic to automatically convert Role IDs from strings to integers in .env, preventing MissingAnyRole errors.

  • Database Handling:

    • Fixed a crash in alerts logic where user data was returned as tuples instead of objects, causing AttributeError: 'tuple' object has no attribute 'handle'.

🚀 New Features (Alerts Cog)

Re-wrote tle/cogs/alerts.py from scratch with the following features:

1. Robust Contest Reminders

  • Supports Codeforces, AtCoder, LeetCode, and CodeChef.

  • Direct API Connections:

    • Codeforces: Uses official API directly (bypassing internal wrapper to prevent attribute errors).

    • AtCoder: Uses Kenkoooo API for stability.

    • Others: Uses kontests.net as a fallback.

  • Sends alerts 24 hours, 1 hour, and 15 minutes before contests.

2. Automatic Ranklists & Rating Updates

  • Automatically detects when a Codeforces round finishes and ratings are updated.

  • Filters results to show only server members.

  • Smart Retry Logic: Looks back 14 days with a 5-day timeout to catch delayed Div. 4 rating updates without getting stuck in infinite loops.

  • Instant Role Update: Triggers a cache reload immediately after posting results to update Discord role colors faster.

3. Milestone Celebrations

  • Detects when a user promotes to a new rank (e.g., Pupil → Specialist).

  • Posts a congratulatory embed with the user's Codeforces Profile Picture.

  • Automatically triggers the ;plot rating command to show their progress graph.

📝 New Commands

Command Description
;subscribe list Shows a dashboard of all active subscriptions for the server.
;subscribe [platform/all] Subscribe channel to reminders (Codeforces, AtCoder, etc).
;subscribe ratings Subscribe channel to Ranklists & Rating Updates.
;subscribe milestones Subscribe channel to Rank-up celebrations.
;unsubscribe [category/all] Stop receiving specific alerts.
;trigger_alert <contest_id> Manually force a ranklist update for a specific contest (Admin only).
;test_milestone Debug command to simulate a rank-up event (Admin only).

@soadmahmud soadmahmud changed the title Bug fixed and Logical Improvement Added Alert for Codeforcers, Atcoder, Codechef contests. Rating updates after contest and Implemented a Auto Congratulations feature when user achieves a upper rank on codeforces. Also fixed some bugs Jan 20, 2026
@soadmahmud soadmahmud changed the title Added Alert for Codeforcers, Atcoder, Codechef contests. Rating updates after contest and Implemented a Auto Congratulations feature when user achieves a upper rank on codeforces. Also fixed some bugs Fix Deployment (Docker/Pillow/Fonts) & Implement Advanced Alerts Cog Jan 20, 2026
@algmyr
Copy link
Collaborator

algmyr commented Jan 21, 2026

I think it's very unlikely we will accept much other than bugfixes. Fixing the font download is a bugfix I'm happy to accept. Similar for the docker setup issues, but there we have a bunch of PRs already.

@soadmahmud
Copy link
Contributor Author

Understood. I’ll submit a pull request only if I find any bugs or issues in the existing codebase.

algmyr added a commit that referenced this pull request Jan 31, 2026
algmyr added a commit that referenced this pull request Jan 31, 2026
Now targets github hosted files which should be more stable.
algmyr added a commit that referenced this pull request Jan 31, 2026
Co-authored-by: Soad Mahmud <108691772+soadmahmud@users.noreply.github.com>
algmyr added a commit that referenced this pull request Jan 31, 2026
Now targets github hosted files which should be more stable.

Co-authored-by: Soad Mahmud <108691772+soadmahmud@users.noreply.github.com>
@algmyr
Copy link
Collaborator

algmyr commented Jan 31, 2026

Extracted the relevant fixes into #543. Added you as co-author to the relevant commits.

@algmyr algmyr closed this Jan 31, 2026
algmyr added a commit that referenced this pull request Jan 31, 2026
Co-authored-by: Soad Mahmud <108691772+soadmahmud@users.noreply.github.com>
algmyr added a commit that referenced this pull request Jan 31, 2026
Now targets github hosted files which should be more stable.

Co-authored-by: Soad Mahmud <108691772+soadmahmud@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants