converters.py 文件源码

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

项目:dogbot 作者: slice 项目源码 文件源码
def convert(self, ctx, argument):
        # Scan attached images.
        if argument == 'attached':
            for attachment in ctx.message.attachments:
                if attachment.height:
                    return attachment.proxy_url

        # Scan channel for any recent images.
        if argument == 'recent':
            result = await _get_recent_image(ctx.channel)
            if not result:
                raise commands.BadArgument('No recent image was found in this channel.')
            return result

        try:
            # Resolve avatar.
            user = await UserConverter().convert(ctx, argument)
            return user.avatar_url_as(format='png')
        except commands.BadArgument:
            pass

        # ok image
        if any(argument.startswith(safe_url) for safe_url in SAFE_IMAGE_HOSTS):
            return argument

        error = ("Invalid image URL or user. To use a recent image from this channel, specify `recent`. You can also "
                 "attach any image and specify `attached` to use that image.")
        raise commands.BadArgument(error)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号