def __init__(self, argument):
compiled = re.compile(r"(?:(?P<hours>\d+)h)?(?:(?P<minutes>\d+)m)?(?:(?P<seconds>\d+)s)?")
self.original = argument
try:
self.seconds = int(argument)
except ValueError as e:
match = compiled.match(argument)
if match is None or not match.group(0):
raise commands.BadArgument('Failed to parse time.') from e
self.seconds = 0
hours = match.group('hours')
if hours is not None:
self.seconds += int(hours) * 3600
minutes = match.group('minutes')
if minutes is not None:
self.seconds += int(minutes) * 60
seconds = match.group('seconds')
if seconds is not None:
self.seconds += int(seconds)
if self.seconds < 0:
raise commands.BadArgument('I don\'t do negative time.')
if self.seconds > 604800: # 7 days
raise commands.BadArgument('That\'s a bit too far in the future for me.')
评论列表
文章目录