create account

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

View this thread on: hive.blogpeakd.comecency.com
· @emrebeyler ·
$66.07
dcom [discord community bot] updates: Automatic curation, global blacklist support
> [dcom](https://github.com/emre/dcom) (**d**iscord **com**munity bot) is a (python3.6+)  bot for communities to trigger upvotes from specified discord channels/servers. - [announcement post](https://steemit.com/utopian-io/@emrebeyler/dcom-a-curation-bot-on-discord-for-steem-communities)

<center><img src="https://cdn.steemitimages.com/DQmYT3svFg4mQczC83uTQ7QMvLVLZMT63kfRBV3utZnGgLJ/Screen%20Shot%202018-12-17%20at%209.50.29%20AM.png"></center>

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.

<center><img src="https://cdn.steemitimages.com/DQmWFRAjkYLNpQEDoxKwp4mNj8oKmJyYtZLTiSdn3p4m1iF/Screen%20Shot%202018-12-19%20at%2012.00.09%20PM.png"></center>
<sup>Bot listens the user change events and marks or remove user's patron role in it's internal database.</sup>

# Listening the "role" change events

In order to implement Step1, dcom needs to track [member_update](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_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.

<center><img src="https://cdn.steemitimages.com/DQmP2ppLC21Wur8CFW1JcD1PqN4FKfFxKEibJ7SVyzSAgmh/Screen%20Shot%202018-12-19%20at%2012.03.07%20PM.png"></center>
<center><sup>The snippet to check role change events</sup></center>


# 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](https://github.com/emre/dcom/blob/master/dcom/client.py#L308) 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

- [Implement auto-curation](https://github.com/emre/dcom/pull/4)

# Implementing global blacklist API

@themarkymark has been maintaining a [global blacklist API](https://steemit.com/utopian-io/@themarkymark/global-blacklist-api-now-supports-actifit-s-blacklist) 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.


<center><img src="https://cdn.steemitimages.com/DQmf5khPanhXTmhHSny5yMubWtweqBpUr4EmdgXjBMGmqPH/blacklist.png"></center>

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.

<center><img src="https://cdn.steemitimages.com/DQmPC8W9gYVSEt8evwReYFvW3zUyt61A8toaPDQLidX7NCv/Screen%20Shot%202018-12-19%20at%2012.18.39%20PM.png"></center>

## Pull Request on blacklist feature

- [Implement global blacklist api](https://github.com/emre/dcom/pull/6)


# Updating the bot

```
$ pip install dcom --upgrade
```


# New configuration parameters

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

| Key                   | Value                                                     |
|-----------------------|-----------------------------------------------------------|
| BOT_ACCOUNT           | The account used for the curation                         |
| BOT\_POSTING\_KEY       | Private posting key of the curation account               |
| STEEM_NODES           | A list of STEEM nodes (comma separated)                   |
| DISCORD\_BOT\_TOKEN     | \<Token of the discord bot\>                                |
| CHANNEL_WHITELIST     | Curation channel id list (comma separated)                |
| LATE\_CURATION\_WINDOW  | Maximum age for a post (in seconds)                       |
| EARLY\_CURATION\_WINDOW | Minimum age for a post (in seconds)                       |
| CURATOR_GROUPS        | Discord roles authorized to use the bot (comma separated) |
| REGISTRATION_CHANNEL  | Registration channel (ID)                                 |
| REGISTRATION_ACCOUNT | Registration account (steem username)                      |
| REGISTRATION\_ACCOUNT\_ACTIVE_KEY | Registration account's active key               |
| ROLE\_FOR\_REGISTERED_USERS| Role name for registered users                         |
| MONGO_URI                | Mongodb connection URI                                 |
| COMMUNITY_NAME            | Community name                                         |
| **PATRON_ROLE**           | Designated discord role                                 |
| **BOT\_LOG\_CHANNEL**.      | Channel id for the bot logs on auto-curation.           |
| **ACCOUNT\_FOR\_VP\_CHECK**  | Which account's VP should be checked for auto-curation  |
| **LIMIT\_ON\_MAXIMUM\_VP**   | When should auto-curation triggered   				  |
| **AUTO\_CURATION\_VOTE_WEIGHT** | The default voting weight.  						  |
*(New parameters with this version is marked as bold.)*



# Running

```bash
$ 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.

 

πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 249 others
properties (23)
authoremrebeyler
permlinkdcom-discord-community-bot-updates-automatic-curation-global-blacklist-support
categoryutopian-io
json_metadata{"community":"steempeak","app":"steempeak","format":"markdown","tags":["utopian-io","development","dcom","python","discord"],"users":["emrebeyler","themarkymark"],"links":["https://github.com/emre/dcom","https://steemit.com/utopian-io/@emrebeyler/dcom-a-curation-bot-on-discord-for-steem-communities","https://discordpy.readthedocs.io/en/latest/api.html#discord.on_member_update","https://github.com/emre/dcom/blob/master/dcom/client.py#L308","https://github.com/emre/dcom/pull/4","/@themarkymark","https://steemit.com/utopian-io/@themarkymark/global-blacklist-api-now-supports-actifit-s-blacklist","https://github.com/emre/dcom/pull/6"],"image":["https://cdn.steemitimages.com/DQmYT3svFg4mQczC83uTQ7QMvLVLZMT63kfRBV3utZnGgLJ/Screen%20Shot%202018-12-17%20at%209.50.29%20AM.png","https://cdn.steemitimages.com/DQmWFRAjkYLNpQEDoxKwp4mNj8oKmJyYtZLTiSdn3p4m1iF/Screen%20Shot%202018-12-19%20at%2012.00.09%20PM.png","https://cdn.steemitimages.com/DQmP2ppLC21Wur8CFW1JcD1PqN4FKfFxKEibJ7SVyzSAgmh/Screen%20Shot%202018-12-19%20at%2012.03.07%20PM.png","https://cdn.steemitimages.com/DQmf5khPanhXTmhHSny5yMubWtweqBpUr4EmdgXjBMGmqPH/blacklist.png","https://cdn.steemitimages.com/DQmPC8W9gYVSEt8evwReYFvW3zUyt61A8toaPDQLidX7NCv/Screen%20Shot%202018-12-19%20at%2012.18.39%20PM.png"]}
created2018-12-19 16:56:09
last_update2018-12-19 16:56:09
depth0
children9
last_payout2018-12-26 16:56:09
cashout_time1969-12-31 23:59:59
total_payout_value49.894 HBD
curator_payout_value16.179 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,636
author_reputation448,535,049,068,622
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries
0.
accountutopian.pay
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,077,550
net_rshares123,352,511,353,297
author_curate_reward""
vote details (313)
@beerlover ·
<div class='pull-right'>https://cdn.steemitimages.com/DQmaHThyECGhEx8tSfHZbiMFRNYjJ35K92cDgiJjkzBUaJo/One%20sip%20of%20BEER%20for%20you.gif<p><sup><a href='https://steem-engine.com/?p=market&t=BEER'>View or trade </a> <code>BEER</code>.</sup></p></div><center><br><br> <p> Hey @emrebeyler, here is a little bit of <code>BEER</code> from @isnochys for you. Enjoy it!</p> </center><div></div>
properties (22)
authorbeerlover
permlinkre-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20191219t060854z
categoryutopian-io
json_metadata"{"app": "beem/0.21.1"}"
created2019-12-19 06:08:57
last_update2019-12-19 06:08:57
depth1
children0
last_payout2019-12-26 06:08:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length390
author_reputation25,764,988,873,156
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id93,543,687
net_rshares0
@berniesanders ·
I've given you an upvote and left you this amazing automated comment (since spamming the blockchain is now acceptable)!!<br><br><br>Vote for witness [nextgencrypto](https://steemconnect.com/sign/account-witness-vote?witness=nextgencrypto&approve=1)!!
πŸ‘  
πŸ‘Ž  
properties (23)
authorberniesanders
permlinkberniesanders-re-emrebeylerdcom-discord-community-bot-updates-automatic-curation-global-blacklist-support
categoryutopian-io
json_metadata""
created2018-12-19 17:33:06
last_update2018-12-19 17:33:06
depth1
children1
last_payout2018-12-26 17:33:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length250
author_reputation600,251,775,828,524
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,079,373
net_rshares-1,868,739,561
author_curate_reward""
vote details (2)
@emrebeyler ·
πŸŽ‰
properties (22)
authoremrebeyler
permlinkre-berniesanders-berniesanders-re-emrebeylerdcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181219t174013271z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-12-19 17:40:12
last_update2018-12-19 17:40:12
depth2
children0
last_payout2018-12-26 17:40:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1
author_reputation448,535,049,068,622
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,079,683
net_rshares0
@helo ·
$12.03
- 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](https://join.utopian.io/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](https://review.utopian.io/result/3/1-2-2-1-1-2-1-).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , ,
properties (23)
authorhelo
permlinkre-emrebeyler-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181219t203518963z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/1-2-2-1-1-2-1-","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-12-19 20:35:18
last_update2018-12-19 20:35:18
depth1
children1
last_payout2018-12-26 20:35:18
cashout_time1969-12-31 23:59:59
total_payout_value9.108 HBD
curator_payout_value2.923 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length725
author_reputation121,547,934,535,311
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,087,501
net_rshares21,451,202,969,564
author_curate_reward""
vote details (13)
@utopian-io ·
Thank you for your review, @helo! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-emrebeyler-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181219t203518963z-20181222t070659z
categoryutopian-io
json_metadata"{"app": "beem/0.20.9"}"
created2018-12-22 07:07:00
last_update2018-12-22 07:07:00
depth2
children0
last_payout2018-12-29 07:07:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length56
author_reputation152,955,367,999,756
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,209,802
net_rshares0
@isnochys ·
Haver another happy year, !BEER
properties (22)
authorisnochys
permlinkre-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20191219t060834z
categoryutopian-io
json_metadata"{"app": "beem/0.20.23"}"
created2019-12-19 06:08:39
last_update2019-12-19 06:08:39
depth1
children0
last_payout2019-12-26 06:08:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length31
author_reputation48,455,428,888,504
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id93,543,685
net_rshares0
@sndbox ·
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! πŸ’ͺ
properties (22)
authorsndbox
permlinkre-emrebeyler-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181220t024132974z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["emrebeyler","sndbox"],"app":"steemit/0.1"}
created2018-12-20 02:41:33
last_update2018-12-20 02:41:33
depth1
children0
last_payout2018-12-27 02:41:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length528
author_reputation633,122,316,798,067
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,100,337
net_rshares0
@steem-ua ·
#### 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](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181219t204029z
categoryutopian-io
json_metadata"{"app": "beem/0.20.14"}"
created2018-12-19 20:40:30
last_update2018-12-19 20:40:30
depth1
children0
last_payout2018-12-26 20:40:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length289
author_reputation23,214,230,978,060
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,087,678
net_rshares0
@utopian-io ·
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](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

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

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-dcom-discord-community-bot-updates-automatic-curation-global-blacklist-support-20181221t104759z
categoryutopian-io
json_metadata"{"app": "beem/0.20.9"}"
created2018-12-21 10:48:00
last_update2018-12-21 10:48:00
depth1
children0
last_payout2018-12-28 10:48:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length592
author_reputation152,955,367,999,756
root_title"dcom [discord community bot] updates: Automatic curation, global blacklist support"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id77,168,529
net_rshares0