Discord bot using py-cord
and slash commands to follow the ranking of a guild
on Hack The Box, Root Me
and Try Hack Me built by @mathious6
for DaVinciCode.
Command | Action |
---|---|
/help |
Display the help message. |
/register <pseudo> |
Register the author of the command with the given pseudo. |
/update <?pseudo> <?htb_id> <?rm_id> <?thm_id> |
Update the author of the command with the given pseudo and ids. |
/profile <?pseudo> |
Display the profile of the author of the command or the given pseudo. |
/leaderboard <platform> |
Display the leaderboard of the organization on the given platform. |
- Sign in to Hack The Box.
- Go to your profile overview.
- Next to your profile picture, on the top, you will see your id after your username:
USERNAME #ID
. Use it to update your profile through the bot.
- Sign in to Root Me.
- Go to your profile overview.
- Under
Modify my parameters
you will see the UID field. Use it to update your profile through the bot.
- Sign in to Try Hack Me.
- Go to your profile overview.
- You will see the
username
field. Use it to update your profile through the bot.
Create a .env
file with the following variables in the root of the project:
DISCORD_TOKEN=discord_token
RM_API_KEY=root_me_api_key
BIRTHDAY_CHANNEL_ID=bday_channel_id
DISCORD_GUILD_ID=guild_id
DISCORD_CHANNEL_ID=[channel_id1, channel_id2, ...]
ORGANIZATION_NAME=organization_name
DATABASE_PATH=database_path
UPDATE_INTERVAL=update_interval
BIRTHDAY_CHANNEL_ID=bd_id
VAULT_TOKEN=vault_token
VAULT_URL=vault_url
DEV_MODE=dev_mode
DEV_DISCORD_GUILD_ID=dev_guild_id
DEV_DISCORD_CHANNEL_ID=[dev_channel_id1, dev_channel_id2, ...]
DEV_DISCORD_TOKEN=dev_discord_token
DISCORD_TOKEN
: Discord bot token, you can get one here. Be careful to not share it.RM_API_KEY
: Root Me API key, you can get one here.DISCORD_GUILD_ID
: Discord guild id, you can get it by activating the developer mode in Discord and right-clicking on the guild.BIRTHDAY_CHANNEL_ID
: Discord channel id, you can get it by activating the developer mode in Discord and right-clicking on the channel.DISCORD_CHANNEL_ID
: Discord channel id, you can get it by activating the developer mode in Discord and right-clicking on the channel. you can add multiple Ids, separated by a comma.ORGANIZATION_NAME
: Will be the name displayed on the embeds.DATABASE_PATH
: Path to the database file, will be created if it doesn't exist.UPDATE_INTERVAL
: Interval in minutes between each update of the leaderboard. (Suggestion: 240)
Optional:
If you want to use Vault to store the tokens, you will need to set up the following variables. In this case, the DISCORD_TOKEN & RM_API_KEY variables will be ignored.
Development:
If you want to run the bot in development mode, you will need to set up the following variables. Instead of running the bot on the main guild, it will run on the development guild.
DEV_MODE
: Set toTrue
to run the bot in development mode (default:False
).DEV_DISCORD_GUILD_ID
: Discord guild id, you can get it by activating the developer mode in Discord and right-clicking on the guild.DEV_DISCORD_CHANNEL_ID
: Discord channel id, you can get it by activating the developer mode in Discord and right-clicking on the channel.DEV_DISCORD_TOKEN
: Discord bot token, you can get one here. Be careful to not share it.
To run the bot locally, you will need to follow the steps below:
- Set up the environment variables in a
.env
file as described above. - Install a virtual environment following those steps:
pip install virtualenv
virtualenv -p python3 venv
source venv/bin/activate
- Once the virtual environment is activated, install the dependencies:
pip install -r requirements.txt
- Run the bot:
python main.py
The bot is deployed with Docker. To deploy the bot, you will need to follow the steps below:
- Set up the environment variables in a
.env
file as described above. - Build the image:
docker build -t Dockerfile .
- Run the container:
docker run -d --name discord-hacker-ranker-bot Dockerfile
- Stop the container:
docker stop discord-hacker-ranker-bot
├── bot
│ ├── core.py : Main file of the bot, contains the slash commands and initialization.
│ ├── embed_creation.py : Contains the functions to create the embeds to provide a good user experience.
│ └── pagination_view.py : Contains the functions to create the pagination view of the leaderboard.
├── database
│ ├── crud_data.py : Contains the functions to interact with the DailyData table.
│ ├── crud_user.py : Contains the functions to interact with the User table.
│ ├── manager.py : Contains the functions to interact with the database and to manage it.
│ └── models.py : Contains the models of the database.
├── resources : Contains the resources used by the bot like the logos, emojis, etc.
│ ├── HTB_logo.png
│ ├── RM_logo.png
│ └── THM_logo.png
├── utils
│ ├── api.py : Contains the functions to interact with the platforms APIs.
│ ├── env_checker.py : Contains the functions to check the environment variables.
│ ├── ressources.py : Contains the functions to get the resources.
│ └── services.py : Contains the functions to interact with the services.
├── database.db
├── docker-compose.yml
├── Dockerfile
├── logging.conf : Configuration file for the logger.
├── main.py : Main file of the bot, contains initialization and run.
├── README.md
└── requirements.txt