diff --git a/db/Task.py b/db/Task.py index dae228c..4c06d0d 100644 --- a/db/Task.py +++ b/db/Task.py @@ -1,5 +1,5 @@ from db import Base -from sqlalchemy import Column, Integer, String, BigInteger, Date +from sqlalchemy import Column, Integer, String, BigInteger, DateTime from datetime import datetime @@ -9,11 +9,13 @@ class Task(Base): message = Column(String, nullable=False) user = Column(BigInteger, nullable=False) channel = Column(BigInteger, nullable=False) - date = Column(Date, nullable=False) - creation_date = Column(Date, default=datetime.now()) + date = Column(DateTime, nullable=False) + creation_date = Column(DateTime, nullable=False, default=datetime.now()) - def __init__(self, message: str, user: int, channel: int, date: datetime): + def __init__(self, message: str, user: int, channel: int, date: datetime, creation_date: datetime = None): self.message = message self.user = user self.channel = channel self.date = date + if creation_date: + self.creation_date = creation_date diff --git a/extensions/reminders.py b/extensions/reminders.py index f35c514..a3f4d28 100644 --- a/extensions/reminders.py +++ b/extensions/reminders.py @@ -49,7 +49,7 @@ class Reminders(commands.Cog): time = time_pars(time) now = datetime.now() s = db.Session() - s.add(db.Task(message, ctx.author.id, ctx.channel.id, now + time)) + s.add(db.Task(message, ctx.author.id, ctx.channel.id, now + time, ctx.message.created_at)) s.commit() s.close() @@ -99,7 +99,7 @@ class Reminders(commands.Cog): embed = Embed(title="You have a reminder !") user = self.bot.get_user(task.user) embed.set_author(name=f"{user.name}#{user.discriminator}", icon_url=user.avatar_url) - embed.add_field(name=str(task.date), value=task.message) + embed.add_field(name=str(task.creation_date), value=task.message) await (await self.bot.get_channel(task.channel).send(f"{user.mention}", embed=embed)).edit(content="") @commands.Cog.listener() @@ -115,6 +115,9 @@ class Reminders(commands.Cog): await ctx.send("An error occurred !") raise error + def cog_unload(self): + self.reminders_loop.stop() + def setup(bot): logger.info(f"Loading...") @@ -131,7 +134,6 @@ def setup(bot): def teardown(bot): logger.info(f"Unloading...") try: - bot.get_cog("Reminders").reminders_loop.stop() bot.remove_cog("Reminders") except Exception as e: logger.error(f"Error unloading: {e}")