+ if not self.conn.registered() and pieces[0] == "NOTICE":
+ self.conn.register()
+ return
+
+ if self.parent.hasnumhook(pieces[1]):
+ hooks = self.parent.getnumhook(pieces[1])
+ for callback in hooks:
+ callback(self, line)
+
+ if pieces[1] == "001":
+ self.conn.registered(True)
+ self.conn.send("MODE %s +x" % (pieces[2]))
+ if self.authname is not None and self.authpass is not None:
+ self.conn.send("AUTH %s %s" % (self.authname, self.authpass))
+ for c in self.chans:
+ self.join(c.name)
+
+ elif pieces[1] == "PRIVMSG":
+ nick = pieces[0].split('!')[0][1:]
+ user = self.parent.user(nick)
+ target = pieces[2]
+ msg = ' '.join(pieces[3:])[1:]
+ self.parsemsg(user, target, msg)
+
+ elif pieces[0] == "PING":
+ self.conn.send("PONG %s" % (pieces[1]))
+
+ elif pieces[1] == "354": # WHOX
+ qt = pieces[3]
+ nick = pieces[4]
+ auth = pieces[5]
+ self.parent.user(nick).authed(auth)
+
+ elif pieces[1] == "JOIN":
+ nick = pieces[0].split('!')[0][1:]
+ chan = self.parent.channel(pieces[2])
+
+ if nick == self.nick:
+ self.conn.send("WHO %s c%%ant,1" % (chan))
+ else:
+ user = self.parent.user(nick, justjoined=True)
+ chan.userjoin(user)
+ user.join(chan)
+
+ elif pieces[1] == "PART":
+ nick = pieces[0].split('!')[0][1:]
+ chan = self.parent.channel(pieces[2])
+
+ if nick != self.nick:
+ self.parent.user(nick).part(chan)
+ chan.userpart(self.parent.user(nick))
+
+ elif pieces[1] == "QUIT":
+ nick = pieces[0].split('!')[0][1:]
+ if nick != self.nick:
+ self.parent.user(nick).quit()
+ del self.parent.users[nick.lower()]
+
+ elif pieces[1] == "NICK":
+ oldnick = pieces[0].split('!')[0][1:]
+ newnick = pieces[2][1:]
+ if newnick.lower() != oldnick.lower():
+ self.parent.users[newnick.lower()] = self.parent.users[oldnick.lower()]
+ del self.parent.users[oldnick.lower()]
+ self.parent.users[newnick.lower()].nickchange(newnick)
+
+ elif pieces[1] == "MODE": #TODO parse for ops/voices (at least)
+ pass
+
+
+ def parsemsg(self, user, target, msg):
+ chan = None
+ if len(msg) == 0:
+ return
+
+ triggerused = msg[0] == self.parent.trigger
+ if triggerused: msg = msg[1:]
+ pieces = msg.split()
+
+ if target == self.nick:
+ if msg[0] == "\001": #ctcp
+ msg = msg.strip("\001")
+ if msg == "VERSION":
+ self.msg(user, "\001VERSION Erebus v%d.%d - http://github.com/zonidjan/erebus" % (self.parent.APIVERSION, self.parent.RELEASE))
+ return
+ if len(pieces) > 1:
+ chanword = pieces[1]
+ if chanword[0] == '#':
+ chan = self.parent.channel(chanword)
+ if chan is not None: #if chan is still none, there's no bot on "chanword", and chanword is used as a parameter.
+ pieces.pop(1)