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()
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

View file

@ -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