From 2f7824f5a8b994285f425b27d8e2d5af596d9987 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 25 Oct 2016 08:37:17 +0100 Subject: [PATCH] Reduce spam of announcements in quiet channels. Don't post an announcement if there has been little channel activity since the last scheduled posting, even if the schedule has been kept correctly. --- bot.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index aee75e4..d05df35 100755 --- a/bot.py +++ b/bot.py @@ -1667,6 +1667,7 @@ def announce(announcement): return voice_only = announcement['voice_id'] == announcement['channel_id'] + already_posted = False if not voice_only: # @everyone mention mangles the digest text = announcement['message'] @@ -1682,12 +1683,18 @@ def announce(announcement): # 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) + 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 + # been posted since the cutoff. + if len(logs) < message_limit.value: + logs = yield from client.logs_from(channel, limit = message_limit.value) for message in logs: raw = re.sub(r'^(