]> jfr.im git - erebus.git/blobdiff - bot.py
modlib - correctly explain IGNORED level
[erebus.git] / bot.py
diff --git a/bot.py b/bot.py
index 3ce39474d39452f673493faacfe35a72450bb3be..73115a8da034c7c3b26d22e0417d4d99ae5ce708 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -27,6 +27,8 @@ else:
 #bots = {'erebus': bot.Bot(nick='Erebus', user='erebus', bind='', server='irc.quakenet.org', port=6667, realname='Erebus')}
 class Bot(object):
        def __init__(self, parent, nick, user, bind, authname, authpass, server, port, realname):
+               self.maxlen = 510
+
                self.parent = parent
                self.nick = nick
                self.permnick = nick
@@ -97,8 +99,6 @@ class Bot(object):
                        self.conn.send("NICK %s" % (self.permnick))
 
        def parse(self, line):
-               if self.parent.cfg.getboolean('debug', 'io'):
-                       self.log('I', line)
                pieces = line.split()
 
                if pieces[0][0] == ":":
@@ -237,15 +237,20 @@ class Bot(object):
                if nick == self.nick:
                        self.conn.send("WHO %s c%%cant,3" % (chan))
                else:
-                       user = self.parent.user(nick, justjoined=True)
+                       user = self.parent.user(nick, send_who=True)
                        chan.userjoin(user)
                        user.join(chan)
        def _clientLeft(self, nick, chan):
-               if nick != self.nick:
-                       gone = self.parent.user(nick).part(chan)
-                       chan.userpart(self.parent.user(nick))
+               if nick == self.nick:
+                       for u in chan.users:
+                               if u.nick != self.nick:
+                                       self._clientLeft(u.nick, chan)
+               else:
+                       user = self.parent.user(nick)
+                       gone = user.part(chan)
+                       chan.userpart(user)
                        if gone:
-                               self.parent.user(nick).quit()
+                               user.quit()
                                del self.parent.users[nick.lower()]
        def _gotpart(self, pieces):
                nick = pieces[0].split('!')[0][1:]
@@ -321,12 +326,20 @@ class Bot(object):
                if len(msg) == 0:
                        return
 
-               if target == self.nick:
-                       if msg.startswith("\001"): #ctcp
-                               msg = msg.strip("\001")
-                               if msg == "VERSION":
-                                       self.msg(user, "\001VERSION Erebus v%d.%d - http://jfr.im/git/erebus.git" % (self.parent.APIVERSION, self.parent.RELEASE))
-                               return
+               if target == self.nick and msg.startswith("\001"): #ctcp
+                       msg = msg.strip("\001")
+                       if msg:
+                               pieces = msg.split()
+                               if pieces[0] == "CLIENTINFO":
+                                       self.msg(user, "\001CLIENTINFO VERSION PING\001")
+                               elif pieces[0] == "VERSION":
+                                       self.msg(user, "\001VERSION Erebus v%d.%d - http://jfr.im/git/erebus.git\001" % (self.parent.APIVERSION, self.parent.RELEASE))
+                               elif pieces[0] == "PING":
+                                       if len(pieces) > 1:
+                                               self.msg(user, "\001PING %s\001" % (' '.join(pieces[1:])))
+                                       else:
+                                               self.msg(user, "\001PING\001")
+                       return
 
                triggerused = msg.startswith(self.parent.trigger)
                if triggerused: msg = msg[len(self.parent.trigger):]
@@ -420,15 +433,9 @@ class Bot(object):
                if self.parent.cfg.getboolean('erebus', 'nofakelag'): append_callback = self.conn.send
 
                cmd = self._formatmsg(target, msg, msgtype)
-               # The max length is much shorter than recvq (510) because of the length the server adds on about the source (us).
+               # The max length is much shorter than conn.maxlen (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)
-               )
+               maxlen = self.maxmsglen()
                if len(cmd) > maxlen:
                        if not truncate:
                                return False
@@ -504,6 +511,15 @@ class Bot(object):
        def quit(self, reason="Shutdown"):
                self.conn.send("QUIT :%s" % (reason))
 
+       def maxmsglen(self):
+               return (
+                       self.maxlen
+                       - 63 # max hostname len
+                       - 11 # max ident len
+                       - 3  # the symbols in :nick!user@host
+                       - len(self.nick)
+               )
+
        def __str__(self): return self.nick
        def __repr__(self): return "<Bot %r>" % (self.nick)
 
@@ -520,7 +536,7 @@ class BotConnection(object):
                self.state = 0 # 0=disconnected, 1=registering, 2=connected
 
                self.bytessent = 0
-               self.recvq = 510
+               self.recvq = 510 # How much we can send per period
                self.exceeded = False
                self._nowrite = False