text += ' tell @{}'.format(mention)
else:
text += ' tell <@{}>'.format(mention)
- text += ' in <#{}>'.format(announcement['channel_id'])
+ if announcement['channel_id'] != announcement['voice_id']:
+ text += ' in <#{}>'.format(announcement['channel_id'])
if announcement['voice_id']:
text += ' voice <#{}>'.format(announcement['voice_id'])
if announcement['sound']:
if announcement['probability'] < 1.0:
text += ' probability {}'.format(announcement['probability'])
- text += ':'
+ if announcement['message']:
+ text += ':'
lines.append(text)
- lines.append(announcement['message'])
+ if announcement['message']:
+ lines.append(announcement['message'])
yield from say(message.channel, '\n'.join(lines))
log.warning("Can't get channel for announcement {}".format(announcement['message']))
return
- # @everyone mention mangles the digest
- text = announcement['message']
- mention = announcement['mention']
- if mention:
- if mention in ['everyone', 'here']:
- text = '@{}\n{}'.format(mention, text)
- else:
- text = '<@{}>\n{}'.format(mention, text)
+ voice_only = announcement['voice_id'] == announcement['channel_id']
+ if not voice_only:
+ # @everyone mention mangles the digest
+ text = announcement['message']
+ mention = announcement['mention']
+ if mention:
+ if mention in ['everyone', 'here']:
+ text = '@{}\n{}'.format(mention, text)
+ else:
+ text = '<@{}>\n{}'.format(mention, text)
+
+ 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'^(<?@\S+\s)+', '', message.content).strip()
+ if hashlib.sha224(raw.encode('utf-8')).hexdigest() == digest:
+ log.debug('Saw previously posted announcement with digest {}'.format(digest))
+ return
- 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'^(<?@\S+\s)+', '', message.content).strip()
- if hashlib.sha224(raw.encode('utf-8')).hexdigest() == digest:
- log.debug('Saw previously posted announcement with digest {}'.format(digest))
- return
+ if announcement['voice_id']:
+ filename = announcement['sound']
+ if not filename:
+ filename = 'meow.wav'
try:
if dryrun:
- log.info('Dryrun: Not posting to {}: {}'.format(channel, text))
+ if voice_only:
+ log.info('Dryrun: Not playing announcement {} in {}'.format(filename, channel))
+ else:
+ log.info('Dryrun: Not posting to {}: {}'.format(channel, text))
else:
announce = random.random() <= announcement['probability']
if announce:
- log.info('Posting to {}: {}'.format(channel, text))
- message = yield from say(channel, text)
- digest = hashlib.sha224(message.content.encode('utf-8')).hexdigest()
+ if voice_only:
+ digest = None
+ else:
+ log.info('Posting to {}: {}'.format(channel, text))
+ message = yield from say(channel, text)
+ digest = hashlib.sha224(message.content.encode('utf-8')).hexdigest()
else:
log.info("Didn't bother with announcement {}".format(announcement['id']))
# Set last_spoke even if we chose not to announce.
if not announce:
return
if announcement['voice_id']:
- filename = announcement['sound']
- if not filename:
- filename = 'meow.wav'
+ log.info('Playing announcement {} in {}'.format(filename, channel))
yield from play_sound(client.get_channel(str(announcement['voice_id'])), filename)
except:
pass