@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']
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'])))
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:
# 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