- 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
Create 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 reboot
Run ./launch-docker.sh
or launch-docker.bat
to:
- dump logs to
./logs
and 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+q
key sequence. UsingCTRL-c
while 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-bot
View live logs:
docker logs -f queue-bot
Stop the bot:
docker compose down
This 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 setup
Start the bot:
npm start
The 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.ts
file to thesrc/commands/commands
directory. Commands should extendEveryoneCommand
orAdminCommand
. - Add the new command class to the
src/commands.command.loader.ts
file. - Update the
README.md
file and the help commands in thesrc/commands/help.command.ts
file.
- Add a new
.option.ts
file to thesrc/options/options
directory. Options should extend one of the base options at the bottom of thesrc/options/base-options.ts
file. - Update the
src/options/options.loader.ts
file.
- Create a new
.button.ts
file in thesrc/buttons/buttons
directory. Buttons should extendEveryoneButton
orAdminButton
. - update the
src/buttons/buttons.loader.ts
file.
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.ts
file. - If you add a new table, or need new querying methods, update the
src/db/store.ts
file and thesrc/db/queries.ts
file. - Run
drizzle-kit generate
in 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 lint
This 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=true
When 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.