### mblazev's blog

By mblazev, history, 3 years ago,

I would like to present to you an open-source competitive programming (primarily codeforces) discord bot written in python by meooow, algmyr, Narut, Rahul, pajenegod, aryaman, DeliciousFlatChest, Chilli, c1729, cfalas and mblazev. Source code is avaliable on github. If you would like to try the bot without having to set it up yourself, enter this server: discord.gg/2CJ6qvY. The bot is still work in progress, but it is already 4 months old so it can already do quite a few cool things. Here is a showcase of a subset of its features:

• It can plot rating distribution of either active or all codeforces users, in either normal or log scale, who have competed at least n times. For example, ;plot cfdistrib normal active 5 gives:
Click to reveal
• It can also place a provided list of users on a plot of the percentile distribution of codeforces. For example, ;plot centile mblazev laggy heon +zoom
Click to reveal
• If you're curious how the entire percentile distribution looks like ;plot centile
Click to reveal
• It can plot codeforces rating graphs for multiple users. For example, ;plot rating mblazev heon tomx +zoom
Click to reveal
• It can plot a histogram of problems solved by a user, color-coded by submission type. For example, ;plot solved stefdasca
Click to reveal
• Of course, it works for multiple users as well. For example ;plot solved stefdasca pikmike
Click to reveal
• It can even plot codeforces rating overlaid on a scatter plot of problems solved along with a running average of ratings of problems solved in practice! For example ;plot scatter pikmike
Click to reveal
• And of course, it can also plot the rating distribution of server members. ;plot distrib
Click to reveal

3 other plotting commands are still WIP so I will not showcase them yet. Some non-graph features include:

Contest forecast
Smart mashup creator
Smart virtual contest picker
Smart practice problem selector
Ranklist with rating prediction
Contest reminders to subscribed users
It's easy to control the subscription
User stalking
Even displaying cf handle of given discord user looks beautiful!
Emoji-interactive list of server members
Scoreboard for fastest/shortest CSES solutions
3 stars -> starboard

It also has a set of commands which we refer to as "gitgud". They are ;gitgud, ;gotgud, ;nogud, ;gudgitters and ;upsolve. They incentivize solving problems around user's rating by giving points (depending on relative difficulty) and maintaining a scoreboard. In this example, a 1900 rated user requested a 100 rating higher problem (worth 12 points):

Click to reveal

To report a solved problem, you run ;gotgud.

Click to reveal

To skip a problem (after at least 3 hours), you run ;nogud.

Click to reveal

Apart from random problems, you can also gain points for ;upsolve-ing problems you failed in a contest. For example:

Click to reveal

To display the scoreboard, run ;gudgitters

Click to reveal

It has even more features (many of which are WIP), but I've omitted them for sake of brevity. We are also planning new features and we welcome new contributors; we'd be happy to help you find your way around the codebase. It's moderately big (3.2k lines of code, not counting comments and whitespaces) but stringent code review ensures the code remains non-terrible.

If you've come this far, just enter discord.gg/2CJ6qvY and try it out! Make sure to read ;help for more details.

• +225

 » 3 years ago, # | ← Rev. 5 →   +39 Nice
•  » » 2 years ago, # ^ |   +6 ... We can see what you typed before editing......
•  » » 19 months ago, # ^ |   0 how can i register in duel list
 » 3 years ago, # |   +29 great bot :D
 » 3 years ago, # |   +26 Wow the bot looks amazing! Can't wait to try it out :)
 » 3 years ago, # |   +43 I joined the server and the people there are really friendly. The bot's features are also very useful too.
•  » » 3 years ago, # ^ |   +11
•  » » » 3 years ago, # ^ |   +2 It's sad that horse has to be like that.
•  » » » » 3 years ago, # ^ |   +2 Yeah, that horse is acting like a piece of crap. Other people there are friendly.
•  » » » » » 3 years ago, # ^ |   +20 Horse being the savage he is is one of the first reasons we still did not die. He is doing a great work.
•  » » » » » » 3 years ago, # ^ |   -10 Yeah no doubt abt that! He is really good at what he does clearly but he's being arrogant and I think he knows that. Well, people there have told him that and he's taken that into account. Anyway, this bot is fun and really useful!
•  » » » » » » 3 years ago, # ^ | ← Rev. 2 →   +3 Indeed, where would we be without Horse's divine providence? /s
 » 3 years ago, # |   +23 Good Stuff
 » 3 years ago, # |   +19 Have you considered implementing something similar to CF Predictor or perhaps even borrowing some of the public CF Predictor API to enhance the bot?I would be very interested in working on what could be the greatest CF crossover to date. :)
