A discord bot which provides information about a headless factorio server.
-
Install Python 3.9
-
Create a virtual environment. From the root of the repository, run:
python -m venv .venv
-
Active the virtual environment.
-
Windows (PowerShell)
& .\.venv\Scripts\Activate.ps1
-
POSIX (Bash, zsh, or similar)
source ./venv/bin/activate
-
-
Install pip packages:
python -m pip install -r requirements.txt
-
Install the Azure CLI
-
Install the Azure Functions Core Tools
-
Log in with Azure CLI
az login
-
Fetch Azure Functions settings
func azure functionapp fetch-app-settings factorio-bot
-
Modify local.settings.json
- The value of
DISCORD_CLIENT_SECRET
should be set to theCLIENT SECRET
from the Discord application's OAuth2 settings.- NOTE: Azure Key Vault references do not work when developing locally. If this restriction ever changes, this step would no longer be necessary.
- The value of
Using Visual Studio Code, start debugging using the "Attach to Python Functions" configuration (F5 by default). The configuration will automatically launch the local Azure Functions runtime and attach a debugger. The terminal output will show you available functions.
Visual Studio Code offers several extensions that aid with developing Azure Functions. These are listed in .vscode/extensions.json.
Debugging Discord webhooks using ngrok speeds up development significantly. After launching the Functions host and attaching a debugger, use ngrok to start an HTTP tunnel to the default Azure Function port:
ngrok http 7071
Copy the HTTPS endpoint provided by ngrok's output. Go to the Discord application's settings and update the Interactions Endpoint URL to ngrok HTTPS endpoint.
After saving the changes, Discord webhooks are forwarded to your local machine for debugging.
Navigating to http://localhost:4040 in a browser allows for closer inspection of webhook requests and responses, as well as replaying requests.
The factorio server manages a headless factorio process. A companion process monitors the factorio process to track its state and upload to blob storage.
The factorio companion process tracks the following information:
- Whether the VM is online, and how long it has been up.
- Whether the factorio process is running, and how long it has been up.
- Which players are online.
The bot surfaces the state of the factorio process to a discord channel.
/factorio status
: Get the status of the server./factorio start
: Start the server./factorio stop
: Stop the server.
Slash commands are added to the discord application by sending a POST request to the CreateApplicationCommands
Azure Function.