From: CMDR furrycat Date: Fri, 11 Nov 2016 10:08:09 +0000 (+0000) Subject: Handle null interval. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=b79b3da5f42a5f2e00f7b28643f8ea42ee9734d7;p=furrycat%2Fcatbot.git Handle null interval. --- diff --git a/plugin/announcements/announcements.py b/plugin/announcements/announcements.py index 5690c1f..f7c76bf 100644 --- a/plugin/announcements/announcements.py +++ b/plugin/announcements/announcements.py @@ -746,23 +746,26 @@ class Announcements(DBConnection): @asyncio.coroutine def announce(self, announcement): update = {} + interval = announcement['interval'] + if interval is None: + interval = 0 # Adhere to schedule. if bot.parse_boolean(announcement['asap']): log.info('Announcement {} was requested ASAP'.format(announcement['id'])) announcement['probability'] = 1.0 update['asap'] = 'false' - elif announcement['interval']: + elif interval: if announcement['start_date'] or announcement['last_spoke']: now = int(time.time()) if announcement['start_date']: start = announcement['start_date'] else: start = announcement['last_spoke'] - intervals = math.floor((now - start) / announcement['interval']) + intervals = math.floor((now - start) / interval) if intervals: # We missed a schedule. - scheduled = start + intervals * announcement['interval'] - if now - scheduled > max(60, announcement['interval'] / 2): + scheduled = start + intervals * interval + if now - scheduled > max(60, interval / 2): log.info('Announcement {} should have been given at {}'.format(announcement['id'], bot.iso8601(scheduled))) if 'digest' in announcement: update['digest'] = announcement['digest'] @@ -770,7 +773,7 @@ class Announcements(DBConnection): self.update_announcement(client, announcement['id'], **update) return # Give the announcement now but set the original schedule. - last_spoke = start + (intervals + 1) * announcement['interval'] + last_spoke = start + (intervals + 1) * interval if last_spoke < now: update['last_spoke'] = last_spoke log.info('Forcing last_spoke for announcement {} to {} in line with schedule'.format(announcement['id'], bot.iso8601(update['last_spoke']))) @@ -787,7 +790,7 @@ class Announcements(DBConnection): channel = yield from client.start_private_message(member) break except: - pass + log.exception('announce') else: channel = client.get_channel(channel_id) if channel is None: @@ -818,7 +821,7 @@ class Announcements(DBConnection): # Always post private messages. Try not to spam public announcements. if not private and not bot.parse_boolean(announcement['asap']): - cutoff = datetime.datetime.utcnow() - datetime.timedelta(0, announcement['interval']) + cutoff = datetime.datetime.utcnow() - datetime.timedelta(0, interval) result = yield from client.logs_from(channel, after = cutoff) logs = list(result) # Don't spam the same message in a quiet channel even if it hasn't