Git Product home page Git Product logo

code-jam-2024's Introduction

Python Discord's Code Jam 2024, Contemplative Constellations Team Project

This repository houses the source code of the team project created for Python Discord's Code Jam 2024, developed by Contemplative Constellations team.

Running the bot

To run the bot, you'll first want to install all of the project's dependencies. This is done using the poetry package manager. You may need to download poetry if you don't already have it.

To install the dependencies, you can run the poetry install command. If you only want to run the bot and you're not interested in also developing / contributing, you can also run poetry install --only-root, which will skip the development dependencies (tools for linting and testing).

Once done, you will want to activate the virtual environment that poetry has just created for the project. To do so, simply run poetry shell.

You'll now need to configure the bot. See the configuring section

Finally, you can start the bot with python -m src.

Using docker

The project also supports docker installation, which should allow running the project anywhere, without installing all of the dependencies manually. This is a lot more convenient way to run the bot, if you just want to run it and you don't wish to do any actual development.

To use docker, you can check out the images that are automatically built after each update to the main branch at ghcr. You can also use docker compose with the docker-compose.yaml file, which will pull this image from ghcr. To run the container using this file, you can use the following command:

docker compose up

Tip

To run the container in the background, add the -d flag to the command.

If you want to build the image locally (to include some other changes that aren't yet in the main branch, maybe during development or to customize something when deploying), you can also use docker-compose.local.yaml, which defines an image building step from our Dockerfile. To run this local version of docker-compose, you can use the following command:

docker compose -f ./docker-compose.local.yaml up

Important

Note that you will still need to create a .env file with all of the configuration variables (see the configuring section

Configuring the bot

The bot is configured using environment variables. You can either create a .env file and define these variables there, or you can set / export them manually. Using the .env file is generally a better idea and will likely be more convenient.

Variable name Type Default Description
BOT_TOKEN string N/A Bot token of the discord application (see: this guide if you don't have one yet)
TVDB_API_KEY string N/A API key for TVDB (see this page if you don't have one yet)
SQLITE_DATABASE_FILE path ./database.db Path to sqlite database file, can be relative to project root (if the file doesn't yet exists, it will be created)
ECHO_SQL bool 0 If 1, print out every SQL command that SQLAlchemy library runs internally (can be useful when debugging)
DEBUG bool 0 If 1, debug logs will be enabled, if 0 only info logs and above will be shown
LOG_FILE path N/A If set, also write the logs into given file, otherwise, only print them
TRACE_LEVEL_FILTER custom N/A Configuration for trace level logging, see: trace logs config section

Trace logs config

We have a custom trace log level for the bot, which can be used for debugging purposes. This level is below debug and can only be enabled if DEBUG=1. This log level is controlled through the TRACE_LEVEL_FILTER environment variable. It works in the following way:

  • If DEBUG=0, the TRACE_LEVEL_FILTER variable is ignored, regardless of it's value.
  • If TRACE_LEVEL_FILTER is not set, no trace logs will appear (debug logs only).
  • If TRACE_LEVEL_FILTER is set to *, the root logger will be set to TRACE level. All trace logs will appear.
  • When TRACE_LEVEL_FILTER is set to a list of logger names, delimited by a comma, each of the specified loggers will be set to TRACE level, leaving the rest at DEBUG level. For example: TRACE_LEVEL_FILTER="src.exts.foo.foo,src.exts.bar.bar"
  • When TRACE_LEVEL_FILTER starts with a ! symbol, followed by a list of loggers, the root logger will be set to TRACE level, with the specified loggers being set to DEBUG level.

code-jam-2024's People

Contributors

itsdrike avatar paillat-dev avatar dragonblz avatar fieryash avatar v33010 avatar

Stargazers

 avatar

Watchers

Lucian avatar  avatar  avatar

code-jam-2024's Issues

Unhandled exception

ValueError: invalid literal for int() with base 10: 'list-8116'
gives this error when i tried to do avatar the last airbender and didnt add the : sign

Consider adding cache service

We could use redis in the bot for caching the api results and potentially various other things. However, integrating redis would mean everyone would need to have a redis instance available to be used when developing, or be forced to use docker. This may be a bit too complex for the contributors.

To avoid this complexity, @Paillat-dev has suggested using https://github.com/aio-libs/aiocache, which can just store the records into memory on it's own, without redis running on the side. This does indeed look very interesting, as it allows us to still have a cache service without the complexities involved with setting it up as a service running externally.

The aiocache library also supports actual redis integration, so it would even allows us to switch to redis eventually, if we would want it.

Unless it's deemed that cache really is needed though, we don't necessarily have to do anything.

Add database support

We'll definitely need a database for the bot as we go on, we'll need to add support for it. Most likely, just using sqlite will be enough here and it will make it a lot easier for everyone involved when compared to having to work with a full dbms, like postgresql.

Question is whether or not we'll also want to do ORM (sqlalchemy) or just write some simple crud classes, or work directly with SQL everywhere. As much as I like sqlalchemy, it's probably a bit too involved and complex for us now. As for writing SQL directly, that could lead to issues and is probably more complex than just exposing some basic crud classes that everyone can use even without being familiar with SQL.

Add a way to show details about an episode

We already support showing details on movies / shows, but not on individual episodes.

  • It would be nice if the embed that shows these details was paginated, so that people can scroll through the episodes.

Requires #34

Support pagination in help commands

While we don't have that many commands right now, this number will definitely grow and will likely result in the help embed being way too big (possibly even surpassing the maximum character limit for the embed). Because of that, we'll need to add support for pagination of the help command.

This should ideally be done with discord' interactive button components.

Capture the full traceback in error handler

Sometimes, the error message shown by the error handler is not sufficient to figure out where an issue occurred. This is because it only shows the error class and the message. It would be nice to add a button that could modify the embed / send another embed / do something else to show the entire traceback to the user.

Alternatively, maybe this button could even directly open a github link with the body pre-filled to contain this exception (these links look like this: https://github.com/ItsDrike/code-jam-2024/issues/new?title=Issue%20Title&body=Issue%20Body) or maybe the traceback could get uploaded somewhere automatically and the error embed can just show some reference number under which we can find it.

If it doesn't clutter the embed, we could even include it directly, but I think in most cases the traceback is just way too big for that to look visually good in the error embed.

Support slash command groups recursively in help

Currently, we only explore 1 level of subcommands and print whatever is in there, however, the subcommand might actually be another subgroup, which means we'll need some recursive logic there

Add a way to mark episodes / movies as watched

There should be a command that allows the user to mark certain episodes as watched.

  • We should support marking multiple episodes as watched at once, perhaps something like episode ranges i.e. (1-25 or s1e1-s3e4), since many people binge-watch episodes and adding one-by-one sounds like it could be annoying
  • There should be a way to mark entire shows as watched, maybe also entire seasons, though that actually might be covered by the previous point.
  • Consider supporting re-watches
  • Track when the person saw given episode(s), maybe even allow people to change this.

Requires #22

Add /profile [user] command

This task requires basic TvDB support and database to be completed.

The /profile command should show the user's favorite shows / movies, amount of total shows added and whatever other things that come to mind.

Requires #22 #31

Add unit-tests

This is a low priority task for us, we can finish without having any unit-tests in place, however, it can provide a fun and useful task for someone if they can't find anything else to work on.

Autocomplete for /sudo unload reload load

Add an autocompletion feature using pycord's basic autocomplete.

For unload and reload, it should iterate over the bot's already loaded extensions. For load, it should use iglob or glob from the glob builtin to show all the available extensions in files.

Autocomplete, unlike choices does not enforce the autocompleted fields, which can still allow you to unput whatever you want, and that is nice

Update the copyright holders in `LICENSE`

The LICENSE file should contain all of the contributors names and emails in the copyright / attribution section (just like those in pyproject.toml). Right now, it just says Python Discord, since that's a remnant from the original template repository owned by python discord.

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.