Last active
          July 28, 2024 00:41 
        
      - 
      
- 
        Save notesbot/7f11900867a6940d1798026566b64f9a to your computer and use it in GitHub Desktop. 
Revisions
- 
        notesbot revised this gist Aug 22, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ def run_bot(): print('Working...') unread_conversations = reddit.subreddit(sub_name).modmail.conversations(state="highlighted") for conversation in unread_conversations: if (len(conversation.authors) > 1 and len(conversation.messages) > 1 and "find_last" in conversation.messages[-1].body_markdown): print(f'Match Found: {conversation.id}') username = conversation.user target_sub = conversation.owner 
- 
        notesbot created this gist Aug 22, 2022 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ def run_bot(): try: print('Working...') unread_conversations = reddit.subreddit(sub_name).modmail.conversations(state="highlighted") for conversation in unread_conversations: if (len(conversation.authors) >= 1 and len(conversation.messages) >= 1 and "find_last" in conversation.messages[-1].body_markdown): print(f'Match Found: {conversation.id}') username = conversation.user target_sub = conversation.owner api = PushshiftAPI() banned_user = api.search_comments(author=username, subreddit=target_sub, limit = 1) banned_user_posts = api.search_submissions(author=username, subreddit=target_sub, limit = 1) comments = [comment.d_ for comment in banned_user] submissions = [submission.d_ for submission in banned_user_posts] for comment in comments: if comment is not None: body_text = comment["body"] # Make a multi-line comment linkable via markdown. replace_comment = body_text[:300] sliced_comment = "".join(f"{i}" for i in replace_comment.split("\n\n")) link_text = comment["permalink"] comment_body = f"\n> [{sliced_comment}...]({link_text})\n\n" else: comment_body = 'None' for submission in submissions: if submission is not None: subm_text = submission["title"] subm_link = comment["permalink"] submission_title = f'\n> [{subm_text}]({subm_link})' else: submission_title = 'None' response = f"I found the last post and comment for the queried user.\n\nPost: \n\n{submission_title}\n\nLast comment: \n\n{comment_body}" conversation.reply(body=response, internal=True) conversation.unhighlight() except Exception as e: print("\t\n### ERROR - Modmail couldn't be checked.") traceback.print_exc()