]> jfr.im git - erebus.git/commitdiff
bot._msg - fix calculation
authorJohn Runyon <redacted>
Sun, 30 Jan 2022 08:22:46 +0000 (02:22 -0600)
committerJohn Runyon <redacted>
Sun, 30 Jan 2022 08:22:46 +0000 (02:22 -0600)
bot.py

diff --git a/bot.py b/bot.py
index 51a5b8f2277ff2ab9db9fa0b9450f0b42ffd428d..a9b7ea91cc9eea696116a75b67ad81953bc9cd6a 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -381,11 +381,20 @@ class Bot(object):
                if self.parent.cfg.getboolean('erebus', 'nofakelag'): return self.fastmsg(target, msg)
 
                cmd = self._formatmsg(target, msg)
-               if len(cmd) > self.conn.recvq:
+               # The max length is much shorter than recvq (510) because of the length the server adds on about the source (us).
+               # If you know your hostmask, you can of course figure the exact length, but it's very difficult to reliably know your hostmask.
+               maxlen = (
+                       self.conn.recvq
+                       - 63 # max hostname len
+                       - 11 # max ident len
+                       - 3  # the symbols in :nick!user@host
+                       - len(self.nick)
+               )
+               if len(cmd) > maxlen:
                        if not truncate:
                                return False
                        else:
-                               cmd = cmd[:self.conn.recvq]
+                               cmd = cmd[:maxlen]
 
                if self.conn.exceeded or self.conn.bytessent+len(cmd) >= self.conn.recvq:
                        append_callback(cmd)
@@ -470,7 +479,7 @@ class BotConnection(object):
                self.state = 0 # 0=disconnected, 1=registering, 2=connected
 
                self.bytessent = 0
-               self.recvq = 400
+               self.recvq = 510
                self.exceeded = False
                self._nowrite = False