- Running Locally
- Data storage and access
- How to create and edit commands
- Misc
- Migrating from the legacy project (pre June 2024)
Clone the repository:
git clone https://github.com/ArrowM/Queue-Bot
cd Queue-BotCreate a Discord bot application and invite it to your server. See Discord.js guide.
Update the .env file with your bot's TOKEN and CLIENT_ID.
You may need to grant yourself docker perms (replacing <username> with your actual username, pi in my case:
chmod +x launch-docker.sh
sudo usermod -aG docker <username>
sudo rebootRun ./launch-docker.sh or launch-docker.bat to:
- dump logs to
./logsand close the previous container (if applicable) - build the image & container
- start the bot in a detached state
- attach to the container (which can safely be exited with the
Ctrl+p Ctrl+qkey sequence. UsingCTRL-cwhile attached will stop the container)
Note if the database schema is outdated, the bot will fail to start and print an error message. To update the schema, run npx drizzle-kit push.
Attach to the bot container (Ctrl+p Ctrl+q to detach):
docker attach queue-botView live logs:
docker logs -f queue-botStop the bot:
docker compose downThis method is not recommended, because it lacks the logging, auto-restart, and rebuild speed of Docker.
Run the setup script (run each time you update the project):
npm run setupStart the bot:
npm startThe bot uses a SQLite database, which is stored in the data/main.sqlite file.
The database is managed by the drizzle package.
The schema is defined in the src/db/schema.ts file.
Query statements are defined in the src/db/queries.ts file.
Modification statements are defined in the src/db/store.ts file.
A store is created and attached to each bot interaction.
Please reference the other files as examples, they follow very similar structures. These instructions are more geared towards pointing you to the files that will need to be added/updated.
- Add a new
.command.tsfile to thesrc/commands/commandsdirectory. Commands should extendEveryoneCommandorAdminCommand. - Add the new command class to the
src/commands.command.loader.tsfile. - Update the
README.mdfile and the help commands in thesrc/commands/help.command.tsfile.
- Add a new
.option.tsfile to thesrc/options/optionsdirectory. Options should extend one of the base options at the bottom of thesrc/options/base-options.tsfile. - Update the
src/options/options.loader.tsfile.
- Create a new
.button.tsfile in thesrc/buttons/buttonsdirectory. Buttons should extendEveryoneButtonorAdminButton. - update the
src/buttons/buttons.loader.tsfile.
If the code for your new command is complex or re-usable, consider placing your logic a utility file in the src/utils directory.
If you need to add or modify database tables or columns:
- Update the
src/db/schema.tsfile. - If you add a new table, or need new querying methods, update the
src/db/store.tsfile and thesrc/db/queries.tsfile. - Run
drizzle-kit generatein the terminal. The drizzle command will generate the necessary SQL migration files for you, which will then be applied withdrizzle-kit push.
Please lint before pushing:
npm run lintThis project is designed to run without compiling thanks to @swc-node/register/esm.
Open a terminal and navigate to the following directory in this project: data/migrations/legacy-export.
Export the old database tables to csv files.
The following command will perform the export for Postgres:
psql -d queue -Atc "SELECT tablename FROM pg_tables WHERE schemaname='public'" | xargs -I{} psql -d queue -c "\copy {} to 'legacy_export/{}.csv' csv header"If you have a different database name, replace queue with your database name.
Then in the .env file, update CHECK_FOR_LEGACY_MIGRATION to be true:
CHECK_FOR_LEGACY_MIGRATION=trueWhen the CHECK_FOR_LEGACY_MIGRATION is set to true, will check the legacy-export directory.
If it finds the csv files, it will prompt you to confirm via console input that you want to import the data.
If confirmed, it will create a dated backup of the database (main.sqlite), then merge the legacy data into the database.
Once the data is imported, CHECK_FOR_LEGACY_MIGRATION should be set back to false.