dcom (discord community bot) updates: Registration module

dcom (discord community bot) is a (python3.6+) bot for communities to trigger upvotes from specified discord channels/servers. - announcement post

dcom has been in use for curation commands in @sndbox discord server in the last two weeks and it's working well.

Registration module

The next step was building a registration module to map discord IDs with STEEM usernames. The expected requirements were:

  • Step 1: User can register themselves by sending #registration channel the following command: $register <steem_username>.-
  • Step 2: Bot responds with a unique token and asks for user to send 0.001 STEEM or 0.001 SBD to the designated steem account. (Ex: @sndbox-register.)
  • Step 3: Bot starts to listen incoming transaction of the designated STEEM account. When it finds a suitable transfer including the correct memo, bot marks the user as verified.
  • Step 4: Bot should return the 0.001 SBD or 0.001 STEEM to the sender.
  • Step 5: If the user is verified successfully, bot adds "registered" role to the user in the Discord server.


It takes 45-60 seconds for bot to pick up the memo from the blockchain.

The challenge

In order to listen STEEM transfers in the background, I need to implement a background task runs forever checking incoming transfers.

I was worried to hack stuff to do that before diving into discord.py library, but it looks like it already support background tasks.

Basically, you can attach a background task to the main asyncio loop just by:

client.loop.create_task(my_background_task())

After that, all you need to do is polling the account history via lightsteem.

There are a couple of optimization touches already implemented. Ex: If there are no waiting veritification codes in the last 60 minutes, bot doesn't poll the account history.

Updating the bot

$ pip install dcom --upgrade

New configuration parameters

A .dcom_env file at your user path should store the below fields:

KeyValue
BOT_ACCOUNTThe account used for the curation
BOT_POSTING_KEYPrivate posting key of the curation account
STEEM_NODESA list of STEEM nodes (comma separated)
DISCORD_BOT_TOKEN<Token of the discord bot>
CHANNEL_WHITELISTCuration channel id list (comma separated)
LATE_CURATION_WINDOWMaximum age for a post (in seconds)
EARLY_CURATION_WINDOWMinimum age for a post (in seconds)
CURATOR_GROUPSDiscord roles authorized to use the bot (comma separated)
REGISTRATION_CHANNELRegistration channel (ID)
REGISTRATION_ACCOUNTRegistration account (steem username)
REGISTRATION_ACCOUNT_ACTIVE_KEYRegistration account's active key
ROLE_FOR_REGISTERED_USERSRole name for registered users
MONGO_URIMongodb connection URI
COMMUNITY_NAMECommunity name

(New parameters with this version is marked as bold.)

Running

$ dcom

To make sure the bot runs all the time, you can use supervisor or other process management software.

For the reference, here is my config for the supervisor:

[program:dcom]
command=/home/user/dcom-env/bin/dcom
autostart=true
autorestart=true
redirect_stderr=true
redirect_stdout=true

Roadmap

Pull requests and Commits

H2
H3
H4
Upload from PC
Video gallery
3 columns
2 columns
1 column
9 Comments