/ThiccBot

Python discord bot

Primary LanguagePython

ThiccBot

Python discord bot

This is a discord bot written in discord.py. It has a flask backend so the bot can be configured through a web interface (coming soon™️)

Bot setup

  1. Set up your .env file, this stores all credentials/tokens that should not be checked into git. You can look at example.env for reference
    1. Copy your Discord bot token into the DISCORD_ID field (you can find/make a bot here)
    2. setup all other environment variables as needed
    3. look at bot/src/config.yml and set any settings to what you want
  2. Set BOT_API_TOKEN in .env to a random string, you can run the following to generate one
    import secrets
    print(secrets.token_urlsafe())
    use the same process to set FLASK_SECRET_KEY
  3. Install docker and docker-compose https://docs.docker.com/compose/install/
  4. Run docker-compose up
  5. Add the bot to your server:
    1. go to the discord application page
    2. select your application and go to "OAuth2"
    3. select the "bot" checkbox under "Scopes" and go to the link provided underneath
    4. select the discord server to add the bot to
    5. type "?help" into chat

Developing

While this uses docker to run the bot and flask backend, you can make a conda environment so your ide (vsCode) can have autocomplete for the packages.

conda create -n thiccBot python=3.7 pip
source activate thiccBot
cd bot
pip install -r requirements.txt
cd ..
cd backend
pip install -r requirements.txt

Run

docker-compose up

if you want to run the web interface locally you can do

docker-compose up

# in a different tab
./runWeb.sh

DB migrate

Run the following command when ever you change or add a model. Not all changes will be detected so look over the generated scripts. More info here

docker-compose run flask flask db migrate

After looking over the scripts and it looks good run

docker-compose run flask flask db upgrade

If you are starting with a fresh container after changing models first build and run everything then run docker-compose run flask flask db migrate

If the db has data and the migration thinks the db is not on the latest migration version run docker-compose run flask flask db stamp <last revision> to get things working

Force DB backup

docker-compose -f docker-compose.prod.yml run pgbackups /backup.sh

connect to db

source .env
docker exec -it thiccbot_postgres_1 psql -U $THICC_USER -w $THICC_PASSWORD -d $THICC_DB

Restore from backup

if you need to restore a backup first wipe the folder ./postgres-data then run

# run just pg so flask and bot don't start putting stuff in the db
docker-compose -f docker-compose.prod.yml run -d postgres


source .env
cat <backup_dump.sql> | docker exec -i <pg_container_id> psql -U $THICC_USER -w $THICC_PASSWORD -d $THICC_DB

Python formatting

Use the python formatter black, install it with pip install black.