fsc.bot is the open source, custom Discord bot written for the fullstack.chat community.
Features
Here are some key features of the bot at the time of this writing.
XP Tracking
I wrote an XP tracking system to automatically determine which users can be considered ‘active’. I wanted to be able to provide perks to users who actively participated in the conversation, one of which is a regular giveaway of some kind.
Each time a user sends a message to the server, they are granted XP. Continued activity will increase an XP multiplier to help active users gain XP faster. Likewise, inactive users are penalized after several days and XP will slowly start being decremented from their totals. This keeps a balance where active users, regardless of how recently they join, gain the biggest benefits of being on the server.
Portfolios
The portfolio
command allows members to register their portfolio URL with the bot, and the bot will update a single message on the server with all member portfolios. It provides a nice way for everyone to connect with each other and see who works on what.
Help System
I also built in a help system. When a user issues the command !fsc help
, a private message will be sent to them with details on each command available to them. They can also append the name of the command if they are only interested in help for one command.
Behind the Scenes
Below are a few design considerations I took when building the bot.
Dynamic Command Parsing
When the bot starts, it will scan the commands directory and parse in JavaScript files dynamically provided the following fields are exported;
command
- The actual command that is registered with the file.fn
- The function that the message object is passed into for processing.
The following fields are optional, but provide additional functionality;
helpText
- The YAML formatted text that is associated with that command. I chose YAML because I could use syntax highlighting when DMing the user.isEnabled
- If set to false, the init process will skip parsing that command file.shouldCleanup
- If set to true, the bot will remove the message that the user sends to trigger the bot. This helps keep the server clean.
Security
Certain commands should only be issues by moderators, so I implemented a method that checks the requester and confirms they are part of the moderator role before executing the code. If the user is not in the role, they will receive a DM from the bot stating they don't have access to that command.
Scheduled Scripts
A scheduler system exists within the bot where certain JavaScript functions are executed on a schedule based on cron expressions. One example of this is the XP system.
Gaining XP is event driven, specifically when the user sends a message to the server. But penalizing users for inactivity cannot be handled in the same way, so there is a script that runs every 24 hours to decrement XP from inactive users.
Data Caching
During the initialization process for the bot, all data is pulled into memory for quick access. Changes to each dataset are committed back to the database on an individual basis.
Infrastructure
Code for the bot is hosted on GitHub. The pipeline however managed by Azure DevOps. I inject environment variables & configuration flags into the build process and want to keep those private. The bot is run in a Docker container on my personal server at the moment, and data is stored in an Azure Storage Table.
Source for the bot can be found at https://github.com/bmorrisondev/fsc.bot.