diff --git a/db/Calendar.py b/db/Calendar.py index 1b93571..c3bc0da 100644 --- a/db/Calendar.py +++ b/db/Calendar.py @@ -29,6 +29,7 @@ class Calendar(Base): server = Column(BigInteger, nullable=False) calendar = Column(Text) calendar_update = Column(DateTime) + last_notify = Column(DateTime, nullable=False, default=datetime.now()) calendars_notify = relationship("CalendarNotify", backref="calendar", lazy="subquery") @@ -58,6 +59,7 @@ class Calendar(Base): return list(filter(lambda x: x.begin.date() >= first_date and x.end.date() <= last_date, events)) async def notify(self, bot: Bot, event: ics.Event): + self.last_notify = datetime.now() for n in self.calendars_notify: bot.loop.create_task(n.notify(bot, event)) diff --git a/extensions/calendar.py b/extensions/calendar.py index 788b286..7b968e7 100644 --- a/extensions/calendar.py +++ b/extensions/calendar.py @@ -242,7 +242,8 @@ class Calendar(commands.Cog): now = datetime.now().replace(tzinfo=timezone.utc).astimezone(tz=None) for c in s.query(db.Calendar).all(): for e in c.events(now.date(), now.date()): - if xor(e.begin >= now - timedelta(minutes=30), e.begin >= now - timedelta(minutes=10)): + if xor(c.last_notify < e.begin - timedelta(minutes=30) <= now, + c.last_notify < e.begin - timedelta(minutes=10) <= now): self.bot.loop.create_task(await c.notify(self.bot, e)) if s.is_modified(c): s.add(c)