add bandaid to fix reminder memory issue

This commit is contained in:
iou1name 2024-06-20 14:46:13 -04:00
parent 7413860601
commit 736a98e274
2 changed files with 17 additions and 0 deletions

View File

@ -100,6 +100,17 @@ def remind_recur(bot, trigger):
bot.reply(msg)
@module.require_admin
@module.commands('clear_dup_reminders')
def remind_recur(bot, trigger):
"""
Clear out duplicate reminders from Fulvia's memory.
This is only a temporary fix to the memory issue.
"""
bot.scheduler.tasks = list(dict.fromkeys(bot.scheduler.tasks))
bot.scheduler.dump_database()
def announce_reminder(bot, sched_time, channel, remindee, reminder, delta=None):
"""Announce the reminder."""
bot.msg(channel, reminder)

View File

@ -71,3 +71,9 @@ class Scheduler:
for task in tasks:
t = tuple(pickle.loads(i) for i in task)
self.tasks.append(t)
def dump_database(self):
self.bot.db.execute("DELETE FROM scheduled_task")
for task in self.tasks:
t = tuple(pickle.dumps(i) for i in task)
self.bot.db.execute("INSERT INTO scheduled_task VALUES (?,?,?)", t)