A real-time, synchronous junior.guru Discord bot.
All junior.guru automation happens asynchronously (with up-to-24h delay) in the main monolith codebase, except of the following tasks provided by this bot:
- Creating threads in #past-vedle-pasti
- Creating threads in #můj-dnešní-objev
- Reacting to member-made threads in #práce-inzeráty
- Reacting to member-made threads in #práce-hledám
- Creating threads in #ahoj
- Greeting new members in #ahoj
- Providing reviews in #cv-github-linkedin
- Saving pins to members' DMs #13
Please, update the above list if adding features.
The original, asynchronous bot installs and uses this codebase to run the same code and perform the same tasks, idempotently:
- If this bot crashes, the asynchronous bot will do the same stuff, just with a delay.
- The purpose of this bot is to provide non-critical progressive enhancement, which can be dropped at any moment.
- To keep the architecture simple, this bot should have no state. There should be no database. It should only react to the state and events of the Discord server, and write to the Discord server.
- The asynchronous bot should monitor whether this bot is up and running. If it's not, it should fail the build, but non-critically (similar to checking broken links in HTML).
- You'll need poetry installed.
- Clone this repository:
git clone [email protected]:juniorguru/chick.git
- Go to the project directory:
cd chick
- Install the project:
poetry install
Running locally:
- Set the
DISCORD_API_KEY
environment variable to your Discord bot token. Set theGITHUB_API_KEY
environment variable to your GitHub API token. Using direnv might help setting environment variables automatically in your shell when you navigate to the project directory. - Run
poetry run chick
to start the bot. - Press Ctrl+C to stop the bot.
Useful commands:
- Run
poetry run chick --prod
to temporarily replace the production instance with the local one if you need to test something. - To test, run
pytest
. - To format code, run
ruff format
. - To organize imports and fix other issues, run
ruff check --fix
.
The bot is deployed to fly.io.
Everything related to deployment is in the Dockerfile
.
There's also fly.toml
, but that's something the flyctl
has generated and only they know what it is good for.
There is no need to deploy this bot manually.
Everything merged to the main
branch of the GitHub repo gets automatically deployed to Fly.
For this to work, the output of flyctl auth token
must be set as FLY_API_TOKEN
secret in the GitHub repo settings.
The rest of the setup is in .github/workflows/build.yml
.
If you insist to deploy manually from your local machine, follow these steps:
- Have a hobby account at fly.io.
- Have a
flyctl
installed and be logged in. - Set the environment variable using
flyctl secrets set DISCORD_API_KEY=...
- Run
flyctl launch
in the project directory. - Run
flyctl deploy
if not deployed already.
Inspired by Hosting a Python Discord Bot for Free with Fly.io by Jonah Lawrence.
AGPL-3.0-only, copyright (c) 2024 Jan Javorek, and contributors.