•  » » 3 years ago, # ^ |   +14 The bot does rating prediction. Read the whole post :P
•  » » » 3 years ago, # ^ |   +14 Sorry, I should have been more specific! I meant that it would be nice to see what your rating change would have been during a virtual participation as well, in addition to the live participations currently supported.
•  » » » » 3 years ago, # ^ |   0 Oh you can pitch that idea to #suggestions and it will be put on list. Though there are currently 32 issues and 6 pull requests outstanding so you might have to wait a while.
 » 3 years ago, # |   +33 Bot is amazing, great work :D
 » 3 years ago, # |   +32 the best thing to happen to codeforces since the invention of codeforces
 » 3 years ago, # |   +8 i think you have forgotten to put kkbb in the credits list, mblazev
 » 3 years ago, # |   +19 I wish I could've contributed to this amazing bot!
•  » » 3 years ago, # ^ |   0
 » 3 years ago, # | ← Rev. 2 →   +22 rip link isnt workingupd: working now
• »
»
3 years ago, # ^ |
+17

# justicefornumb

•  » » » 3 years ago, # ^ |   +8 For you I am Mr master
• »
»
»
»
3 years ago, # ^ |
+11

# justiceforbaumanec

•  » » 3 years ago, # ^ |   0 It's because you are on ban list. I'm sorry.
•  » » 8 months ago, # ^ |   0 can you give me a link for discord server? where i discuss problem and approch it is hard to do alone
 » 3 years ago, # |   0 great work!! thanks a lot!!
 » 3 years ago, # | ← Rev. 2 →   +3 why Codeforces handle for @handle not found in database shows for green even i set my handle cp community discord ?? is it a bug ? UPD : got that.
 » 3 years ago, # |   0 Thanks for crediting my two commits
•  » » 3 years ago, # ^ |   +3 Well remember if you didn't write that I would have done a polyfit() in ;chilli lmao
•  » » » 3 years ago, # ^ |   0 orz polyfit = big brain
 » 3 years ago, # |   -25 You win this round. I'll use TLE for CPC Спойлерfor now err
 » 3 years ago, # | ← Rev. 2 →   +9 Good bot!
 » 3 years ago, # |   0 I'm pretty sure this bot will help CP become more fun as a sport.
 » 3 years ago, # |   0 why discord link is not working?
•  » » 3 years ago, # ^ |   0 It's working unless you're banned.
 » 2 years ago, # |   0 the link is not working :(
 » 2 years ago, # |   +3 This bot's just amazing and I seriously want to have it in one of my servers, but I can't cuz I have some weird issue with my PATH and Python and Poetry can't work.... So when would the bot be on https://top.gg ?
•  » » 2 years ago, # ^ |   0 Same problem here. Did you manage to resolve the issue?
•  » » 2 years ago, # ^ |   0 Same .. poetry pycairo issues
•  » » » 2 years ago, # ^ |   0 The pycairo stuff requires you to install some libraries. Recently we updated the README to better describe the setup and dependencies needed. So if you use some recent ubuntu version it should be fairly easy to get it going.Be aware that we pretty much assume you're on a linux machine, I don't think we have tested how feasible it is to get it running on windows since we added the cairo dependencies. It should be possible, but might be hard.
•  » » » » 23 months ago, # ^ |   0 I spent 3 hours looking how to install this on windows. Most useful link till now is link. But i don't understand how to install this whl file in the virtual env. I am on the last step right now and I will give up in like an hour or so if i can't solve this. However, if i do solve this i will send up a write up for instructions on how to do this on windows. :)
•  » » 8 months ago, # ^ |   0 well people dont need to setup it they can invite this bot to there server by this following link https://top.gg/bot/822801297547722782#/
 » 2 years ago, # |   +13 This is just brilliant. How come I get to know only 9 months later?:(
•  » » 2 years ago, # ^ |   +37 It is even more brilliant than you think. In those 9 months we added so many more features that the ones mentioned in this archaic blog barely scratch the surface.
•  » » » 2 years ago, # ^ |   0 Thanks mblazev. bot gives really great problems for beginners like me
•  » » » 2 years ago, # ^ | ← Rev. 2 →   0 How does the problem recommender work i.e. on what basis do you recommend problems to a user?
•  » » » » 2 years ago, # ^ |   +8 I'm too lazy to explain the details but for most part it's just random. There are plans to make it smarter using ML but it's not easy.
 » 2 years ago, # |   0 What a nice thingy.
 » 2 years ago, # |   0 Because of the new formula causing some problems to become unreasonable for their labeled rating right now, could you allow for skips in ;gitgud
 » 2 years ago, # |   0 Maybe a phone app one day? Or a chrome extension? Cuz if TLE will never be on top.gg that would be sad to have all this functionality limited to one Discord server...
