Tardsquad Discord Bot
A Discord chat bot for the Tardsquad guild (Discord name for server).
Resouces
- Discord Developer Portal
- A general tutorial for a Discord bot can be found here
- GCP
- Container Registry
- Storage Bucket for the above containers
- Service Account used to publish Docker images to GCR.
- Cloud Run Service that runs our container for image published to GCR.
- Secret Manager is where
DISCORD_TOKEN
is stored, which is hooked up as envvar in the Cloud Run service.
Installation
Make sure to use a supported python version. See the key python
in the section tool.poetry.dependencies
at pyproject.toml.
$ pip install tardsquad-discord-bot
$ tardsquad-bot
If you use pipx to install, you must specify a supported and locally available python version like:
$ pipx install --python python3.9 tardsquad-discord-bot
Development
TL;DR the easy way
- Get the discord token by asking @erikw or from the bot tab in the tardsquad-discord-bot application in the Discord developer portal
$ git clone https://github.com/tardsquad/tardsquad-discord-bot.git
$ cd tardsquad-discord-bot
$ echo "DISCORD_TOKEN=the-token" > .env
$ docker-compose up
Continue reading for how to setup local development envionment, with our without Docker below:
More elaborate
-
Make sure to
$ poetry shell
before using tools like pyright LSP, so that it can find the installed dependency modules -
Reference for how to structure a python project: https://realpython.com/pypi-publish-python-package/
-
Clone this git
$ git clone https://github.com/tardsquad/tardsquad-discord-bot.git
$ cd tardsquad-discord-bot
- Install Poetry
$ pip install poetry
- Install project dependencies
$ poetry install
- Set up envionment. Fetch the bot token from the bot tab in the tardsquad-discord-bot application in the Discord developer portal. Either set this as as an envionmental variable together with the guild (server name), or more preffered in the git-ignored
.env
file in the project directory:
$ echo "DISCORD_TOKEN=the-token" > .env
- Now tardsquad-discord-bot should work!
$ poetry run tardsquad-discord-bot
- To install locally:
$ poetry build
$ pip install dist/tardsquad_discord_bot-*.whl
- Build and run Docker image using the local
.env
file with secrets:
$ docker build -t tardsquad-discord-bot .
$ docker run --env-file=.env -t tardsquad-discord-bot
$ # or more simply
$ docker-compose up
- Drop in to a shell like
$ docker run --env-file=.env --rm -it --entrypoint bash tardsquad-discord-bot
Releasing
$ vi -p pyproject.toml CHANGELOG.md # Update version.
$ poetry build
$ ls -l dist/
$ git commit -m "Prepare vX.Y.Z"
$ git tag V.X.Y.Z
$ git push --all && git push --tags
$ poetry publish