From b502d08256fc1957726c256f00cc3c00d8f5c51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 11 Sep 2020 13:27:38 +0200 Subject: [PATCH] Implement tweet filtering --- bot.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index e78df4f..ae1a3ad 100644 --- a/bot.py +++ b/bot.py @@ -64,6 +64,7 @@ class Bot(discord.Client): super().__init__() async def process_event(self, service, data): + await self.wait_until_ready() action = getattr(self, 'process_{0}_event'.format(service)) await action(data) @@ -124,10 +125,31 @@ class Bot(discord.Client): api = self.get_twitter_api(user_id) if not api: return - await self.wait_until_ready() channel = self.get_channel(twitter_channel_id) if channel: for tweet in tweets: + if tweet.get('user', {}).get('id_str') == user_id: + retweeted = tweet.get('retweeted_status') + if retweeted: + tweet = retweeted + else: + quoted = tweet.get('quoted_status') + if quoted: + tweet = quoted + else: + reply_to = tweet.get('in_reply_to_status_id_str') + if reply_to: + original = api.get_status(reply_to) + if original: + await channel.send(embed=self.make_twitter_embed(original)) + elif tweet.get('user', {}).get('verified'): + reply_to = tweet.get('in_reply_to_status_id_str') + if reply_to: + original = api.get_status(reply_to) + if original: + await channel.send(embed=self.make_twitter_embed(original)) + else: + continue await channel.send(embed=self.make_twitter_embed(tweet)) def format_remainder(self, seconds):