Skip to content

A discord bot that messages each registered discord server with a local leaderboard and rating change predictions after each leetcode contest

License

Notifications You must be signed in to change notification settings

pedrosorio/discord_leetcode_bot

Repository files navigation

Discord Bot for leetcode contest rating predictions

Discord bot that posts contest summary and rating change predictions after every leetcode contest for users in a discord server. Uses flask/gunicorn and sqlite for storage.

Predictions for weekly-contest-xxx

#33 WeekendCoder 🇺🇸 +111.25 = 2541.35

#83 Top100Enjoyer 🇺🇸 + 9.25 = 2897.21

#150 pedro 🇵🇹 + 20.00 = 2690.69

#3316 Beginner 🇦🇶 + 13.24 = 1889.14

#5493 Interviewer 🇦🇶 - 28.44 = 2041.32

Important files:

  • register_app_commands.py registers with discord the list of commands the bot supports (and their UI)
  • flask_app/interactions.py contains the code to handle the commands issued by users in a discord channel. Supports basic discord bot HTTP API functionality. Does not depend on a "discord bot" library.
  • posting_job.py is a script that polls https://lccn.lbao.site (Github project) every 30s until a new contest is published. Once a new contest is available, it fetches the rank and rating prediction for every user who registered with the bot and stores them in the DB. It uses this information to iterate over the discord servers where the bot is installed and sends a message to the corresponding channel summarizing the results of the users in that server.

Bot setup:

  • See discord docs on how to create an application/bot
  • Create a SECRETS.txt file in the home directory of the project (do not commit this) containing a json with the following keys: APPLICATION_ID, PUBLIC_KEY (present in your discord application's general information tab), and TOKEN (generated in Bot's page - DO NOT publish this one)
  • Create virtualenv, activate it and install requirements: python3 -m venv venv; source venv/bin/activate; pip install -r requirements.txt
  • Register with discord the commands the bot can respond to: python3 register_app_commands.py
  • Initialize the db: flask init-db
  • Run the flask app through gunicorn: gunicorn --bind 0.0.0.0:PORT wsgi:app
  • Fill in the interactions endpoint URL in the application's page so discord knows where to send requests from commands

Bot installation in discord server:

About

A discord bot that messages each registered discord server with a local leaderboard and rating change predictions after each leetcode contest

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages