Fixed timer plugin, now checks every hour (with aiocron) for timers in the next hour and sets them
This commit is contained in:
45
bot/utils.py
45
bot/utils.py
@@ -1,51 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import random
|
||||
from typing import Tuple
|
||||
from pprint import pprint
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
TIME_UNITS = {
|
||||
's': 'seconds',
|
||||
'm': 'minutes',
|
||||
'h': 'hours',
|
||||
'd': 'days',
|
||||
'w': 'weeks',
|
||||
'mon': 'months',
|
||||
'y': 'years',
|
||||
}
|
||||
from datetime import datetime
|
||||
|
||||
pp = pprint
|
||||
|
||||
|
||||
def re_generator(low: int = 5, high: int = 20) -> str:
|
||||
return 'R{}'.format('E' * random.randint(low, high))
|
||||
|
||||
|
||||
def date_from_iso(date: str) -> datetime:
|
||||
return datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
|
||||
|
||||
def time_delta(text: str) -> timedelta:
|
||||
match = re.match(r'(\d+)(s|m|h|d|mon|w|y)', text)
|
||||
if match:
|
||||
num, unit = match.groups()
|
||||
num = int(num)
|
||||
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})
|
||||
|
||||
|
||||
def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
||||
try:
|
||||
val = int(val)
|
||||
@@ -60,7 +29,3 @@ def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
||||
return val, order
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def re_generator(low: int = 5, high: int = 20) -> str:
|
||||
return 'R{}'.format('E' * random.randint(low, high))
|
||||
|
||||
Reference in New Issue
Block a user