+ 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 _got354(self, pieces):
+ qt, nick, auth = pieces[3:6]
+ user = self.parent.user(nick)
+ user.authed(auth)
+ if qt == "2":
+ 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%%ant,1" % (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:
+ self.parent.user(nick).part(chan)
+ chan.userpart(self.parent.user(nick))
+ def _gotquit(self, pieces):
+ nick = pieces[0].split('!')[0][1:]
+ if nick != self.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): #TODO parse for ops/voices (at least)
+ pass
+
+
+ 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()
+
+ if self.parent.hashook(cmd):
+ for callback in self.parent.gethook(cmd):
+ if chan is None and callback.needchan:
+ self.msg(user, "You need to specify a channel for that command.")
+ elif user.glevel >= callback.reqglevel and (not callback.needchan or chan.levelof(user.auth) >= callback.reqclevel):
+ try:
+ cbret = callback(self, user, chan, target, *pieces[1:])
+ except NotImplementedError:
+ self.msg(user, "Command not implemented.")
+ except Exception:
+ self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
+ self.__debug_cbexception("hook", user=user, target=target, msg=msg)
+ except SystemExit as e:
+ curs = self.parent.db.cursor()
+ curs.execute("UPDATE bots SET connected = 0")
+ curs.close()
+ raise e