Utbot, the bot for a standard format of Utopian submissions in Discord

in #utbot5 years ago

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.

utbotbanner.png
Designed by Rawpixel.com

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.

image.png

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.

Technical details

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.

Settings

Two files lead the settings of the bot, config.json and 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.

Parameters

There are a few parameters that may be set for the message.

NameValuesNoteStatus
statusopen
in progress
closed
a status of a task requestrequired
bounty00 NAMEe.g. 10 SBD
a bounty may contain more currencies delimited by comma
optional
description"text"text must be enclosed in double quotesoptional
skills"skill1, skill2, skill3"a set of skills separated by comma; must be enclosed in double quotesoptional
discord<@0000000000>
username#0000
a user ID or username with discriminatoroptional
deadline2018-01-01a date in format YYYY-MM-DDoptional
assignees"@steemname1, @steemname2"Steem mentions of assigned people; valid only for a task that is in progressoptional

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

Future additions

  • 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

Conclusion

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.


PR Links

Because the project is quite new and in the initial phase still, there is no specific part to highlight.

Sort:  

Looks great. :)

  • There was a small problem on installation instructions. Just sent a PR.

  • Looks like you have defined a helper function (is_utopian_contribution on utils package and import it in the utbot.py, yet, you don't use it in the bot.)

  • Good use of type annotations. :)

Some minor issues includes personal preference:

  • The upper case choice on LOGGER variable kinda feels wrong. It should be a constant variable if you do that. (convention) I think, the logger is something you can mutate and shouldn't be considered as constant.

  • I see some long lines. PEP8 encourages 80 or 100.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hey, thanks for the notes. I will fix the issues. Regarding the length of the lines, I suppose I let some of the strings be too long. Otherwise, I use black formatter which encourages not to stick to 80 chars on a line.

Thank you for your review, @emrebeyler! Keep up the good work!

Hi @espoem!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 5.317 which ranks you at #709 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 280 contributions, your post is ranked at #165.

Evaluation of your UA score:
  • You've built up a nice network.
  • The readers appreciate your great work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Hey, @espoem!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.36
TRX 0.12
JST 0.040
BTC 70446.49
ETH 3571.68
USDT 1.00
SBD 4.73