dcom [discord community bot] updates: Automatic curation, global blacklist support

in #utopian-io5 years ago

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

dcom's registration module was a success. It has been working the last 2-3 days and working well.

The remaining planned features were also completed today.

Automatic Curation

After having registration and manual curation capabilities, the next step was building an automatic curation process.

  • Step 1: Discord user gains access to a designated role. (Let's call it patron.) in the discord server.

  • Step 2: Discord user registers his STEEM account to their discord handle by using the $register command and verifies ownership.

  • Step 4: dcom checks the voting power of the main curation account in the background, periodically.

  • Step 5: If the voting power is greater than %99, it will fetch a list of votable patron posts in the STEEM blockchain and upvote them with a %20 voting weight. (Voting weight and voting power should be configurable in the .env file.)

There are a couple of limitations are already in place. Ex: A patron can only get one upvote in 24 hours.


Bot listens the user change events and marks or remove user's patron role in it's internal database.

Listening the "role" change events

In order to implement Step1, dcom needs to track member_update events in the discord server.

By attaching your custom function to that event, you get two parameters. The first one is the old instance of the user, the second one is the fresh instance of the user.

That way I could check the roles in both old and fresh instances and checked if there was a change in their "patron" roles.


The snippet to check role change events

Curating in the background

After completing the step1 by listening role changes, the rest of the logic was easy to implement.

A new background task called auto_curation is attached to the main asyncio loop.

This function checks

  • if the VP is enough
  • if there are registered and available patrons available for curating
  • if there are suitable posts with the available patrons

and curates automatically.

One minor problem in this part is that the blocking calls to the STEEM blockchain. Steem doesn't have any asynchronous library to interact with the chain, so there are some parts blocking the i/o.

I don't think that's a huge problem on a small scale like this, but if that results with a lag in the bot, I am thinking about separating the background voter from the main bot.

Pull request on automatic curation

Implementing global blacklist API

@themarkymark has been maintaining a global blacklist API for a while. For the $upvote command of the bot, there is a check placed if the author is blacklisted in any community, then the upvote operation won't happen.

The same "blocking i/o" problem was also the case for here, too. Using the good, old requests library in here creates the same problem.

So, I have used aiohttp library to make sure the main asyncio loop is not blocked.

Pull Request on blacklist feature

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
PATRON_ROLEDesignated discord role
BOT_LOG_CHANNEL.Channel id for the bot logs on auto-curation.
ACCOUNT_FOR_VP_CHECKWhich account's VP should be checked for auto-curation
LIMIT_ON_MAXIMUM_VPWhen should auto-curation triggered
AUTO_CURATION_VOTE_WEIGHTThe default voting weight.

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

Running

$ dcom

That's all for this update. I think dcom is in a good state for feature-wise at the moment. All planned requirements are implemented.

Sort:  
  • Great looking article with code samples.
  • Good job on mentioning your challenges, others can learn and even answers may be offered.
  • I really appreciate the upgrade instructions as it is often overlooked in other projects.

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!

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

This is very exciting @emrebeyler! Thank you for working with us on developing a community bot with such amazing super powers. We'll go-live with an updated Discord channel structure in the first week of January and also craft a @sndbox post to highlight the community benefits of this.

In terms of scaling this (growing the chatroom) we'll keep an eye out for hiccups / if it will eventually require two separate bots to handle role curation + other tasks.

Thank you again for your generous time, support, and expertise! 💪

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!

Haver another happy year, !BEER



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

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 62934.09
ETH 3118.65
USDT 1.00
SBD 3.85