From 0e1cd216818f0408511e8ddea0ce30c7f1d055ac Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 28 May 2020 17:27:35 +0200 Subject: [PATCH 1/3] Fix reminder loop close --- extensions/reminders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/reminders.py b/extensions/reminders.py index f35c514..4c87439 100644 --- a/extensions/reminders.py +++ b/extensions/reminders.py @@ -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}") From 5e3610818620eaddb0b1c4af1d8dd8438156770f Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 28 May 2020 17:34:09 +0200 Subject: [PATCH 2/3] Fix Task DB object date and creation_date type --- db/Task.py | 6 +++--- extensions/reminders.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/Task.py b/db/Task.py index dae228c..b39c7df 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,8 +9,8 @@ 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, default=datetime.now()) def __init__(self, message: str, user: int, channel: int, date: datetime): self.message = message diff --git a/extensions/reminders.py b/extensions/reminders.py index 4c87439..d55e58f 100644 --- a/extensions/reminders.py +++ b/extensions/reminders.py @@ -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() From e51a7509c6c43c29b99de499a293489bb64b7bb0 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 28 May 2020 17:44:22 +0200 Subject: [PATCH 3/3] Fix Task creation date --- db/Task.py | 6 ++++-- extensions/reminders.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/db/Task.py b/db/Task.py index b39c7df..4c06d0d 100644 --- a/db/Task.py +++ b/db/Task.py @@ -10,10 +10,12 @@ class Task(Base): user = Column(BigInteger, nullable=False) channel = Column(BigInteger, nullable=False) date = Column(DateTime, nullable=False) - creation_date = Column(DateTime, default=datetime.now()) + 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 d55e58f..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()