+ curs = self.parent.db.cursor()
+ curs.execute("UPDATE bots SET connected = 1 WHERE nick = %s", (self.nick,))
+ curs.close()
+
+ 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)
+ def _gotprivmsg(self, pieces):
+ nick = pieces[0].split('!')[0][1:]
+ user = self.parent.user(nick)
+ target = pieces[2]
+ msg = ' '.join(pieces[3:])[1:]
+ self.parsemsg(user, target, msg)
+ def _got353(self, pieces):
+ chan = self.parent.channel(pieces[4])
+ names = pieces[5:]
+ names[0] = names[0][1:] #remove colon
+ for n in names:
+ user = self.parent.user(n.lstrip('@+'))
+ if n[0] == '@':
+ chan.userjoin(user, 'op')
+ elif n[0] == '+':
+ chan.userjoin(user, 'voice')
+ else:
+ chan.userjoin(user)
+ user.join(chan)
+ def _got354(self, pieces):
+ qt = int(pieces[3])
+ if qt < 3:
+ nick, auth = pieces[4:6]
+ chan = None
+ else:
+ chan, nick, auth = pieces[4:7]
+ chan = self.parent.channel(chan)
+ user = self.parent.user(nick)
+ user.authed(auth)
+
+ if chan is not None:
+ user.join(chan)
+ chan.userjoin(user)
+
+ if qt == 2: # triggered by !auth
+ if user.isauthed():
+ if user.glevel > 0:
+ self.msg(nick, "You are now known as #%s (access level: %s)" % (auth, user.glevel))
+ else:
+ self.msg(nick, "You are now known as #%s (not staff)" % (auth))
+ else:
+ self.msg(nick, "I tried, but you're not authed!")
+ def _gotjoin(self, pieces):
+ nick = pieces[0].split('!')[0][1:]
+ chan = self.parent.channel(pieces[2])
+
+ if nick == self.nick:
+ self.conn.send("WHO %s c%%cant,3" % (chan))
+ else:
+ user = self.parent.user(nick, justjoined=True)
+ chan.userjoin(user)
+ user.join(chan)
+ def _gotpart(self, pieces):
+ nick = pieces[0].split('!')[0][1:]
+ chan = self.parent.channel(pieces[2])
+
+ if nick != self.nick:
+ gone = self.parent.user(nick).part(chan)
+ chan.userpart(self.parent.user(nick))
+ if gone:
+ self.parent.user(nick).quit()
+ del self.parent.users[nick.lower()]
+ def _gotquit(self, pieces):
+ nick = pieces[0].split('!')[0][1:]
+ if nick != self.nick:
+ for chan in self.parent.user(nick).chans:
+ chan.userpart(self.parent.user(nick))
+ self.parent.user(nick).quit()
+ del self.parent.users[nick.lower()]
+ def _gotnick(self, pieces):
+ 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)
+ def _gotmode(self, pieces):
+ source = pieces[0].split('!')[0][1:]
+ chan = self.parent.channel(pieces[2])
+ mode = pieces[3]
+ args = pieces[4:]
+
+ adding = True
+ for c in mode:
+ if c == '+':
+ adding = True
+ elif c == '-':
+ adding = False
+ elif c == 'o':
+ if adding:
+ chan.userop(self.parent.user(args.pop(0)))
+ else:
+ chan.userdeop(self.parent.user(args.pop(0)))
+ elif c == 'v':
+ if adding:
+ chan.uservoice(self.parent.user(args.pop(0)))
+ else:
+ chan.userdevoice(self.parent.user(args.pop(0)))
+ else:
+ pass # don't care about other modes
+
+ def __debug_cbexception(self, source, *args, **kwargs):
+ if int(self.parent.cfg.get('debug', 'cbexc', default=0)) == 1:
+ self.conn.send("PRIVMSG %s :%09.3f ^C4^B!!!^B^C CBEXC %s" % (self.parent.cfg.get('debug', 'owner'), time.time() % 100000, source))
+ __import__('traceback').print_exc()
+ print "%09.3f %s [!] CBEXC %s %r %r" % (time.time() % 100000, self.nick, source, args, kwargs)
+
+
+ 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)
+
+ else: # message was sent to a channel
+ chan = self.parent.channel(target)
+ try:
+ if msg[0] == '*': # message may be addressed to bot by "*BOTNICK" trigger?
+ if pieces[0][1:].lower() == self.nick.lower():
+ pieces.pop(0) # command actually starts with next word
+ msg = ' '.join(pieces) # command actually starts with next word
+ elif not triggerused:
+ if self.parent.haschanhook(target.lower()):
+ for callback in self.parent.getchanhook(target.lower()):
+ try:
+ cbret = callback(self, user, chan, *pieces)
+ except NotImplementedError:
+ self.msg(user, "Command not implemented.")
+ except:
+ self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
+ self.__debug_cbexception("chanhook", user=user, target=target, msg=msg)
+ return # not to bot, don't process!
+ except IndexError:
+ return # "message" is empty
+
+ cmd = pieces[0].lower()