Fixed some bugs
This commit is contained in:
19
bot/utils.py
19
bot/utils.py
@@ -23,14 +23,25 @@ def date_from_iso(date: str) -> datetime:
|
||||
|
||||
|
||||
def time_delta(text: str) -> timedelta:
|
||||
match = re.match(r'(\d+)(s|m|h|mon|w|y)', text)
|
||||
match = re.match(r'(\d+)(s|m|h|d|mon|w|y)', text)
|
||||
if match:
|
||||
num, unit = match.groups()
|
||||
num = int(num)
|
||||
unit = TIME_UNITS[unit]
|
||||
if unit == 'mon':
|
||||
if unit == 's':
|
||||
unit = 'seconds'
|
||||
elif unit == 'm':
|
||||
unit = 'minutes'
|
||||
elif unit == 'h':
|
||||
unit = 'hours'
|
||||
elif unit == 'd':
|
||||
unit = 'days'
|
||||
elif unit == 'w':
|
||||
unit = 'weeks'
|
||||
elif unit == 'mon':
|
||||
unit = 'weeks'
|
||||
num *= 4
|
||||
elif unit == 'y':
|
||||
unit = 'weeks'
|
||||
num *= 52
|
||||
return timedelta(**{unit: num})
|
||||
|
||||
@@ -52,4 +63,4 @@ def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
||||
|
||||
|
||||
def re_generator(low: int = 5, high: int = 20) -> str:
|
||||
return 'R{}'.format(''.join('E' for _ in range(random.randint(low, high))))
|
||||
return 'R{}'.format('E' * random.randint(low, high))
|
||||
|
||||
Reference in New Issue
Block a user