Combined database + API + web server + Discord bot for the Hypercubing leaderboards
- Install Rust
- Clone this repository:
git clone https://github.com/Hypercubers/hsc-leaderboard.git
cd hsc-leaderboard
- Follow the database setup instructions
- Install
sqlx
withcargo install sqlx-cli
- On Ubuntu, you may need to run
sudo apt install gcc libssl-dev pkg-config
first
- Initialize the database schema with
cargo sqlx migrate run
- (optional) Create a file
discord_accounts.txt
containing lines of the formname_in_solvers_yml DISCORD_USER_ID
- Run
cargo run -- reset && cargo run -- init
to reinitialize the database fromsolves.csv
- Run
cargo run
to run the web server and Discord bot
Before committing, run cargo sqlx prepare
. To do this automatically on every commit, create a pre-commit hook with this command:
echo "cargo sqlx prepare > /dev/null 2>&1; git add .sqlx > /dev/nu
ll" > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
- Install the GitHub CLI with
sudo apt install gh
- Create a personal access token, preferably with the Hypercubers organization as the resource owner and a long expiration.
- Set the resource owner to the Hypercubers organization
- Set the expiration to 1 year
- Set the repository access to Public repositories (read-only)
- Run
gh run download --repo hypercubers/hsc-leaderboard --name linux
- Extract the file with
unzip linux.zip
- Follow the database setup instructions
- Intialize the database from
solves.csv
with./hsc-leaderboard init
You can use psql -U leaderboards_bot -h 127.0.0.1 leaderboards
to access the database directly, although it's best to avoid this. Remember to always BEGIN TRANSACTION
before making any changes!
- Install PostgreSQL
- On macOS:
brew install postgresql
- On Ubuntu:
sudo apt install postgresql-client && sudo systemctl enable --now postgresql
- Access the PSQL prompt and use it to set up the database.
- On macOS:
psql -d template1
- On Linux:
sudo -u postgres psql
CREATE DATABASE leaderboards;
CREATE USER leaderboards_bot WITH PASSWORD 'password';
ALTER DATABASE leaderboards OWNER TO leaderboards_bot;
exit
- Create a
.env
file based on.env.example
- (Optional) Replace
leaderboards_bot
with the database user you used in step 2 - (Optional) Replace
leaderboards
with the database name you used in step 2 - (Optional) Replace
password
with the database password you used in step 2 - Replace
YOUR_DISCORD_TOKEN_HERE
with your Discord bot token
See docs/schema.md
for an explanation of the database schema.
This project is licensed under MIT OR Apache v2.0.