From 10de40549c19b11735b94e5c1e41e98ec94e3f2f Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 18 Jan 2018 14:48:53 +0100 Subject: [PATCH] added regex magic so twitter & masto don't mention themselves by accident --- retootbot.py | 3 ++- retweetbot.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/retootbot.py b/retootbot.py index c39f8cb..8b4ffdc 100755 --- a/retootbot.py +++ b/retootbot.py @@ -77,9 +77,10 @@ class RetootBot(object): self.save_last() os.rename('seen_toots.pickle.part', 'seen_toots.pickle') # add mention to mentions + text = re.sub("(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", status['status']['content']) mentions.append(report.Report(status['account']['acct'], "mastodon", - re.sub(r'<[^>]*>', '', status['status']['content']), + re.sub(r'<[^>]*>', '', text), status['status']['id'], status['status']['created_at'])) return mentions diff --git a/retweetbot.py b/retweetbot.py index a585633..b120a4f 100755 --- a/retweetbot.py +++ b/retweetbot.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import tweepy +import re import requests import pytoml as toml import trigger @@ -111,9 +112,10 @@ class RetweetBot(object): else: mentions = self.api.mentions_timeline(since_id=self.last_mention) for status in mentions: + text = re.sub("(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", status.text) reports.append(report.Report(status.author.screen_name, "twitter", - status.text, + text, status.id, status.created_at)) return reports