Note: if you're just looking to use FCOM, please see the repository for FcomClient.
Also, I would prefer that you don't run an instance of my bot. Just use the one I have!
Although the bot appears to users as a single, cohesive entity, it actually consists of three separate components:
- A client-facing Flask API
- Accepts forwarded messages
- Allows clients to "confirm" a registration token and provide a callsign
- The API responds with the Discord username (and Snowflake ID) associated with the given token
- A Discord bot
- Sends the forwarded messages to the associated Discord user
- A relational database (specifically, MariaDB)
- This acts as the link between the two
- It also stores the mappings between Discord users and FCOM clients
The bot and the API need to be run simultaneously.
- Python 3.6+
- discord.py (rewrite)
- Flask
- Gunicorn
- mysql.connector
The requirements.txt
file also contains a number of dependencies, but these are the main ones required.
CREATE DATABASE fcom;
CREATE USER '<username>'@'localhost' identified by '<password>';
Create the following environment variables for the login:
- Username:
FCOM_DB_USERNAME
- Password:
FCOM_DB_PASSWORD
See included schema.sql
file.
Create a file named bot_token.txt
This file should contain the Discord bot token, and nothing else.
This token can be found at https://discordapp.com/developers/applications/
Create a file named curr_client_version.txt
.
This file should contain the current version number in the following format:
FcomClient/x.y.z
x.y.z
is the client version number (e.g. 0.8.0
).
First, download from GitHub, then set up virtualenv
:
cd FcomServer
python3.6 -m venv ./venv
source ./venv/bin/activate
pip3 install wheel
pip3 install -r requirements.txt
pip3 install gunicorn
Create a file named bot_token.txt
inside the FcomServer folder (i.e. at the top level). It should contain your bot token, and nothing else.
Then, run both the bot and the API. They must be run simultaneously.
python3 main_bot.py
python3 main_api.py
If you want to have both run in the background, you'll have to set them up as a service on your operating system.
As is the case with any Flask API, please use a production server to serve the FCOM API.
My implementation uses gunicorn
, but you can use anything, really.
To get out of the virtual environment:
deactivate
As of the time of writing, due to difficulties in getting the bot to clean up old registrations, this feature is implemented via a cronjob that runs every 5 minutes.
Implement the following SQL command via any tool of your choice, as long as it can be executed via cron
:
DELETE FROM registration
WHERE ( is_verified IS TRUE
AND last_updated < Date_sub(Now(), INTERVAL 24 hour) )
OR ( is_verified IS FALSE
AND last_updated < Date_sub(Now(), INTERVAL 5 minute) );