•  » » 2 years ago, # ^ | ← Rev. 2 →   +3 It is not limited to one discord server. It is open source and many servers use it.
•  » » » 2 years ago, # ^ |   0 Yes but it's not intuitive to add it. Not everybody can, if you're not Linux or you don't use Discord, you won't be able to use it.
•  » » » » 2 years ago, # ^ |   +3 or you don't use Discord Well duh its a discord bot.
•  » » » » » 2 years ago, # ^ |   -8 Yeah, that's what I mean : It's only a Discord bot. With all the functionality it have, I think it could be something bigger than just a Discord bot, like a phone app.(Sorry for eventuals english mistakes)
•  » » » » » » 2 years ago, # ^ |   0 "Porting" this to a mobile platform would essentially mean rewriting the entire thing. The effort required is enormous and the benefit is minimal.
 » 2 years ago, # |   0 Does the bot automatically update my rating if the rating changes?
•  » » 2 years ago, # ^ |   0 If by that you mean role updates then yes.
•  » » » 2 years ago, # ^ |   0 so the moderator needs to give roleupdate command. And then everyone's rating will get updated.? p.s. sorry for the vague question
•  » » » » 2 years ago, # ^ |   0 You dont need manual intervention for role updates. It happens as soon as mike updates roles on codeforces. Although you can also manually run a command to update roles. You can do ;help roleupdate on your private server to know how to setup auto role updates. Make sure you have Admin/Moderator role
 » 2 years ago, # | ← Rev. 3 →   0 When plotting histogram of problems solved by multiple users, 2 consecutive difficulties get merged, e.g. here pikmike's 2400 and 2500 solved have been merged (separately: here).Is it possible to avoid this merging?
 » 2 years ago, # |   +1 hello, sorry the bot it's simply amazing, but i need some help with the installation on a mac, if someone can help me I will really appreciates that, sorry for the problems and thanks in advance
 » 22 months ago, # |   0 Is anyone able to deploy this on heroku?
•  » » 22 months ago, # ^ |   0 I'm trying but there are some issues with poetry as heroku doesn't have poetry buildpack by default
 » 21 month(s) ago, # | ← Rev. 3 →   0 Hello mblazevwhen i try to run this command : export BOT_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXX" poetry run python -m tleI get this error : — bash: export: -m': not a valid identifierPlease help me fix this.
•  » » 21 month(s) ago, # ^ |   +18 Those are supposed to be two different commands... Just copy paste from the README...
•  » » » 21 month(s) ago, # ^ |   0 Thanks for that. I tried what you suggested. However, it still says, "no module named TLE" what to do?P.S. Thanks a lot for your help.
•  » » » » 21 month(s) ago, # ^ |   +28 Follow the instructions described in the README.
 » 21 month(s) ago, # | ← Rev. 2 →   0 Nice
 » 18 months ago, # |   +28 Copy-paste directly to your terminal After a lot of struggle, finally...sudo apt updatesudo apt upgradesudo apt install software-properties-commonsudo add-apt-repository ppa:deadsnakes/ppasudo apt install python3.7python3.7 --versionsudo apt-get install gitcd TLEpoetry installapt-get install python3.7-venv libpython3.7-devpython3.7 -m pip install poetrypython3.7 -m poetry installsudo apt-get install python3.7-venv libpython3.7-devpython3.7 -m pip install poetrycd ..python3.7 -m pip install poetrysudo python3.7 -m pip install poetrypython3.7 --versionpython3.7 -m pip install poetrysudo apt install python3-pippip3 --versionpython3.7 -m pip install poetrysudo apt install python3-testresourcespython3.7 -m pip install poetrypython3.7 -m poetry installpython3.7 -m pip install poetrypython3.7 -m poetry installcd TLEpython3.7 -m pip install poetrypython3.7 -m poetry installpoetry installpython3.7 -m pip install poetrysudo apt-get install libcairo2-dev libgirepository1.0-dev libpango1.0-dev pkg-config python3-dev gir1.2-pango-1.0sudo apt-get install libjpeg-dev zlib1g-dev./run.shcd .../run.shcd TLEpoetry --versionpoetry installcd ..apt-get install python3.7-venv libpython3.7-devsudo apt-get install python3.7-venv libpython3.7-devpython3.7 -m pip install poetrycd TLEpoetry installpython3.7 -m pip install poetrypoetry installpython3.7 -m poetry installpoetry --versioncd ..poetry --versionsudo apt install curlcurl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3.7poetry --versionsource \$HOME/.poetry/envcd TLE./run.sh
