diff options
-rwxr-xr-x[-rw-r--r--] | cogs/twitter.py | 38 | ||||
-rwxr-xr-x | custom_commands.json | 2 |
2 files changed, 24 insertions, 16 deletions
diff --git a/cogs/twitter.py b/cogs/twitter.py index d321ca3..668169c 100644..100755 --- a/cogs/twitter.py +++ b/cogs/twitter.py @@ -1,37 +1,45 @@ +import json from discord.ext import commands, tasks import discord import tweepy +import asyncio -class MyStreamListener(tweepy.StreamListener): +class StreamListener(tweepy.StreamListener): def on_error(self, status_code): if status_code == 420: + print("Rate limit reached. ") #returning False in on_error disconnects the stream return False - def on_status(self, status): - if hasattr(status, "retweeted_status"): # Check if Retweet - try: - print(status.retweeted_status.extended_tweet["full_text"]) - except AttributeError: - print(status.retweeted_status.text) - else: - try: - print(status.extended_tweet["full_text"]) - except AttributeError: - print(status.text) + def on_data(self, data): + global channelTweet + data = json.loads(data) + tweetUser = data['user']['screen_name'] + tweetID = data['id_str'] + tweetLink = f'https://twitter.com/{tweetUser}/status/{tweetID}' + loop = asyncio.get_event_loop() + try: + loop.run_until_complete(channelTweet.send(tweetLink)) + finally: + loop.run_until_complete(loop.shutdown_asyncgens()) + loop.close() + #print(json.dumps(data, indent='\t')) class Twitter(commands.Cog): def __init__(self, bot): self.bot = bot + global channelTweet + channelTweet = self.bot.get_channel(737713121447378965) + auth = tweepy.OAuthHandler(self.bot.config['twitter']['consumer_key'], self.bot.config['twitter']['consumer_secret']) auth.set_access_token(self.bot.config['twitter']['access_token'], self.bot.config['twitter']['access_token_secret']) api = tweepy.API(auth) - myStreamListener = MyStreamListener() - self.myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener) - self.myStream.filter(follow=['1287799985040437254'], is_async=True) + myStreamListener = StreamListener() + stream = tweepy.Stream(auth = api.auth, listener=myStreamListener) + stream.filter(follow=['1287799985040437254'], is_async=True) def setup(bot): bot.add_cog(Twitter(bot))
\ No newline at end of file diff --git a/custom_commands.json b/custom_commands.json index 9606473..f4143fc 100755 --- a/custom_commands.json +++ b/custom_commands.json @@ -30,7 +30,7 @@ "!GlasgowRangers": "You Let Your Club Die!", "!e\ud83c\udd71\ufe0fic": "HEY GUYS ITS SHIGAME45", "!testy": "test", - "!toxicitypass": "```TOXICITY PASS\n\nTHE HOLDER OF THIS PASS HAS PERMISSION FROM THE HEAVENS ABOVE TO DO AND SAY WHATEVER THE HELL THEY WANT\nTHEY ARE ALLOWED TO BE AS TOXIC AS THEY WILL WITHOUT REPERCUSSIONS\n\nPASS OWNER: Duck W aka Weexy aka Indy Kambeitz```", + "!toxicitypass": "```TOXICITY PASS\n\nTHE HOLDER OF THIS PASS HAS PERMISSION FROM THE HEAVENS ABOVE TO DO AND SAY WHATEVER THE HELL THEY WANT\nTHEY ARE ALLOWED TO BE AS TOXIC AS THEY WILL WITHOUT REPERCUSSIONS\n\nPASS OWNER: Duck W aka Weexy aka Indy Kambeitz\nPASS OWNER: Ex-Duck K aka Kai McCann aka Madelines long lost sibling```", "!welcome": "Welcome! <:mango:715738087627685908>", "!learntoread": "When two players are tied on the leaderboards **ONLY ONE FUCKER WILL BE VISIBLE**", "!mobiledupe": "1) place item to dupe in the crafting grid\n2) keep pressed until the green bar thing appears\nclick any \"Impossible\" craft (red ones)\n3)press the item to dupe (that is in your hotbar now -> it should have moved there since you pressed the impossible craft)\n4)your item should be duped", |