+
+ if pieces[1] == "PRIVMSG":
+ nick = pieces[0].split('!')[0][1:]
+ user = self.parent.user(nick)
+ chan = self.parent.channel(pieces[2])
+ msg = ' '.join(pieces[3:])[1:]
+ self.parsemsg(user, chan, msg)
+
+ elif pieces[0] == "PING":
+ self.conn.send("PONG %s" % (pieces[1]))
+
+ elif pieces[1] == "JOIN":
+ nick = pieces[0].split('!')[0][1:]
+ user = self.parent.user(nick)
+ chan = self.parent.channel(pieces[2]) #TODO TODO TODO
+
+ def parsemsg(self, user, chan, msg):
+ if msg[0] == '!': #TODO check config for trigger
+ msg = msg[1:]
+
+ else:
+ return
+
+ pieces = msg.split()
+ cmd = pieces[0].upper()
+
+ if cmd == "EVAL":
+ try: ret = eval(' '.join(pieces[1:]))
+ except: self.msg(chan, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
+ else: self.msg(chan, "Done: %r" % (ret))
+
+ elif cmd == "EXEC":
+ try: exec ' '.join(pieces[1:])
+ except: self.msg(chan, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
+ else: self.msg(chan, "Done.")
+
+ #TODO
+
+ def msg(self, target, msg):
+ if isinstance(target, self.parent.User): self.conn.send("NOTICE %s :%s" % (target.nick, msg))
+ elif isinstance(target, self.parent.Channel): self.conn.send("PRIVMSG %s :%s" % (target.name, msg))
+ elif isinstance(target, basestring):
+ if target[0] == '#': self.conn.send("PRIVMSG %s :%s" % (target, msg))
+ else: self.conn.send("NOTICE %s :%s" % (target, msg))
+ else: raise TypeError('Bot.msg() "target" must be Erebus.User, Erebus.Channel, or string')
+
+ def join(self, chan):
+ self.conn.send("JOIN %s" % (chan))
+
+ def part(self, chan):
+ self.conn.send("PART %s" % (chan))
+
+ def quit(self, reason="Shutdown"):
+ self.conn.send("QUIT :%s" % (reason))