The Discord bot for Titan Robotics, FRC 5587
This bot has a couple of integrations particularly important for our team, namely:
- Auto-announcements from Google Calendar
- Polls taken through reactions
- A powerful equation solver
-
Install Python and pip and clone this repository
-
Then, from the root of the this repository, install all of the dependencies for this project using the included
requirements.txtfile:pip3 install -r requirements.txt
-
Next, delete all the files within
tokens/and replace them with all of the appropriate tokens, as detailed in the Getting Credentials Set Up Section -
Finally, to start the bot:
python3 bot.py
One thing you are probably going to want to do is add yourself as a dev for the bot. This will allow you to use any dev-based commands like -die, which ends the bot. To do this, simply...
Fill the "devs" array in ./config.json with the Discord IDs of the users you wish to have dev permissions.
Also, at any time, you can run -help to see a list of commands, and -help <specific command> to see any details on that command
Making the discord bot is pretty simple, you just have to follow these steps.
-
Log onto the Discord Developer Portal with whatever account you want to own the bot
-
Hit "New Application" on the top right corner
- Name your app, this does not really matter, only you will see it
- On the left sidebar, click
Bot, thenAdd Botand confirm it - You can now change the bot's username
- Now copy the token, and make a file in
tokens/calleddiscord-token.txt
-
Add the bot to your server
- Find your bot's ID in the Discord Developer portal, found under "Client ID"
- Go to the following link in your web browser, with
<BOT_ID>replaced with your bot's ID. This link should contain all of the permissions necessary for the bot to work.
https://discordapp.com/api/oauth2/authorize?client_id=<BOT_ID>&permissions=1342401600&scope=bot -
Then have someone with the
Manage Serverpermission on your Discord server use the link to add the bot to your sever- Make sure that you allow it all of the permissions
- Open the Google Calendar API with the Google account that owns the Google Calendar that you want the bot to access
- Click
Enable the Google Calendar API- Name the project, and confirm
- Download the Client Configuration
- Move the the downloaded file (
credentials.json) to.tokens/ - Rename the file to
calendar-credentials.json
At this point you must run the bot local to your computer to generate the OAuth tokens
- With the bot running, send
-testeither in a DM or a server with the bot and confirm that it sends a response. If it does, send-events. Otherwise, ensure that the bot is running and try again - It should open up a page on your web browser for you, but if it doesn't simply copy/paste the link printed in the terminal into your web browser
- Select the correct Google account (if you are logged in to multiple)
- It will probably say "This app isn't verified" but just ignore that, and click
advanced, thenGo to <name of API>(unsafe)(its not actually unsafe, don't worry) - Confirm the next couple of prompts
- If it says "The authentication flow has completed, you may close this window." then you succeeded, otherwise just restart the bot and do the steps again
If you are publicly posting or hosting the code for this bot, you don't want to publish your unencrypted credentials and tokens. Both Google and Discord have web scrapers looking for unencrypted tokens, and they will deactivate your token if they notice the security breach, plus it's also just dumb.
To address this, you can encrypt your credentials and tokens with gpg and store them in your code. If you want to use this feature, read the following guide, but note that support for this feature is currently limited to Linux environments.
-
Install gpg on your computer
-
Place your unencrypted credentials in the
credentials/directory if you have not done so already (see Getting Credentials Set Up Section for more information) -
From the root of this repository, run
./scripts/encrypt-tokens.sh all "<password you want to encrypt them with>" -
To be safe, delete all the files in
tokens/that don't end in a.gpg
From here, you can push your code to your SCM.
For a detailed setup guide as to hosting the bot with Heroku (which our team does), see below. Note that a Profile and a requirements.txt file are already included in this repository.
- Put all of your code with credentials and tokens in a GitHub repository. If the repository is public, make sure you have followed the Securely Storing Tokens section!
- Make a Heroku account, then download the Heroku CLI from here
- Follow along with this guide where needed (again, a Procfile and
requiremements.txtare already included, so most of the setup is already done for you)
If you didn't store this bot in a public repository, then you are done (yay!). However, if your code is in a public repository, keep going through to set up the decryption of tokens and credentials:
- In the Heroku website, go to your bot, under the
Deploytab hit the GiHub button, and add your repository - Finally, configure your config variables
- Go to the
Settingstab and hitReveal Config Vars - In the
KEYparameter putTOKEN_DECRYPT_PASS - In the
VALUEparameter put the exact same password you used to encrypt the tokens and credentials
- Go to the
- Set your bot to run and bathe in its majestic glory!
If you have any problems with any of these steps you can make an issue on the TitanBot repository or DM
Johnny Wobble#1085