time.py 文件源码

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

项目:dogbot 作者: slice 项目源码 文件源码
def convert(self, ctx: DogbotContext, argument: str) -> str:
        cog: 'Time' = ctx.command.instance

        # resolve another user's timezone
        try:
            member = await MemberConverter().convert(ctx, argument)
            timezone = await cog.get_timezone_for(member)
            if timezone:
                return timezone
        except BadArgument:
            pass

        # hippo checking
        blacklisted = list('`\\<>@')
        if any(character in argument for character in blacklisted) or len(argument) > 30:
            raise BadArgument("That doesn't look like a timezone.")

        # actually check if it's a valid timezone with arrow's parser
        try:
            arrow.utcnow().to(argument)
        except arrow.parser.ParserError:
            raise BadArgument('Invalid timezone.')

        return argument
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号