•  » » 18 months ago, # ^ | ← Rev. 2 →   +6 Make sure to cool up your system 24/7 :)
 » 17 months ago, # | ← Rev. 2 →   0 Can't we use it for another server?
•  » » 17 months ago, # ^ |   0 You will have to host your own instance. Code is open source. Thats the only way out.
•  » » » 16 months ago, # ^ |   0 I have hosted it on my system, and it's working fine! (as long as my Laptop is running) But I wanted to ask, is there any other way to host the bot (maybe in some online server or something) so that when I close my laptop, it still works? it's kind of impossible for me to leave my laptop turned on 24/7!
•  » » » » 12 months ago, # ^ |   0 did you solve it?
 » 17 months ago, # | ← Rev. 2 →   0 Hi, I setup the bot in a server and I keep getting this line in the terminal when I run itMessage: "Ranklist fetch failed for contest 1410. ContestNotFoundError('Contest with ID 1410 not found on Codeforces')"Has something gone wrong??
 » 16 months ago, # | ← Rev. 2 →   0 I am getting this error please help me fix this!./run.shAlready up to date.Installing dependencies from lock fileNo dependencies to install or updateInstalling the current project: TLE (0.1.0)ujson module not found, using jsonmsgpack not installed, MsgPackSerializer unavailableERROR:root:Token required
•  » » 16 months ago, # ^ |   0 Looks like you probably skipped the step where you put your bot token in the environment file. I would start over and follow every step carefully if I were you. I recently followed the docs exactly and didn't have an issue.
•  » » » 16 months ago, # ^ | ← Rev. 2 →   0 export BOT_TOKEN="Nzk2MzYxNDY4NDEyMTY2MTQ1.X_WzaQ.1x1COGsxVk5vb8wSGyFGMh9Rb08"export LOGGING_COG_CHANNEL_ID="790954918612697091"export ALLOW_DUEL_SELF_REGISTER="false"I have set it like this.Anyways thank you!!
•  » » » » 16 months ago, # ^ | ← Rev. 2 →   +15 Please share your credit card no and CVV no along with this BOT_TOKEN. Thanks.Spoiler You shouldnt publish this. Now go and reset Bot Token.
•  » » » » » 16 months ago, # ^ | ← Rev. 3 →   0 This is not the correct not token I just typed randomly just to show how I set it up
•  » » » » 16 months ago, # ^ | ← Rev. 2 →   0 Just in case, keep in mind that "environment.template" file is just an example, you need to create a new file in the same directory called "environment" with your exports.Also, BOT_TOKEN should not be shared, because other people might be able to control your bot if they know the token value, so please generate a new token.
•  » » 13 months ago, # ^ |   0 I am also getting the same problem ERROR:root:Token requiredMy bot token, channel id , everything is correct. Still I am getting this error. What should I do????
•  » » » 9 months ago, # ^ |   0 invite the bot from this link you dont need to setup it https://top.gg/bot/822801297547722782#/
 » 12 months ago, # |   +10 Hello aryanc403, what could i do with this?
 » 10 months ago, # |   0 When I do ./run.sh then it works but after some time it stops working and goes offline. How to solve this ?
 » 9 months ago, # |   0 well people dont need to setup it they can invite this bot to there server by this following link https://top.gg/bot/822801297547722782#/
 » 8 months ago, # |   0 Such an amazing bot ;_;
 » 4 months ago, # |   -11 ratings not updating in bot tf??
 » 3 months ago, # |   0 how can i register in duel list??
•  » » 3 months ago, # ^ |   0 ask to a mod
 » 4 weeks ago, # |   +1 How do we update the ratings of handle so it will synced to user's latest rating?
•  » » 4 weeks ago, # ^ |   +1 ;roleupdate now
•  » » 4 weeks ago, # ^ |   +1 ;roleupdate now for 1 time only, and ;roleupdate auto on for auto roleupdates
•  » » » 4 weeks ago, # ^ |   +1 Thanks!