1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Administrator-py/administrator/utils.py
2020-08-02 19:41:38 +02:00

15 lines
567 B
Python

import re
from datetime import timedelta
from discord.ext.commands import BadArgument
def time_pars(s: str) -> timedelta:
match = re.fullmatch(r"(?:([0-9]+)W)*(?:([0-9]+)D)*(?:([0-9]+)H)*(?:([0-9]+)M)*(?:([0-9]+)S)*",
s.upper().replace(" ", "").strip())
if match:
w, d, h, m, s = match.groups()
if any([w, d, h, m, s]):
w, d, h, m, s = [i if i else 0 for i in [w, d, h, m, s]]
return timedelta(weeks=int(w), days=int(d), hours=int(h), minutes=int(m), seconds=int(s))
raise BadArgument()