There are often many ideas floating around that may never be implemented. Be the reasons a lack of time or a low priority for some tasks postpones their implementations. As I did not work on any interesting side project, I decided to create something for Utopian and potentially for others. I'll present a simple bot for sending messages to Discord with information about task requests.
Utbot is a simple tool that listens to the blockchain operations and waits for the right trigger. Its purpose is to gather necessary information about a Utopian task request and create a consistent message for a Discord server/channel.
While Utopian relies on arbitrary Steem user interface for the submissions, there is no standard followed which would allow simple extraction of crucial information from the posts. Utopian can't save data in json_metadata either and the only way to get a certain kind of information is to follow a template.
Thus, the initial purpose of this tool is to create a template and a set of commands/parameters to generate and send a Discord message. We could say, it is a naive way to replace a notification system for reviewed tasks.
Examples of the messages
The current state of the bot offers a basic format of the task requests information. A reviewer is required to call the bot with a set of parameters to avoid including noise in the message. Perhaps I will be able to figure out a better way, but it currently relies on the person to call it with correct parameters.
Each of the messages consists of two parts. The first one contains the category, task's status and the link to the task. The second one, which is more appealing and covers more information, is a message embed with extra fields such as skills, a bounty or a deadline.
Messages have a category icon and colour to recognise the category faster the task belongs to.
I decided to use Python as the language for the bot since it is closest to me at the moment and Python is quite easy to use. For now, I chose Discord Webhooks to manage the message sending to Discord channel. It has some limitations as it is not able to interact with users and channels. Yet, as long as I am able to do all the work outside Discord, it may be enough. However, I must admit that there are already a few things that would benefit from having knowledge about the Discord context.
Two files lead the settings of the bot,
constants.py. Config.json file contains general parameters that do not hold any sensitive information. They are then loaded in the constants file where the rest of the settings is set.
While not being entirely sure of the best way to save sensitive variables, I decided to let the user determine if they set them in the configuration file or in environment variables. Let me know which one is better and if the current "mirroring" is a bad practice.
There are a few parameters that may be set for the message.
|a status of a task request||required|
|bounty||00 NAME||e.g. 10 SBD |
a bounty may contain more currencies delimited by comma
|description||"text"||text must be enclosed in double quotes||optional|
|skills||"skill1, skill2, skill3"||a set of skills separated by comma; must be enclosed in double quotes||optional|
|a user ID or username with discriminator||optional|
|deadline||2018-01-01||a date in format YYYY-MM-DD||optional|
|assignees||"@steemname1, @steemname2"||Steem mentions of assigned people; valid only for a task that is in progress||optional|
The only required parameter is the status. Other information may not be available in the post because it is not mandatory for the authors to include in the post.
How to call the bot
Only selected people may call the bot. They must call the bot in a comment. For that reason, it is recommended to make a separate comment with the bot parameters. The reason is simple. Since there is no context management, it may trigger the bot every time a comment is edited.
I implemented two ways of passing the input parameters. I will present the one-line format here.
!utbot --status open --bounty 10 SBD --description "Short description of the task" --skills "Python, Flask, Steem" --deadline 2018-01-01 --discord <@351997733646761985>
Things to improve
Since the bot relies on the concept of webhooks, there is no way to get more data from Discord. I will see if the project can continue with webhooks or I will need to switch to Discord bot API.
There are some issues that webhooks can't solve:
- it is not possible to find (actually guess) a user by their username only
- Discord mentions require user ID
- Webhooks do not have access to older messages
- Webhooks are bound to one channel only
- Move more variables to the config file to make the bot of more general use
- Add tests
- Tests will be definitely useful in this case to ensure that the bot remains flexible enough
- Add messages for regular contributions
- Add more commands and parameters with better handling
- Add history/context awareness
- Rely less on manual calls
Utbot is an attempt to bring a standard format for Discord messages. The expectation is to use these message to notify the community of new tasks. While it relies on human's input, it may be a small tool to complement the review process in Utopian.
Because the project is quite new and in the initial phase still, there is no specific part to highlight.