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
This commit is contained in:
Brian S. Stephan 2017-02-12 10:58:18 -06:00
parent 8b4f8b2545
commit 010afd05ce
1 changed files with 5 additions and 0 deletions

View File

@ -872,6 +872,7 @@ class IRCBot(irc.client.SimpleIRCClient):
if recursing: if recursing:
return replystr return replystr
else: else:
lines = 0
replies = replystr.split('\n') replies = replystr.split('\n')
for reply in replies: for reply in replies:
# split messages that are too long. max length is 512, but we also need to # 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:] reply = self.splitter + ' ' + reply[splitpos + 1:]
self.privmsg(replypath, splittext) self.privmsg(replypath, splittext)
# antiflood
lines += 1
time.sleep(int(0.5 * lines))
# done splitting, or it was never necessary # done splitting, or it was never necessary
self.privmsg(replypath, reply) self.privmsg(replypath, reply)
if stop: if stop: