nsfw.py 文件源码

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

项目:jose 作者: lnmds 项目源码 文件源码
def booru(self, ctx, booru, tags):
        if '[jose:no_nsfw]' in ctx.channel.topic:
            return
        # taxxx
        await self.jcoin.pricing(ctx, self.prices['API'])

        try:
            # grab posts
            posts = await booru.get_posts(ctx.bot, tags)

            if not posts:
                return await ctx.send('Found nothing.')

            # grab random post
            post = random.choice(posts)
            post_id = post.get('id')
            post_author = booru.get_author(post)

            log.info('%d posts from %s, chose %d', len(posts),
                     booru.__name__, post_id)

            tags = (post['tags'].replace('_', '\\_'))[:500]

            # add stuffs
            embed = discord.Embed(title=f'Posted by {post_author}')
            embed.set_image(url=post['file_url'])
            embed.add_field(name='Tags', value=tags)
            embed.add_field(name='URL', value=booru.url_post.format(post_id))

            # hypnohub doesn't have this
            if 'fav_count' in post and 'score' in post:
                embed.add_field(name='Votes/Favorites',
                                value=f"{post['score']} votes, {post['fav_count']} favorites")

            # send
            await ctx.send(embed=embed)
        except BooruError as err:
            raise self.SayException(f'Error while fetching posts: `{err!r}`')
        except aiohttp.ClientError as err:
            log.exception('client error')
            raise self.SayException(f'Something went wrong. Sorry! `{err!r}`')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号