From 48c84ef99b837f722218d2e80cfdecbb4510dfbc Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Fri, 7 Oct 2016 15:50:55 +0100 Subject: [PATCH] More scheduling fixes. --- bot.py | 5 +++-- db.py | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index accff22..115adec 100755 --- a/bot.py +++ b/bot.py @@ -1246,7 +1246,7 @@ def announce(announcement): db.set_announcement(client, announcement['id'], digest = announcement['digest'] if 'digest' in announcement else None, last_spoke = scheduled) return # Give the announcement now but set the original schedule. - last_spoke = start + announcement['interval'] + last_spoke = start + (intervals + 1) * announcement['interval'] log.info('Forcing last_spoke for announcement {} to {} in line with schedule'.format(announcement['id'], iso8601(last_spoke))) channel = None @@ -1279,11 +1279,12 @@ def announce(announcement): else: text = '<@{}>\n{}'.format(mention, text) + digest = announcement['digest'] + # Always post private messages. Try not to spam public announcements. if not private: cutoff = datetime.datetime.utcnow() - datetime.timedelta(0, announcement['interval']) logs = yield from client.logs_from(channel, after = cutoff) - digest = announcement['digest'] for message in logs: raw = re.sub(r'^( ? or end_date=start_date) and (asap=1 or last_spoke is null or last_spoke < ? - interval) and (last_spoke is null or interval > 0) and bot_id=?', [now, now, now, client.user.id]) + cursor = self.query("select id, server_id, member_id, channel_id, voice_id, sound, mention, start_date, end_date, interval, probability, last_spoke, asap, message, digest from announcements where (start_date is null or start_date <= ?) and (end_date is null or end_date > ? or end_date=start_date) and (asap='true' or last_spoke is null or last_spoke < ? - interval) and (last_spoke is null or interval > 0) and bot_id=?", [now, now, now, client.user.id]) for row in cursor.fetchall(): yield dict(row) self.close_db() - def set_announcement(self, client, id, digest = None, last_spoke = None, asap = 'asap'): - if last_spoke is None: + def set_announcement(self, client, id, digest = None, last_spoke = None, asap = None): + if last_spoke is None and asap is None: last_spoke = self.now() + if asap is None: + asap = 'asap' cursor = self.query('update announcements set last_spoke=?, asap=?, digest=? where id=?', [last_spoke, asap, digest, id]) self.dbh.commit() self.close_db() -- 2.7.4