GithubHelp home page GithubHelp logo

cheran-senthil / tle Goto Github PK

View Code? Open in Web Editor NEW
313.0 8.0 199.0 1.22 MB

๐Ÿค– Discord Bot for Competitive Programming

Home Page: https://discordapp.com/invite/2CJ6qvY

License: MIT License

Python 99.44% Shell 0.42% Dockerfile 0.15%
discord discord-bot python codeforces

tle's Introduction

TLE

TLE is a Discord bot centered around Competitive Programming.

Features

The features of the bot are split into a number of cogs, each handling their own set of commands.

Codeforces cogs

  • Codeforces Commands that can recommend problems or contests to users, taking their rating into account.
  • Contests Shows details of upcoming/running contests.
  • Graphs Plots various data gathered from Codeforces, e.g. rating distributions and user problem statistics.
  • Handles Gets or sets information about a specific user's Codeforces handle, or shows a list of Codeforces handles.

CSES cog

  • CSES Commands related to the CSES problemset, such as showing leaderboards.

Other cogs

  • Starboard Commands related to the starboard, which adds messages to a specific channel when enough users react with a โญ๏ธ.
  • CacheControl Commands related to data caching.

Installation

If you want to run the bot inside a docker container follow these instructions

Clone the repository

git clone https://github.com/cheran-senthil/TLE

Optional: venv

If you want to isolate the TLE python environment from your system one, now would be the time to do it. See the venv documentation for details.

If you decide to use a venv there is some convenience logic in the startup script to automatically active your venv when running the bot. See Environment Variables for details.

Dependencies

Now all dependencies need to be installed. TLE uses Poetry to manage its python dependencies. After installing Poetry navigate to the root of the repo and run

poetry install

โš ๏ธ TLE requires Python 3.7 or later!

If you are using Ubuntu with older versions of python, then do the following:

apt-get install python3.7-venv libpython3.7-dev
python3.7 -m pip install poetry
python3.7 -m poetry install

On some systems, Poetry is not able to install TLE's dependencies correctly. If you are unable to run poetry install without errors after completing the steps below, see the note at the end of the final steps section.


Library dependencies

TLE also depends on cairo and pango for graphics and text rendering, which you need to install. For Ubuntu, the relevant packages can be installed with:

apt-get install libcairo2-dev libgirepository1.0-dev libpango1.0-dev pkg-config python3-dev gir1.2-pango-1.0

Additionally TLE uses pillow for graphics, which requires the following packages:

apt-get install libjpeg-dev zlib1g-dev

Final steps

You will need to setup a bot on your server before continuing, follow the directions here. Following this, you should have your bot appearing in your server and you should have the Discord bot token. Finally, go to the Bot settings in your App's Developer Portal (in the same page where you copied your Bot Token) and enable the Server Members Intent.

Create a new file environment.

cp environment.template environment

Fill in appropriate variables in new "environment" file.

Environment Variables

  • BOT_TOKEN: the Discord Bot Token for your bot.
  • LOGGING_COG_CHANNEL_ID: the Discord Channel ID of a Discord Channel where you want error messages sent to.
  • ALLOW_DUEL_SELF_REGISTER: boolean value indicating if self registration for duels is enabled.
  • TLE_ADMIN: the name of the role that can run admin commands of the bot. If this is not set, the role name will default to "Admin".
  • TLE_MODERATOR: the name of the role that can run moderator commands of the bot. If this is not set, the role name will default to "Moderator".
  • VENV_DIR: If non-empty, automatically activate this venv when running the bot.

To start TLE just run:

./run.sh

On some systems, Poetry is unable to correctly install TLE's dependencies even after completing the above steps. In this case, using Pip to manage the dependencies instead may work. Note that Poetry still must be installed.

To install dependencies in a virtual environment using Pip and start TLE, just run:

./run-pip.sh

Notes

  • In order to run admin-only commands, you need to have the Admin role, which needs to be created in your Discord server and assign it to yourself/other administrators.
  • In order to prevent the bot suggesting an author's problems to the author, a python file needs to be run (since this can not be done through the Codeforces API) which will save the authors for specific contests to a file. To do this run python extra/scrape_cf_contest_writers.py which will generate a JSON file that should be placed in the data/misc/ folder.
  • In order to display CJK (East Asian) characters for usernames, we need appropriate fonts. Their size is ~36MB, so we don't keep in the repo itself and it is gitignored. They will be downloaded automatically when the bot is run if not already present.
  • One of the bot's features is to assign roles to users based on their rating on Codeforces. In order for this functionality to work properly, the following roles need to exist in your Discord server
    • Newbie
    • Pupil
    • Specialist
    • Expert
    • Candidate Master
    • Master
    • International Master
    • Grandmaster
    • International Grandmaster
    • Legendary Grandmaster
  • One of the bot's commands require problemsets to be cached. Run ;cache problemsets all at the very first time the bot is used. The command may take around 10 minutes to run.

Usage

In order to run bot commands you can either ping the bot at the beginning of the command or prefix the command with a semicolon (;), e.g. ;handle pretty.

In order to find available commands, you can run ;help which will bring a list of commands/groups of commands which are available. To get more details about a specific command you can type ;help <command-name>.

Contributing

Pull requests are welcome. For major changes please open an issue first to discuss what you would like to change.

Before submitting your PR, consider running some code formatter on the lines you touched or added. This will help reduce the time spent on fixing small styling issues in code review. Good options are yapf or autopep8 which likely can be integrated into your favorite editor.

Please refrain from formatting the whole file if you just change some small part of it. If you feel the need to tidy up some particularly egregious code, then do that in a separate PR.

License

MIT

tle's People

Contributors

algmyr avatar aneesh2312 avatar aryamanarora avatar aryanc403 avatar cfalas avatar cheran-senthil avatar denjellboone avatar dependabot[bot] avatar dgcnz avatar goswami-rahul avatar kabeer27 avatar krofna avatar kuroni avatar lior5654 avatar meooow25 avatar metalball887 avatar mgilder avatar mohammad-yasser avatar mukundan314 avatar narutse avatar nullchilly avatar parsaalizadeh avatar potatohashing avatar prabh1601 avatar prabowo02 avatar robert-30 avatar sahroush avatar shafinkhadem avatar shahraaz avatar wasim7raja10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tle's Issues

contest summary

Make new command which will print predicted rating, total # solved, # solved per color, average # of attempts before AC, % tried solved, # of hacks etc

Show an appropriate message instead of empty plots

Show appropriate message instead of empty graph for

  • ;plot rating invoked on unrated users
  • ;plot solved invoked on users without submissions
  • ;plot scatter invoked on users without both rating and submissions

gitgud stats

pikmike:

can this leaderboard also show the number of problems solved?
or average score of the problem
or average rating

Use cache in graph cog

Currently the graph cog relies entirely on the API, making all necessary requests every time a command is invoked.
We can switch to using the cache in a number of places for better performance.

Improve error handing

Improve Codeforces API error handling, runhandlerelatedcoro function, and relevant code.

;gitgud ;gotgud

  • rename ;gitgud to ;gimmie
  • new command ;gitgud will give a problem of desired relative difficulty, from -200 to +200
  • give points based on relative difficulty: 1 2 3 4 5 (-200 -100 0 100 200)
  • also give burles (berland currency) for betting
  • allow a skip of unsolved after 12 hours
  • ;gotgud reports completion
  • overall leaderboard: tiebreaker is # of skips

Group "handle" commands

Group "handle" commands sethandle, gethandle, showhandles, removehandle and prettyhandles together.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.