This is the first section of our new approval function. Also, check out this concept art I slapped together.
I wanted to see how everybody felt about having an Asian Giant Hornet for a new mascot. I think it's the perfect addition to 2020. 😉
I'm no artist but maybe I can see if @overkillcoin is interesting in another commision using this concept.
I will split it apart in several sections to explain the design.
Section 1 Prechecks
This section performs a few prerequisite checks before querying the chain for eligle downvotes.
@bot.command()
async def approve(ctx, link):
"""Checks post body for @hive-dr mention and https://hive.blog and must be in the flag_comment_review
channel id """
try:
if not mod_check(ctx.author.roles):
await ctx.send('Must be an HDR Moderator or Admin to run this command.')
return
#obtains mods steem account based on pairing in config file and splits our username from single quotes
approving_mod_hive_acct = 'hive-dr'
for item in cfg.Moderators:
if item['DiscordID'] == ctx.author.id:
approving_mod_hive_acct = item['HiveUserName']
await ctx.send("Approving mod's Hive Account identified as "+approving_mod_hive_acct+"!")
print(approving_mod_hive_acct)
if ctx.message.channel.id != cfg.FLAG_APPROVAL_CHANNEL_ID:
await ctx.send('Send commands in the right channel please.')
return
logging.info('Registered command for {} by {}'.format(link, ctx.message.author.name))
comment_perm = link.split('@')[-1]
try:
flaggers_comment = Comment(comment_perm, steem_instance=hive)
except ContentDoesNotExistsException:
await ctx.send('Please look at your link again. Could not find the linked comment.')
return
flagger = Account(flaggers_comment['author'])
hdr = Account(cfg.HDRACCOUNT, steem_instance=hive)
hdrt = Account(cfg.HDRTACCOUNT, steem_instance=hive)
if '@{}'.format('https://hive.blog') not in flaggers_comment['body'].lower():
await ctx.send("Could not find a @%s mention. Please check "
"the comment." % (cfg.HDRACCOUNT))
return
cats = get_abuse_categories(flaggers_comment['body'])
if len(cats) == 0:
await ctx.send('No abuse category found.')
return
await ctx.send('Abuse category acknowledged as {}'.format(', '.join(cats)))
parent_perm = construct_authorperm(flaggers_comment['parent_author'],
flaggers_comment['parent_permlink'])
flagged_post = Comment(parent_perm, steem_instance=hive)
if '@{}'.format('https://hive.blog') not in flaggers_comment['body'].lower():
await ctx.send("Could not find a @%s mention. Please check the comment." % (cfg.HDRACCOUNT))
return
logging.info(f'Flagged post: {flagged_post.authorperm}')
weight = 0
if flagged_post.is_pending(): # to ensure flags are final, check if flagged post is pending payout
await ctx.send("This post is still pending. Try again later!")
return
Section 2 Downvote Query / Credit / Update DB
This section queries, credits, and updates the database. Once the downvoted post reaches payout, a flagger may leave a mention for the downvotes to be processed and paid.
The reporting flag receives a ROI bonus so there is an incentive to be the one to do it. Downvotes will be credited within the approval workflow which is a change from the clunky daily distribution model from before. Expect a significant performance increase.
dv_list = []
dv_count = 0
global distributions = [] #HDR distributions
for v in flagged_post['active_votes']:
if int(v['rshares']) < 0 and v['voter'] == flagger['name']:
dv_count += 1
await ctx.send(str(dv_count)+'Downvote(s) Detected')
hdrdvote = v
ROI = cfg.ROI
ROI += cfg.new_flag_ROI
if not cursor.execute('SELECT flagger FROM steemflagrewards WHERE flagger == ?;', (flagger['name'],)): #check to see if it is flaggers first HDR flag
ROI += cfg.first_flag_ROI
weight = calculate_weight(v,ROI)
if not check_db(flaggers_comment):
await ctx.send("Crediting "+flagger['name']+"'s downvote HDR")
stu = hive.rshares_to_sbd(abs(int(v['rshares'])))
payout_stu = Decimal(max(round(stu,3),0.001))
tx = hive_eng.send_token('HDR', 'hdr-treasury', flagger['name'], payout_stu, 'HDR Flag Payout for @'+flagged_post.author+'/'+flagged_post.permlink)
dist_dict = {'Payeee': flagger['name'], 'Amount': payout_stu, 'TX': tx.id}
distributions += dist_dict
insert_mention(approving_mod_hive_acct,cats,False,flagger['name'], flaggers_comment,flagged_post, hdrdvote, weight, False)
db.commit()
await ctx.send("Added "+flagger['name']+"'s flag to database")
if int(v['rshares']) < 0 and v['voter'] != flagger['name']:
dv_count += 1
await ctx.send(str(dv_count)+'Downvote(s) Detected')
ROI = cfg.ROI
if not cursor.execute('SELECT flagger FROM hdr WHERE flagger == ?;', (flagger['name'],)): #check to see if it is flaggers first HDR flag
ROI += cfg.first_flag_ROI
weight = calculate_weight(v,ROI)
if(flag_exists(q[0],flagger)):
continue
await ctx.send("Crediting "+flagger['name']+"'s downvote HDR")
stu = hive.rshares_to_sbd(abs(int(v['rshares'])))
dist_dict = {'Payee': pay['flagger'], 'Amount': payout_stu, 'TX': tx.id
distributions += dist_dict
payout_stu = Decimal(max(round(stu,3),0.001))
tx = hive_eng.send_token('HDR', 'hdr-treasury', flagger['name'], payout_stu, 'HDR Flag Payout for @'+flagged_post.author+'/'+flagged_post.permlink)
insert_mention(approving_mod_hive_acct,cats,False,flagger['name'],None, flagged_post, v, weight,False)
if not weight:
print(weight)
await ctx.send('Apparently, the post wasn\'t flagged!')
return
else:
await ctx.send("Flag already in database")
body = get_approval_comment_body(flaggers_comment['author'], cats,False)
hive.post('', body, #Leave Downvote Approval Comment
reply_identifier=flaggers_comment['authorperm'],
community='HDR', parse_body=True,
author=hdr.name)
await ctx.send('Commented.')
Section 3 Bonus Curation
If there is excess VP, reporting comment will be upvoted nominally. This will be a bonus to the existing moderation incentive and serve to optimize voting power.
if hdr.vp > 98:
min_vote_pct = hive.rshares_to_vote_pct(0.0245 / hive.get_sbd_per_rshares(),
hive_power=hdr.sp,
voting_power=hdr.vp)
for curator in cfg.CURATORS:
curator_account = Account(curator,steem_instance=hive)
if curator_account.vp > 90:
flaggers_comment.upvote(weight=3,voter=curator)
flaggers_comment.upvote(weight=round((min_vote_pct*3) / 10000),voter=cfg.SFRACCOUNT)
Section 4 New Flag Report
This report will be generated as a post is approved providing an audit log of token transactions for users. Ideally, we will want to move this functionality to a proper front end which will be something that I work on as my schedule permits.
if distributions:
tr = payout_report(distributions)
msg = 'Sucessfully posted a new Token Distribution report! Check it out! (And upvote it as well :P)\nhttps://hive.blog/{}'.format(
r)
await ctx.send(msg)
postpromo = bot.get_channel(cfg.POST_PROMOTION_CHANNEL_ID)
await postpromo.send(msg)
hdr.claim_reward_balance()
hdr.refresh()
hdrt.refresh()
except OSError as e:
print(e)
bot.clear()...
The approval mechanism has arguably been one of the most convoluted. The new approach intends to streamline the process. THe next step will be for us to resolve dependencies in the parent script but hopefully with this post you have a better idea of where I am going with things.