added regex magic so twitter & masto don't mention themselves by accident

This commit is contained in:
b3yond 2018-01-18 14:48:53 +01:00
parent ee61ba19e6
commit 10de40549c
2 changed files with 5 additions and 2 deletions

View file

@ -77,9 +77,10 @@ class RetootBot(object):
self.save_last() self.save_last()
os.rename('seen_toots.pickle.part', 'seen_toots.pickle') os.rename('seen_toots.pickle.part', 'seen_toots.pickle')
# add mention to mentions # 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'], mentions.append(report.Report(status['account']['acct'],
"mastodon", "mastodon",
re.sub(r'<[^>]*>', '', status['status']['content']), re.sub(r'<[^>]*>', '', text),
status['status']['id'], status['status']['id'],
status['status']['created_at'])) status['status']['created_at']))
return mentions return mentions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import tweepy import tweepy
import re
import requests import requests
import pytoml as toml import pytoml as toml
import trigger import trigger
@ -111,9 +112,10 @@ class RetweetBot(object):
else: else:
mentions = self.api.mentions_timeline(since_id=self.last_mention) mentions = self.api.mentions_timeline(since_id=self.last_mention)
for status in mentions: 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, reports.append(report.Report(status.author.screen_name,
"twitter", "twitter",
status.text, text,
status.id, status.id,
status.created_at)) status.created_at))
return reports return reports