twitter.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号