A small Discord bot that i'm using to learn rust. The Code is questionable, I know.
This bot is created with poise which is a Discord API wrapper.
-
Install postgresql
-
Switch user:
sudo su - postgres -
Init the db:
initdb -D /var/lib/postgres/dataNote: On Debian and Ubuntu this command may not be available by default due to opinionated packaging that goes against postgres's documentation.
The database may already be set up and ready to go after installing the package. But if not, add the following to
~/.bashrcandsource ~/.bashrc:export PATH=$PATH:/usr/lib/postgresql/{version}/bin/ -
Start the database server:
pg_ctl -D /var/lib/postgres/data -l logfile startNote: If you get
FATAL: could not create lock file, the directory/run/postgresqlmay not be created. Run the following to create and set ownership of it:sudo mkdir /run/postgresql sudo chown postgres /run/postgresql -
(Optional) If you want to use a database under a non-default name, run the following (replace
postgresmothywith whatever you prefer):sudo su - postgres psql CREATE DATABASE postgresmothy;Verify it has been created with:
SELECT datname FROM pg_database WHERE datistemplate = false; -
Exit the postgres user with
exit
-
Install sqlx-cli
cargo install sqlx-cliNote: On Debian and Ubuntu try this if there are weird openssl errors:
apt-get install libssl-dev pkg-config -
Copy
.end_templateto.envand input the following:DATABASE_URL=postgres://postgres@localhost/postgresNote: Replace the
postgreson the end with whatever your database name is if your are not using the default. -
Init database:
cargo sqlx migrate runNote: Debian and Ubuntu REALLY REALLY REALLY want your database to have a password and will beat you over the head with errors until you just give up and set one. Here's how to do that:
sudo -u postgres psql ALTER USER postgres PASSWORD '{password}'; # replace {password} with your passwordEdit the
DATABASE_URLin .env to include the password (replace {password} with your password):DATABASE_URL=postgres://postgres:{password}@localhost/postgres
- Run
fetch_moth_data.shto grab data for the moth species integrations.
-
Add your bot token to
MOTHY_TOKENin.env. -
Invite the bot somewhere
Example (replace
{BOT_ID_HERE}): https://discord.com/oauth2/authorize?client_id={BOT_ID_HERE}&scope=bot%20applications.commands&permissions=8 -
Run
mregisterto register commands ormdevregisterifDEV_COMMANDS=trueis set in.env.