10 KiB
Contributor's guide
Branches and tags
The main
branch represents the current state of the bot.
New features are developed on feature/*
branches for the development of specific features; these are to be squashed as a single commit onto the main
branch.
Pushing a v*
tag will automatically trigger the build of a new Docker image for the tagged commit.
Please use annotated tags (git tag -a
) if possible!
Old Royalnet versions are available for reference on the historic/*/*
orphan branches.
Setting up a development environment
Follow these instructions to setup a Royalnet development environment, so that you may be able to test your changes!
Installing Rust
You'll need to have the latest stable version of the Rust toolchain installed.
On Linux
- Download
rustup
from your distribution's package manager:# On Arch Linux pacman -Syu rustup
- Use
rustup
to install the latest stable toolchain:rustup default stable
On Windows
- Follow the instructions at the Install Rust page.
- Use
rustup
to install the latest stable toolchain:rustup default stable
Installing an IDE
Using an IDE for Rust is highly recommended!
Steffo's personal recommendation is RustRover by Jetbrains with the Steffula Ultra color scheme, which provides a fully visual environment for interacting with the Rust toolchain.
Installing Git
To contribute changes to the project, you need to have the [Git] version control system installed.
On Linux
It's very likely that git
is bundled with your Linux distribution.
In case it isn't:
- Download it from your distribution's package manager:
# On Arch Linux pacman -Syu git
On Windows
Windows doesn't bundle git
, so you'll need to download and install it externally.
- Download it from the Git download page.
- Install it by running the downloaded executable.
- The default options provided by the installer are fine, but you might want to change the one allowing you to pick the text editor to use with
git
to match the one you're most comfortable with.
- The default options provided by the installer are fine, but you might want to change the one allowing you to pick the text editor to use with
Configuring Git
If you have never used Git before on your machine, you have to configure your identity before you're able to create new commits:
# This will be publicly visible, if you're uncomfortable with that, you may use a pseudonym.
git config --global user.name "Name Surname"
# This needs to be the same email you've used to sign up to GitHub!
git config --global user.email "example@example.org"
Creating a configuration file
To configure the bot's features with parameters whose value has to remain secret, an .env
file in the root directory of the project is used.
An example file .example.env
is provided with the repository; copy it to .env
to make use of it as a template:
cp .example.env .env
Selecting features
To minimize compilation times and configuration work needed, Royalnet supports conditional compilation via Cargo features.
The following features are currently available:
interface_database
- allows interaction with a PostgreSQL database
interface_stratz
- allows interaction with the STRATZ GraphQL API
service_telegram
- processes commands sent to a [Telegram] bot
service_brooch
- sends notifications to a [Telegram] group about recently played Dota 2 matches via a bot
default
- includes all features
To toggle features on other editors, remember to pass the --no-default-features
and --features
option to Cargo when running commands:
cargo --no-default-features --features="interface_database,interface_stratz,service_telegram,service_brooch" run
Configuring PostgreSQL
Note
You'll need to configure PostgreSQL only if you're developing something using the
interface_database
feature.
Royalnet stores some persistent data inside a PostgreSQL database, so you might need one installed to test things that use it:
- Make sure you have an instance of the DBMS available to use somewhere reachable from your machine.
- Create an user to use with royalnet.
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely you'll be able to create an usable user with:
sudo --user=postgres -- createuser "$USER"
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely you'll be able to create an usable user with:
- Create a database
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely you'll be able to create an usable database with:
sudo --user=postgres -- createdb --owner="$USER" royalnet
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely you'll be able to create an usable database with:
- Use the connection URI documentation page to determine the string to use to access your database:
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely the connection string will be:
postgres:///royalnet?host=/run/postgresql/
- If you're on a Linux system, and you have installed PostgreSQL via your package manager, most likely the connection string will be:
- Set the
DATABASE_URL
,TELEGRAM_DATABASE_URL
andBROOCH_DATABASE_URL
variables in the.env
file to the connection URI:export DATABASE_URL='postgres:///royalnet?host=/run/postgresql/' export TELEGRAM_DATABASE_URL='postgres:///royalnet?host=/run/postgresql/' export BROOCH_DATABASE_URL='postgres:///royalnet?host=/run/postgresql/'
- Install cargo-binstall to allow
cargo
to download pre-compiled executables:cargo install cargo-binstall
- Binstall [diesel_cli] to allow
cargo
to perform operations on the database:cargo binstall diesel_cli
- Load the
.env
file into your current environment:source .env
- Generate the database schema by running all migrations with
diesel_cli
:~/.cargo/bin/diesel_cli migration run
Configuring the STRATZ GraphQL API
Note
You'll need to configure the STRATZ GraphQL API only if you're developing something using the
interface_stratz
feature.
Royalnet uses the STRATZ GraphQL API to retrieve information about past Dota 2 matches, so you might need to configure it to make some data available:
- Log in to STRATZ with your Steam account.
- Visit the My Tokens page.
- Click the "Show Token Information" button.
- Copy the displayed token.
- Set the
BROOCH_STRATZ_TOKEN
variable in your.env
to the token you've just copied:export BROOCH_STRATZ_TOKEN='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Configuring a Telegram bot
Note
You'll need to configure a Telegram bot for commands only if you're developing something using the
service_telegram
orservice_brooch
features.
Royalnet can be interacted with via a [Telegram] bot, a special user account that allows for automated interactions with chat rooms, which needs to be manually created:
- Log in to Telegram using Telegram Desktop.
- Search for the account with the username
@BotFather
. - Send the
/start
command. - Send the
/newbot
command. - Answer the questions asked by the BotFather.
- Once the bot is created, copy the displayed token.
- Set the
TELEGRAM_BOT_TOKEN
andBROOCH_TELEGRAM_BOT_TOKEN
variables in your.env
to the token you've just copied. - Open Telegram Desktop's "Settings" modal.
- Navigate to the "Advanced" category.
- Navigate to the "Experimental settings" subcategory.
- Enable the "Show Peer IDs in Profile" option.
- Close the modal.
- Create a new group containing just you and the bot you've just created.
- Open the "Manage group" menu.
- Navigate to the "Administrators" category.
- Click on your profile.
- Enter anything in the "Custom title" field.
- Click "Save" two times.
- Close the modal.
- Click the group's name on the top of the window.
- Click on the group's id to copy it.
- Set the
TELEGRAM_NOTIFICATION_CHATID
andBROOCH_NOTIFICATION_CHAT_ID
variables in your.env
to-100
, followed by the ID you've just copied:# Assuming the copied chat id is `123456789` export TELEGRAM_NOTIFICATION_CHATID='-100123456789' export BROOCH_NOTIFICATION_CHAT_ID='-100123456789'
Using the development environment
The following recipes are available to perform most frequently used actions.
Run Royalnet
The Run run configuration or the following script runs Royalnet with all the enabled features:
source .env
cargo run
Check the validity and quality of the code
The Clippy run configuration or the following script checks the whole source code for errors, warnings, anti-patterns and potential mistakes:
source .env
cargo clippy
Open documentation
The Doc run configuration or the following script compiles the documentation of all available crates, then opens it in your web browser:
source .env
cargo doc --open