1
0
Fork 0

Merge pull request #9 from flifloo/reminders

Reminders
This commit is contained in:
Ethanell 2020-05-28 17:51:57 +02:00 committed by GitHub
commit 3c6e394ccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -1,5 +1,5 @@
from db import Base from db import Base
from sqlalchemy import Column, Integer, String, BigInteger, Date from sqlalchemy import Column, Integer, String, BigInteger, DateTime
from datetime import datetime from datetime import datetime
@ -9,11 +9,13 @@ class Task(Base):
message = Column(String, nullable=False) message = Column(String, nullable=False)
user = Column(BigInteger, nullable=False) user = Column(BigInteger, nullable=False)
channel = Column(BigInteger, nullable=False) channel = Column(BigInteger, nullable=False)
date = Column(Date, nullable=False) date = Column(DateTime, nullable=False)
creation_date = Column(Date, 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.message = message
self.user = user self.user = user
self.channel = channel self.channel = channel
self.date = date self.date = date
if creation_date:
self.creation_date = creation_date

View file

@ -49,7 +49,7 @@ class Reminders(commands.Cog):
time = time_pars(time) time = time_pars(time)
now = datetime.now() now = datetime.now()
s = db.Session() 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.commit()
s.close() s.close()
@ -99,7 +99,7 @@ class Reminders(commands.Cog):
embed = Embed(title="You have a reminder !") embed = Embed(title="You have a reminder !")
user = self.bot.get_user(task.user) user = self.bot.get_user(task.user)
embed.set_author(name=f"{user.name}#{user.discriminator}", icon_url=user.avatar_url) 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="") await (await self.bot.get_channel(task.channel).send(f"{user.mention}", embed=embed)).edit(content="")
@commands.Cog.listener() @commands.Cog.listener()
@ -115,6 +115,9 @@ class Reminders(commands.Cog):
await ctx.send("An error occurred !") await ctx.send("An error occurred !")
raise error raise error
def cog_unload(self):
self.reminders_loop.stop()
def setup(bot): def setup(bot):
logger.info(f"Loading...") logger.info(f"Loading...")
@ -131,7 +134,6 @@ def setup(bot):
def teardown(bot): def teardown(bot):
logger.info(f"Unloading...") logger.info(f"Unloading...")
try: try:
bot.get_cog("Reminders").reminders_loop.stop()
bot.remove_cog("Reminders") bot.remove_cog("Reminders")
except Exception as e: except Exception as e:
logger.error(f"Error unloading: {e}") logger.error(f"Error unloading: {e}")