diff --git a/extensions/__init__.py b/extensions/__init__.py index 4e0e6ec..0a87adf 100644 --- a/extensions/__init__.py +++ b/extensions/__init__.py @@ -5,3 +5,4 @@ bot.load_extension("extensions.speak") bot.load_extension("extensions.extension") bot.load_extension("extensions.purge") bot.load_extension("extensions.poll") +bot.load_extension("extensions.reminders") diff --git a/extensions/reminders.py b/extensions/reminders.py new file mode 100644 index 0000000..11fa4e6 --- /dev/null +++ b/extensions/reminders.py @@ -0,0 +1,133 @@ +import re +from datetime import datetime, timedelta + +from discord.ext import commands +from discord import Embed +from discord.ext.commands import CommandNotFound, BadArgument, MissingRequiredArgument +from discord.ext import tasks + +from bot_bde.logger import logger + + +extension_name = "reminders" +logger = logger.getChild(extension_name) + + +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() + + +class Reminders(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + self.tasks = [] + + @commands.group("reminder", pass_context=True) + async def reminder(self, ctx: commands.Context): + if ctx.invoked_subcommand is None: + raise CommandNotFound() + + @reminder.group("help", pass_context=True) + async def reminder_help(self, ctx: commands.Context): + embed = Embed(title="Reminder help") + embed.add_field(name="speak add