dcom (discord community bot) updates: Registration module

in #utopian-io6 years ago (edited)

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

Sort:  
  • Great quality shown, all the elements that makes a visually appealing and informative post are present.
  • Code is really readable for what it does.
  • I liked the fist pump analogy.

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]

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

Okay Cool job <3

Posted using Partiko Android

Wow, great job. Really cool project

Posted using Partiko Android

Thank you so much for participating the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Hi @emrebeyler!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @emrebeyler!

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!



Hey @emrebeyler, here is a little bit of BEER from @isnochys for you. Enjoy it!

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 56586.95
ETH 2389.49
USDT 1.00
SBD 2.34