def twitter_add(self, ctx, handle : str):
'''
Add a Twitter handle to a text channel
A delay of up to 2 min. is possible due to Twitter rate limits
'''
if handle in self.feeds_info["channels"].get(ctx.message.channel.id, {}).get("handles", []):
await self.bot.embed_reply(":no_entry: This text channel is already following that Twitter handle")
return
message, embed = await self.bot.embed_reply(":hourglass: Please wait")
try:
await self.stream_listener.add_feed(ctx.message.channel, handle)
except tweepy.error.TweepError as e:
embed.description = ":no_entry: Error: {}".format(e)
await self.bot.edit_message(message, embed = embed)
return
if ctx.message.channel.id in self.feeds_info["channels"]:
self.feeds_info["channels"][ctx.message.channel.id]["handles"].append(handle)
else:
self.feeds_info["channels"][ctx.message.channel.id] = {"name" : ctx.message.channel.name, "handles" : [handle]}
with open("data/twitter_feeds.json", 'w') as feeds_file:
json.dump(self.feeds_info, feeds_file, indent = 4)
embed.description = "Added the Twitter handle, [`{0}`](https://twitter.com/{0}), to this text channel".format(handle)
await self.bot.edit_message(message, embed = embed)
评论列表
文章目录