From 010afd05ce3999abeef13024043606ee3445ca70 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 12 Feb 2017 10:58:18 -0600 Subject: [PATCH] add some anti-flood protection stuff this throttles multi-line messages in a way that probably doesn't affect the normal cases much, and scales fairly well to far longer text. for some reason long ascii art still triggers the flood detection, but with this code at least it happens later in the process. so, success, for now? i can fix the ascii art at some future point if i ever hit it practically closes bss/dr.botzo#23 --- ircbot/bot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ircbot/bot.py b/ircbot/bot.py index 2f43767..df7b617 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -872,6 +872,7 @@ class IRCBot(irc.client.SimpleIRCClient): if recursing: return replystr else: + lines = 0 replies = replystr.split('\n') for reply in replies: # split messages that are too long. max length is 512, but we also need to @@ -886,6 +887,10 @@ class IRCBot(irc.client.SimpleIRCClient): reply = self.splitter + ' ' + reply[splitpos + 1:] self.privmsg(replypath, splittext) + # antiflood + lines += 1 + time.sleep(int(0.5 * lines)) + # done splitting, or it was never necessary self.privmsg(replypath, reply) if stop: