def test_edit(self): bts = self.bts c = Comment(self.authorperm, steem_instance=bts) c.edit(c.body, replace=False) body = c.body + "test" tx = c.edit(body, replace=False) self.assertEqual((tx["operations"][0][0]), "comment") op = tx["operations"][0][1] self.assertIn(self.author, op["author"])
def test_edit(self): bts = self.bts bts.txbuffer.clear() c = Comment(self.authorperm, blockchain_instance=bts) c.edit(c.body, replace=False) body = c.body + "test" tx = c.edit(body, replace=False) self.assertEqual((tx["operations"][0][0]), "comment") op = tx["operations"][0][1] self.assertIn(self.author, op["author"])
def test_edit_replace(self): bts = self.bts c = Comment(self.authorperm, steem_instance=bts) body = c.body + "test" tx = c.edit(body, meta=c["json_metadata"], replace=True) self.assertEqual((tx["operations"][0][0]), "comment") op = tx["operations"][0][1] self.assertIn(self.author, op["author"]) self.assertEqual(body, op["body"])
def update_comment(post): """ Updates the comment left by the bot to reflect that the contribution was unvoted. """ body = (f"Hey @{post.author}, your contribution was unvoted because we " "found out that it did not follow the " "[Utopian rules](https://join.utopian.io/rules).\n\n Upvote this " "comment to help Utopian grow its power and help other Open " "Source contributions like this one.\n\n**Want to chat? Join us " "on [Discord](https://discord.gg/Pc8HG9x).**") # Iterate over replies until bot's comment is found for comment in get_replies(post): comment = Comment(comment) if comment.author == ACCOUNT and comment.is_comment(): try: logger.info(f"Updating comment {comment.authorperm}") comment.edit(body, replace=True) except Exception as error: logger.error(error) return
def send_summary_to_steem(parsed_cmd: dict, reply: Comment, root_comment: Comment, retry: int = 3): while retry > 0: if reply: bot: dict = reply.json_metadata.get(BOT_NAME, {}) bot.update(parsed_cmd) try: resp = reply.edit( body=build_bot_tr_message(parsed_cmd), meta={BOT_NAME: bot}, replace=True, ) except: logger.info("Can't submit a comment to %s", root_comment["url"]) logger.exception("Something went wrong.") retry -= 1 else: logger.info("Comment successfully updated at %s", root_comment["url"]) logger.debug(resp) break else: try: resp = STM.post( body=build_bot_tr_message(parsed_cmd), author=ACCOUNT, title="", reply_identifier=root_comment.authorperm, json_metadata={BOT_NAME: parsed_cmd}, ) except: logger.info("Can't submit a comment to %s", root_comment["url"]) logger.exception("Something went wrong.") retry -= 1 else: logger.info("Comment successfully sent to %s", root_comment["url"]) logger.debug(resp) break