def test_vote(self): bts = self.bts c = Comment(self.authorperm, blockchain_instance=bts) bts.txbuffer.clear() tx = c.vote(100, account="test") self.assertEqual((tx["operations"][0][0]), "vote") op = tx["operations"][0][1] self.assertIn("test", op["voter"]) c.blockchain.txbuffer.clear() tx = c.upvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 10000) c.blockchain.txbuffer.clear() tx = c.upvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 9990) c.blockchain.txbuffer.clear() tx = c.downvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -10000) c.blockchain.txbuffer.clear() tx = c.downvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -9990)
def vote_discussion( discussion: Comment, voter: str, weight: float ) -> bool: """Vote a discussion (post, comment) with selected account and vote weight. :param discussion: Post or comment :type discussion: beem.comment.Comment :param voter: Voter :type voter: str :param weight: Vote weight :type weight: float :return: True if vote was successful else False :rtype: bool """ try: discussion.upvote(weight, voter) except beem.exceptions.VotingInvalidOnArchivedPost: LOGGER.info("Invalid post, can't vote. %s", discussion["url"]) return False except: LOGGER.exception( "Error during upvoting with %s. %s", voter, discussion["url"] ) return False else: LOGGER.info( "Upvote with account %s at weight %s%%. %s", voter, weight, discussion["url"], ) return True
def test_vote(self, node_param): if node_param == "non_appbase": bts = self.bts else: bts = self.appbase c = Comment(self.authorperm, steem_instance=bts) bts.txbuffer.clear() tx = c.vote(100, account="test") self.assertEqual((tx["operations"][0][0]), "vote") op = tx["operations"][0][1] self.assertIn("test", op["voter"]) c.steem.txbuffer.clear() tx = c.upvote(weight=150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 10000) c.steem.txbuffer.clear() tx = c.upvote(weight=99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], 9990) c.steem.txbuffer.clear() tx = c.downvote(weight=-150, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -10000) c.steem.txbuffer.clear() tx = c.downvote(weight=-99.9, voter="test") op = tx["operations"][0][1] self.assertEqual(op["weight"], -9990)
async def queue_voting(ctx, sfr): """ Voting on steemflagrewards mentions one after one once the voting power of the account reached 90%. This maintains a rather staple flagging ROI """ global queueing while queueing: while sfr.vp < queue_vp: # For not failing because of unexpected manual votes await asyncio.sleep(sfr.get_recharge_timedelta(queue_vp).total_seconds()) sfr.refresh() next_queued = cursor.execute( 'SELECT comment, flagger, category, weight, followon FROM steemflagrewards WHERE queue == 1 ORDER BY created ASC LIMIT 1;').fetchone() if not next_queued: queueing = False await ctx.send('No more mentions left in the queue. Going back to instant voting mode.') return authorperm, flagger, cats, weight, follow_on = next_queued comment = Comment(authorperm,steem_instance=stm) #gets post created date without timezone info for comparing to now created = comment['created'].replace(tzinfo=None) now=datetime.datetime.utcnow().replace(microsecond=0) dif = now - created ts = round(dif.total_seconds()) difmin=round((ts/60)) if(difmin < 15): await asyncio.sleep(ts) try: comment.upvote(weight, sfr.name) await asyncio.sleep(STEEM_MIN_VOTE_INTERVAL) # sleeps to account for STEEM_MIN_VOTE_INTERVAL except VotingInvalidOnArchivedPost: await ctx.send( 'Sadly one comment had to be skipped because it got too old.' \ 'Maybe the author can delete the comment and write a new one?') cursor.execute('UPDATE steemflagrewards SET queue = 0 WHERE comment == ?', (authorperm,)) db.commit() continue await ctx.send(f'Sucessfully voted on mention by {flagger} out of the queue.') if not follow_on: cat_string = '' for i in cats.split(', '): cat_string += CAT_DESCRIPTION[i] body = 'Steem Flag Rewards mention comment has been approved! Thank you for reporting' \ 'this abuse, @{}. {} This post was submitted via our Discord Community channel.' \ 'Check us out on the following link!\n[SFR Discord](https://discord.gg/7pqKmg5)'.format( flagger, cat_string) await asyncio.sleep(get_wait_time(sfr)) stm.post('', body, reply_identifier=authorperm, community='SFR', parse_body=True, author=sfr.name) await ctx.send('Commented on queued mention.') cursor.execute('UPDATE steemflagrewards SET queue = 0 WHERE comment == ?', (authorperm,)) db.commit() sfr.refresh() return
def monitor(): table = db.load_table("leaderboard") vote_table = db["vote_history"] print("[Monitor Starting up...]") # Read the live stream and filter out only transfers for post in stream: try: q = table.find_one(user=post["author"]) if q is not None and post["author"] == q["user"]: perm = construct_authorperm(post["author"], post["permlink"]) c = Comment(perm, blockchain_instance=hive) if c.is_main_post(): today = datetime.now(timezone.utc) week_tally = tally(post["author"]) print(f"[Post Found! By: {q['user']} Rank: {q['rank']}]") vote_weight = math.ceil( ((160 - q["rank"]) * 2.5) / (week_tally)) vote_weight = 100 if vote_weight >= 100 else vote_weight vote_weight = 1 if vote_weight <= 1 else vote_weight print( f"[{week_tally} post(s) a week. - {perm} should be voted with a {vote_weight}% upvote.]" ) # Trying to catch about the 4 minute mark for curation. time.sleep(240) tx = c.upvote(weight=vote_weight, voter=voter) reply_body = f"Your current Rank ({q['rank']}) in the battle Arena of Holybread has granted you an Upvote of {vote_weight}%" # print(tx) reply_tx = c.reply(reply_body, title="Leaderboard Vote", author=voter) # print(reply_tx) vote_table.insert( dict( user=q["user"], rank=q["rank"], post=perm, vote_weight=vote_weight, vote_time=today, )) except Exception as e: print(f"[Error: {e}]")
def votecall(): for b in balances: if len(blacklist) > 0 and b["account"] in blacklist: print("blacklisted user, skipping...") continue if float(b["balance"]) < 5: print("user under minimum balance") continue account = Account(b["account"]) for post in account.get_blog(limit=1): c = Comment(post, steem_instance=stm) if (c.time_elapsed().total_seconds() / 60 / 60 / 24) > max_post_age_days: print("Post is to old, skipping") time.sleep(1) continue if (c.time_elapsed().total_seconds() / 60) < min_post_age: print("Post is to new, skipping") time.sleep(1) continue tags_ok = True if len(blacklist_tags) > 0 and "tags" in c: for t in blacklist_tags: if t in c["tags"]: tags_ok = False if not tags_ok: print("skipping, as one tag is blacklisted") time.sleep(1) continue already_voted = False for v in c["active_votes"]: if v["voter"] == upvote_account: already_voted = True if already_voted: print("skipping, as already upvoted") continue upvote_weight = float(b["balance"]) / 20 if c["author"] != b["account"]: print("Skipping reblog") continue if upvote_weight > 100: upvote_weight = 100 print("upvote %s from %s with %.2f %%" % (c["permlink"], c["author"], upvote_weight)) c.upvote(weight=upvote_weight, voter=upvote_account) time.sleep(3) reply_body = "You have received a " + str( upvote_weight ) + "% upvote based on your balance of " + str( b["stake"]) + " TMPS!" c.reply(body=reply_body, author=upvote_account) print("sending comment") time.sleep(1) continue print("upvote %s from %s with %.2f %%" % (c["permlink"], c["author"], upvote_weight)) c.upvote(weight=upvote_weight, voter=upvote_account) time.sleep(3) reply_body = "You have received a " + str( upvote_weight) + "% upvote based on your balance of " + str( b["balance"]) + " TMPS!" c.reply(body=reply_body, author=upvote_account) print("sending comment") time.sleep(1) print("Process Complete!") time.sleep(5)
voter = acc if voter is None: voter = "steembasicincome" if nobroadcast and voter is not None: print(c["authorperm"]) print("Comment Vote %s from %s with %.2f %%" % (author, voter, vote_percentage)) elif voter is not None: print("Comment Upvote %s from %s with %.2f %%" % (author, voter, vote_percentage)) vote_sucessfull = False cnt = 0 while not vote_sucessfull and cnt < 5: try: c.upvote(vote_percentage, voter=voter) time.sleep(4) c.refresh() for v in c["active_votes"]: if voter == v["voter"]: vote_sucessfull = True except: time.sleep(4) if cnt > 0: c.steem.rpc.next() print("retry to vote %s" % c["authorperm"]) cnt += 1 if vote_sucessfull: upvote_counter[author] += 1 postTrx.update_voted(author, created, vote_sucessfull) else:
def upvote(s, post_author, permlink, voter): acc = Comment("@{}/{}".format(post_author, permlink), steem_instance=s) votes = acc.upvote(voter=voter)
def run(self, start_block, stop_block): self.hive.wallet.unlock(self.config["wallet_password"]) self.blockchain = Blockchain(mode='head', blockchain_instance=self.hive) current_block = self.blockchain.get_current_block_num() if stop_block is None or stop_block > current_block: stop_block = current_block if start_block is None: start_block = current_block last_block_num = current_block - 1 else: last_block_num = start_block - 1 self.log_data["start_block_num"] = start_block for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"]): self.log_data = print_block_log(self.log_data, op, self.config["print_log_at_block"]) last_block_num = op["block_num"] if op["type"] == "comment": token = None for key in self.token_config: if op["body"].find( self.token_config[key]["comment_command"]) >= 0: token = key if token is None: continue if op["author"] == self.token_config[token]["token_account"]: continue cnt = 0 c_comment = None c_parent = None authorperm = construct_authorperm(op) use_tags_api = True while c_comment is None and cnt < 10: cnt += 1 try: c_comment = Comment(authorperm, use_tags_api=use_tags_api, blockchain_instance=self.hive) c_comment.refresh() except: if cnt > 5: use_tags_api = False nodelist = NodeList() nodelist.update_nodes() self.hive = Hive(node=nodelist.get_hive_nodes(), num_retries=5, call_num_retries=3, timeout=15) time.sleep(3) if cnt == 10 or c_comment is None: logger.warn("Could not read %s/%s" % (op["author"], op["permlink"])) continue if 'depth' in c_comment: if c_comment['depth'] == 0: continue else: if c_comment["parent_author"] == '': continue if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0: logger.warn("Skip %s, as edited" % c_comment["authorperm"]) continue already_voted = False if self.token_config[token]["upvote_token_receiver"]: parent_identifier = construct_authorperm( c_comment["parent_author"], c_comment["parent_permlink"]) c_parent = Comment(parent_identifier, blockchain_instance=self.hive) for v in c_parent.get_votes(raw_data=True): if self.token_config[token]["token_account"] == v[ "voter"]: already_voted = True else: for v in c_comment.get_votes(raw_data=True): if self.token_config[token]["token_account"] == v[ "voter"]: already_voted = True if already_voted: continue already_replied = None cnt = 0 if self.token_config[token]["usage_upvote_percentage"] == 0: while already_replied is None and cnt < 5: cnt += 1 try: already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token][ "token_account"]: already_replied = True except: already_replied = None self.hive.rpc.next() if already_replied is None: already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token][ "token_account"]: already_replied = True if already_replied: continue muting_acc = Account(self.token_config[token]["token_account"], blockchain_instance=self.hive) blocked_accounts = muting_acc.get_mutings() if c_comment["author"] in blocked_accounts: logger.info("%s is blocked" % c_comment["author"]) continue # Load bot token balance bot_wallet = Wallet(self.token_config[token]["token_account"], blockchain_instance=self.hive) symbol = bot_wallet.get_token( self.token_config[token]["symbol"]) # parse amount when user_can_specify_amount is true amount = self.token_config[token]["default_amount"] if self.token_config[token]["user_can_specify_amount"]: start_index = c_comment["body"].find( self.token_config[token]["comment_command"]) stop_index = c_comment["body"][start_index:].find("\n") if stop_index >= 0: command = c_comment["body"][start_index + 1:start_index + stop_index] else: command = c_comment["body"][start_index + 1:] command_args = command.replace(' ', ' ').split(" ")[1:] if len(command_args) > 0: try: amount = float(command_args[0]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.info("Could not parse amount") if self.token_config[token][ "maximum_amount_per_comment"] and amount > self.token_config[ token]["maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if not self.config["no_broadcast"] and self.hive.wallet.locked( ): self.hive.wallet.unlock(self.config["wallet_password"]) self.log_data["new_commands"] += 1 wallet = Wallet(c_comment["author"], blockchain_instance=self.hive) token_in_wallet = wallet.get_token( self.token_config[token]["symbol"]) balance = 0 if token_in_wallet is not None: logger.info(token_in_wallet) if self.token_config[token]["count_only_staked_token"]: balance = 0 else: balance = float(token_in_wallet["balance"]) if "stake" in token_in_wallet: balance += float(token_in_wallet['stake']) if 'delegationsIn' in token_in_wallet and float( token_in_wallet['delegationsIn']) > 0: balance += float(token_in_wallet['delegationsIn']) if 'pendingUnstake' in token_in_wallet and float( token_in_wallet['pendingUnstake']) > 0: balance += float(token_in_wallet['pendingUnstake']) if balance > self.token_config[token][ "min_token_in_wallet"]: if self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = int( balance / self.token_config[token] ["token_in_wallet_for_each_outgoing_token"]) else: max_token_to_give = self.token_config[token][ "maximum_amount_per_comment"] else: max_token_to_give = 0 else: max_token_to_give = 0 logger.info("token to give for %s: %f" % (c_comment["author"], max_token_to_give)) db_data = read_data(self.data_file) if "accounts" in db_data and c_comment["author"] in db_data[ "accounts"] and token in db_data["accounts"][ c_comment["author"]]: if db_data["accounts"][c_comment["author"]][token][ "last_date"] == date.today( ) and self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = max_token_to_give - db_data[ "accounts"][c_comment["author"]][token]["amount"] if amount > max_token_to_give: amount = max_token_to_give if amount > self.token_config[token][ "maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if token_in_wallet is None or balance < self.token_config[ token]["min_token_in_wallet"]: reply_body = self.token_config[token]["fail_reply_body"] elif max_token_to_give < 1: reply_body = self.token_config[token][ "no_token_left_for_today"] elif c_comment["parent_author"] == c_comment["author"]: reply_body = "You cannot sent token to yourself." elif float(symbol["balance"]) < amount: reply_body = self.token_config[token]["no_token_left_body"] else: if "{}" in self.token_config[token]["sucess_reply_body"]: reply_body = (self.token_config[token] ["sucess_reply_body"]).format( c_comment["parent_author"]) else: reply_body = self.token_config[token][ "sucess_reply_body"] if "{}" in self.token_config[token]["token_memo"]: token_memo = ( self.token_config[token]["token_memo"]).format( c_comment["author"]) else: token_memo = self.token_config[token]["token_memo"] sendwallet = Wallet( self.token_config[token]["token_account"], blockchain_instance=self.hive) try: logger.info( "Sending %.2f %s to %s" % (amount, self.token_config[token]["symbol"], c_comment["parent_author"])) sendwallet.transfer(c_comment["parent_author"], amount, self.token_config[token]["symbol"], token_memo) if "accounts" in db_data: accounts = db_data["accounts"] else: accounts = {} if c_comment["author"] not in accounts: accounts[c_comment["author"]] = {} accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } elif token not in accounts[c_comment["author"]]: accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: if accounts[c_comment["author"]][token][ "last_date"] < date.today(): accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: accounts[c_comment["author"]][token][ "n_comments"] += 1 accounts[c_comment["author"]][token][ "amount"] += amount store_data(self.data_file, "accounts", accounts) logger.info( "%s - %s" % (c_comment["author"], str(accounts[c_comment["author"]][token]))) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not send %s token" % self.token_config[token]["symbol"]) continue reply_identifier = construct_authorperm( c_comment["parent_author"], c_comment["parent_permlink"]) if self.config["no_broadcast"]: logger.info("%s" % reply_body) else: try: self.hive.post( "", reply_body, author=self.token_config[token]["token_account"], reply_identifier=reply_identifier) if self.token_config[token][ "usage_upvote_percentage"] <= 0: time.sleep(5) self.hive.post( "", "Command accepted!", author=self.token_config[token] ["token_account"], reply_identifier=c_comment["authorperm"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not reply to post") continue if self.token_config[token]["usage_upvote_percentage"] > 0: time.sleep(5) upvote_percentge = self.token_config[token][ "usage_upvote_percentage"] if self.token_config[token]["scale_upvote_weight"]: upvote_percentge = upvote_percentge * amount / self.token_config[ token]["maximum_amount_per_comment"] print("Upvote with %.2f %%" % upvote_percentge) if self.token_config[token]["upvote_token_receiver"]: if c_parent is None: c_parent = Comment( parent_identifier, blockchain_instance=self.hive) try: c_parent.upvote(upvote_percentge, voter=self.token_config[token] ["token_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") else: try: c_comment.upvote(upvote_percentge, voter=self.token_config[token] ["token_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") time.sleep(4) return last_block_num
if (c.time_elapsed().total_seconds() / 60 / 60 / 24) > max_post_age_days: print("Post is to old, skipping") continue if (c.time_elapsed().total_seconds() / 60) < min_post_age: print("Post is to new, skipping") continue tags_ok = True if len(blacklist_tags) > 0 and "tags" in c: for t in blacklist_tags: if t in c["tags"]: tags_ok = False if not tags_ok: print("skipping, as one tag is blacklisted") continue already_voted = False for v in c["active_votes"]: if v["voter"] == upvote_account: already_voted = True if already_voted: print("skipping, as already upvoted") continue upvote_weight = float(h["quantity"]) * token_weight_factor if upvote_weight > 100: upvote_weight = 100 print("upvote %s from %s with %.2f %%" % (c["permlink"], c["author"], upvote_weight)) c.upvote(weight=upvote_weight, voter=upvote_account) time.sleep(60)
async def approve(ctx, link): """Checks post body for @steemflagrewards mention and https://steemit.com/ and must be in the flag_comment_review channel id """ global queueing if ctx.message.channel.id != 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=stm) except ContentDoesNotExistsException: await ctx.send('Please look at your link again. Could not find the linked comment.') return flagger = Account(flaggers_comment['author']) sfr = Account(sfr_name,steem_instance=stm) if '@steemflagrewards' not in flaggers_comment['body']: await ctx.send('Could not find a @steemflagrewards mention. Please check the comment.') return cats = check_cat(flaggers_comment['body']) if not cats: await ctx.send('No abuse category found.') return await ctx.send('Abuse category acknowledged as {}'.format(', '.join(cats))) flagged_post = Comment('{}/{}'.format(flaggers_comment['parent_author'], flaggers_comment['parent_permlink']),steem_instance=stm) cursor.execute('SELECT * FROM steemflagrewards WHERE comment == ?', (flagged_post.authorperm,)) if flagged_post['author'] == sfr_name: # Check if flag is a follow on flag for i in range(2): flagged_post = Comment('{}/{}'.format(flagged_post['parent_author'], flagged_post['parent_permlink']),steem_instance=stm) follow_on = True await ctx.send('Follow on flag spotted') elif cursor.fetchone(): follow_on = True while True: flaggers_comment = Comment(flaggers_comment['parent_author']+'/'+ flaggers_comment['parent_permlink'],steem_instance=stm) if cursor.execute('SELECT * FROM steemflagrewards WHERE post == ?', (flaggers_comment.permlink,)).fetchall(): break else: follow_on = False cursor.execute('SELECT post FROM steemflagrewards WHERE post == ?', (flagged_post.authorperm,)) if cursor.fetchall(): await ctx.send( 'There has already been some flagging happenin\' on that post/comment. Please consider using the follow on flag feature if you don\'t make a good comment.') follow_on = True logging.info(f'Flagged post: {flagged_post.authorperm}') weight = 0 for v in flagged_post['active_votes']: if int(v['rshares']) < 0 and v['voter'] == flagger['name']: await ctx.send('Downvote confirmed') sfrdvote = v follow_on_ROI = 0.1 new_flag_ROI = 0.2 first_flag_ROI = 0.25 ROI = 1.05 if follow_on is True: ROI += follow_on_ROI elif follow_on is False: ROI += new_flag_ROI else: await ctx.send('Something went very wrong. I\'m sorry about the inconvenience.') if not cursor.execute('SELECT flagger FROM steemflagrewards WHERE flagger == ?;', (flagger.name,)): ROI += first_flag_ROI if queueing: voting_power = queue_vp * 100 else: voting_power = sfr.vp * 100 vote_pct = stm.rshares_to_vote_pct(int(abs(int(v['rshares'])) * ROI), # ROI for the flaggers steem_power=sfr.sp, voting_power=voting_power) min_vote_pct = stm.rshares_to_vote_pct(0.0245 / stm.get_sbd_per_rshares(), steem_power=sfr.sp, voting_power=voting_power) weight = max(round((vote_pct / 10000) * 100), round((min_vote_pct / 10000) * 100)) if sfr.get_vote(flaggers_comment): await ctx.send('Already voted on this!') return elif not weight: await ctx.send('Apparently, the post wasn\'t flagged!') return if not queueing: logging.info('Attempting to vote now.') created = flaggers_comment['created'].replace(tzinfo=None) now=datetime.datetime.utcnow().replace(microsecond=0) dif = now - created ts = round(dif.total_seconds()) difmin=round((ts/60)) if(difmin < 15): await asyncio.sleep(ts) flaggers_comment.upvote(weight=weight, voter=sfr.name) await ctx.send('Upvoted.') if not follow_on: cat_string = '' for i in cats: cat_string += CAT_DESCRIPTION[i] body = 'Steem Flag Rewards mention comment has been approved! Thank you for reporting this abuse, @{}. {} This post was submitted via our Discord Community channel. Check us out on the following link!\n[SFR Discord](https://discord.gg/7pqKmg5)'.format( flaggers_comment['author'], cat_string) await asyncio.sleep(get_wait_time(sfr)) stm.post('', body, reply_identifier='{}/{}'.format(flaggers_comment['author'], flaggers_comment['permlink']), community='SFR', parse_body=True, author=sfr.name) await ctx.send('Commented.') else: await ctx.send('Queued upvote for later on.') cursor.execute('INSERT INTO steemflagrewards VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', ( flagger.name, flaggers_comment.authorperm, flagged_post.authorperm, ', '.join(cats), flaggers_comment['created'], False, stm.rshares_to_sbd(sfrdvote['rshares']), queueing, weight, follow_on)) db.commit() q = \ cursor.execute( 'SELECT COUNT(DISTINCT flagger) FROM steemflagrewards WHERE included == 0;').fetchone()[ 0] await ctx.send('Now at {} out of 9 needed flaggers for a report.'.format(q)) if q > 8: await ctx.send('Hit flagger threshold. Posting report.') r = report() msg = 'Sucessfully posted a new report! Check it out! (And upvote it as well :P)\nhttps://steemit.com/{}'.format( r) await ctx.send(msg) postpromo = bot.get_channel(POST_PROMOTION_CHANNEL_ID) await postpromo.send(msg) sfr.claim_reward_balance() sfr.refresh() if sfr.vp < queue_vp and not queueing: await ctx.send( 'Hey my mojo is getting low. I should take a break...\nThat\'s why I\'ll go into queue mode now.'.format( str(round(sfr.get_voting_value_SBD(), 3)))) queueing = True await queue_voting(ctx, sfr)
24) > max_post_age_days: print("Post is to old, skipping") continue tags_ok = True if len(blacklist_tags) > 0 and "tags" in c: for t in blacklist_tags: if t in c["tags"]: tags_ok = False if not tags_ok: print("skipping, as one tag is blacklisted") continue already_voted = False for v in c["active_votes"]: if v["voter"] == upvote_account: already_voted = True if already_voted: print("skipping, as already upvoted") continue upvote_weight = float(h["quantity"]) * token_weight_factor if upvote_weight > 100: upvote_weight = 100 print("upvote %s from %s with %.2f %%" % (c["permlink"], c["author"], upvote_weight)) print(c.upvote(weight=upvote_weight, voter=upvote_account)) if len(reply_comment) > 0: time.sleep(4) print(c.reply(reply_comment, author=upvote_account)) time.sleep(60)
def run(self, start_block): self.stm.wallet.unlock(self.config["wallet_password"]) self.blockchain = Blockchain(mode='head', steem_instance=self.stm) stop_block = self.blockchain.get_current_block_num() if start_block is not None: last_block_num = start_block - 1 self.log_data["start_block_num"] = start_block for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"], max_batch_size=50): self.log_data = print_block_log(self.log_data, op, self.config["print_log_at_block"]) last_block_num = op["block_num"] if op["type"] == "comment": token = None for key in self.token_config: if op["body"].find( self.token_config[key]["comment_command"]) >= 0: token = key if token is None: continue if op["author"] == self.token_config[token]["token_account"]: continue try: c_comment = Comment(op, steem_instance=self.stm) c_comment.refresh() except: logger.warn("Could not read %s/%s" % (op["author"], op["permlink"])) continue if c_comment.is_main_post(): continue if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0: logger.warn("Skip %s, as edited" % c_comment["authorperm"]) continue already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token][ "token_account"]: already_replied = True if already_replied: continue muting_acc = Account(self.token_config[token]["token_account"], steem_instance=self.stm) blocked_accounts = muting_acc.get_mutings() if c_comment["author"] in blocked_accounts: logger.info("%s is blocked" % c_comment["author"]) continue # Load bot token balance bot_wallet = Wallet(self.token_config[token]["token_account"], steem_instance=self.stm) symbol = bot_wallet.get_token( self.token_config[token]["symbol"]) # parse amount when user_can_specify_amount is true amount = self.token_config[token]["default_amount"] if self.token_config[token]["user_can_specify_amount"]: start_index = c_comment["body"].find( self.token_config[token]["comment_command"]) stop_index = c_comment["body"][start_index:].find("\n") if stop_index >= 0: command = c_comment["body"][start_index + 1:start_index + stop_index] else: command = c_comment["body"][start_index + 1:] command_args = command.replace(' ', ' ').split(" ")[1:] if len(command_args) > 0: try: amount = float(command_args[0]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.info("Could not parse amount") if self.token_config[token][ "maximum_amount_per_comment"] and amount > self.token_config[ token]["maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if not self.config["no_broadcast"] and self.stm.wallet.locked( ): self.stm.wallet.unlock(self.config["wallet_password"]) self.log_data["new_commands"] += 1 wallet = Wallet(c_comment["author"], steem_instance=self.stm) token_in_wallet = wallet.get_token( self.token_config[token]["symbol"]) if token_in_wallet is not None: balance = float(token_in_wallet["balance"]) if "stake" in token_in_wallet: balance += float(token_in_wallet['stake']) if 'delegationsIn' in token_in_wallet and float( token_in_wallet['delegationsIn']) > 0: balance += float(token_in_wallet['delegationsIn']) if 'pendingUnstake' in token_in_wallet and float( token_in_wallet['pendingUnstake']) > 0: balance += float(token_in_wallet['pendingUnstake']) if balance > self.token_config[token][ "min_token_in_wallet"]: if self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = int( balance / self.token_config[token] ["token_in_wallet_for_each_outgoing_token"]) else: max_token_to_give = self.token_config[token][ "maximum_amount_per_comment"] else: max_token_to_give = 0 else: max_token_to_give = 0 db_data = read_data(self.data_file) if "accounts" in db_data and c_comment["author"] in db_data[ "accounts"] and token in db_data["accounts"][ c_comment["author"]]: if db_data["accounts"][c_comment["author"]][token][ "last_date"] == date.today( ) and self.token_config[token][ "token_in_wallet_for_each_outgoing_token"] > 0: max_token_to_give = max_token_to_give - db_data[ "accounts"][c_comment["author"]][token]["amount"] if amount > max_token_to_give: amount = max_token_to_give if amount > self.token_config[token][ "maximum_amount_per_comment"]: amount = self.token_config[token][ "maximum_amount_per_comment"] if token_in_wallet is None or float( token_in_wallet["balance"] ) < self.token_config[token]["min_token_in_wallet"]: reply_body = self.token_config[token]["fail_reply_body"] elif max_token_to_give < 1: reply_body = self.token_config[token][ "no_token_left_for_today"] elif c_comment["parent_author"] == c_comment["author"]: reply_body = "You cannot sent token to yourself." elif float(symbol["balance"]) < amount: reply_body = self.token_config[token]["no_token_left_body"] else: if "{}" in self.token_config[token]["sucess_reply_body"]: reply_body = (self.token_config[token] ["sucess_reply_body"]).format( c_comment["parent_author"]) else: reply_body = self.token_config[token][ "sucess_reply_body"] if "{}" in self.token_config[token]["token_memo"]: token_memo = ( self.token_config[token]["token_memo"]).format( c_comment["author"]) else: token_memo = self.token_config[token]["token_memo"] sendwallet = Wallet( self.token_config[token]["token_account"], steem_instance=self.stm) try: logger.info( "Sending %.2f %s to %s" % (amount, self.token_config[token]["symbol"], c_comment["parent_author"])) sendwallet.transfer(c_comment["parent_author"], amount, self.token_config[token]["symbol"], token_memo) if "accounts" in db_data: accounts = db_data["accounts"] else: accounts = {} if c_comment["author"] not in accounts: accounts[c_comment["author"]] = {} accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } elif token not in accounts[c_comment["author"]]: accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: if accounts[c_comment["author"]][token][ "last_date"] < date.today(): accounts[c_comment["author"]][token] = { "last_date": date.today(), "n_comments": 1, "amount": amount } else: accounts[c_comment["author"]][token][ "n_comments"] += 1 accounts[c_comment["author"]][token][ "amount"] += amount store_data(self.data_file, "accounts", accounts) logger.info( "%s - %s" % (c_comment["author"], str(accounts[c_comment["author"]][token]))) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not send %s token" % self.token_config[token]["symbol"]) continue reply_identifier = construct_authorperm( c_comment["parent_author"], c_comment["parent_permlink"]) if self.config["no_broadcast"]: logger.info("%s" % reply_body) else: try: self.stm.post( "", reply_body, author=self.token_config[token]["token_account"], reply_identifier=reply_identifier) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn( "%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not reply to post") continue if self.token_config[token]["usage_upvote_percentage"] > 0: try: c_comment.upvote(self.token_config[token] ["usage_upvote_percentage"], voter=self.token_config[token] ["token_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split( exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") time.sleep(4) return last_block_num
def run(self, start_block): self.stm.wallet.unlock(self.config["wallet_password"]) self.blockchain = Blockchain(mode='head', steem_instance=self.stm) stop_block = self.blockchain.get_current_block_num() if start_block is not None: last_block_num = start_block - 1 self.log_data["start_block_num"] = start_block for op in self.blockchain.stream(start=start_block, stop=stop_block, opNames=["comment"], max_batch_size=50): self.log_data = print_block_log(self.log_data, op, self.config["print_log_at_block"]) last_block_num = op["block_num"] if op["type"] == "comment": token = None for key in self.token_config: if op["body"].find(self.token_config[key]["comment_command"]) >= 0: token = key if token is None: continue if op["author"] == self.token_config[token]["scot_account"]: continue try: c_comment = Comment(op, steem_instance=self.stm) c_comment.refresh() except: logger.warn("Could not read %s/%s" % (op["author"], op["permlink"])) continue if c_comment.is_main_post(): continue if abs((c_comment["created"] - op['timestamp']).total_seconds()) > 9.0: logger.warn("Skip %s, as edited" % c_comment["authorperm"]) continue already_replied = False for r in c_comment.get_all_replies(): if r["author"] == self.token_config[token]["scot_account"]: already_replied = True if already_replied: continue # Load scot token balance scot_wallet = Wallet(self.token_config[token]["scot_account"], steem_instance=self.stm) scot_token = scot_wallet.get_token(self.token_config[token]["scot_token"]) # parse amount when user_can_specify_amount is true amount = self.token_config[token]["maximum_amount"] if self.token_config[token]["user_can_specify_amount"]: start_index = c_comment["body"].find(self.token_config[token]["comment_command"]) stop_index = c_comment["body"][start_index:].find("\n") if stop_index >= 0: command = c_comment["body"][start_index + 1:start_index + stop_index] else: command = c_comment["body"][start_index + 1:] command_args = command.replace(' ', ' ').split(" ")[1:] if len(command_args) > 0: try: amount = float(command_args[0]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.info("Could not parse amount") if not self.config["no_broadcast"] and self.stm.wallet.locked(): self.stm.wallet.unlock(self.config["wallet_password"]) self.log_data["new_commands"] += 1 wallet = Wallet(c_comment["author"], steem_instance=self.stm) token_in_wallet = wallet.get_token(self.token_config[token]["scot_token"]) if token_in_wallet is None or float(token_in_wallet["balance"]) < self.token_config[token]["min_staked_token"]: reply_body = self.token_config[token]["fail_reply_body"] elif c_comment["parent_author"] == c_comment["author"]: reply_body = "You cannot sent token to yourself." elif float(scot_token["balance"]) < amount: reply_body = self.token_config[token]["no_token_left_body"] else: if "%s" in self.token_config[token]["sucess_reply_body"]: reply_body = self.token_config[token]["sucess_reply_body"] % c_comment["parent_author"] else: reply_body = self.token_config[token]["sucess_reply_body"] if "%s" in self.token_config[token]["token_memo"]: token_memo = self.token_config[token]["token_memo"] % c_comment["author"] else: token_memo = self.token_config[token]["token_memo"] sendwallet = Wallet(self.token_config[token]["scot_account"], steem_instance=self.stm) try: logger.info("Sending %.2f %s to %s" % (amount, self.token_config[token]["scot_token"], c_comment["parent_author"])) sendwallet.transfer(c_comment["parent_author"], amount, self.token_config[token]["scot_token"], token_memo) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not send %s token" % self.token_config[token]["scot_token"]) continue reply_identifier = construct_authorperm(c_comment["parent_author"], c_comment["parent_permlink"]) if self.config["no_broadcast"]: logger.info("%s" % reply_body) else: try: self.stm.post("", reply_body, author=self.token_config[token]["scot_account"], reply_identifier=reply_identifier) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not reply to post") continue if self.token_config[token]["usage_upvote_percentage"] > 0: try: c_comment.upvote(self.token_config[token]["usage_upvote_percentage"], voter=self.token_config[token]["scot_account"]) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.warn("%s - %s - %s" % (str(exc_type), str(fname), str(exc_tb.tb_lineno))) logger.warn("Could not upvote comment") time.sleep(4) return last_block_num
def upvote(s, permlink, voter): acc = Comment(permlink, steem_instance=s) votes = acc.upvote(voter=voter)