diff options
-rwxr-xr-x | bot.py | 7 | ||||
-rw-r--r-- | cogs/twitter.py | 37 |
2 files changed, 41 insertions, 3 deletions
@@ -42,13 +42,11 @@ class BedrockBot(commands.Bot): with open('custom_commands.json', 'r') as f: self.custom_commands = json.load(f) - for extension in extensions: - self.load_extension(extension) - with open('config.json', 'r') as f: self.config = json.load(f) config = self.config + async def on_ready(self): self.uptime = datetime.datetime.utcnow() @@ -67,6 +65,9 @@ class BedrockBot(commands.Bot): except json.decoder.JSONDecodeError: self.video_blacklist = [] + for extension in extensions: + self.load_extension(extension) + self.logger.warning(f'Online: {self.user} (ID: {self.user.id})') async def on_message(self, message): diff --git a/cogs/twitter.py b/cogs/twitter.py new file mode 100644 index 0000000..d321ca3 --- /dev/null +++ b/cogs/twitter.py @@ -0,0 +1,37 @@ +from discord.ext import commands, tasks +import discord +import tweepy + +class MyStreamListener(tweepy.StreamListener): + def on_error(self, status_code): + if status_code == 420: + #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) + + +class Twitter(commands.Cog): + def __init__(self, bot): + self.bot = bot + + 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) + +def setup(bot): + bot.add_cog(Twitter(bot))
\ No newline at end of file |