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
评论列表
文章目录