From: CMDR furrycat Date: Wed, 5 Oct 2016 11:22:13 +0000 (+0100) Subject: Support voice only announcements. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=104f6b29681aaf9f58ed0174c5c72ef7232d315c;p=furrycat%2Fcatbot.git Support voice only announcements. --- diff --git a/bot.py b/bot.py index 274b2dc..e5b6d86 100755 --- a/bot.py +++ b/bot.py @@ -821,7 +821,8 @@ def show_announcement(message, id): 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']: @@ -829,9 +830,11 @@ def show_announcement(message, id): 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)) @@ -878,33 +881,46 @@ def announce(announcement): 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'^(