X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/826964670ac56032443ea66986c5b87c5ef38a4c..db75daab8e080fef8e9dbe7796492b24945e8707:/bot.py diff --git a/bot.py b/bot.py index 50456b5..68cd8ae 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,8 @@ #!/usr/bin/python +# Erebus IRC bot - Author: John Runyon +# "Bot" and "BotConnection" classes (handling a specific "arm") + #TODO: error checking import socket, sys @@ -15,7 +18,8 @@ class Bot(object): self.conn = BotConnection(self, bind, server, port) def connect(self): - if self.conn.connect(): + +if self.conn.connect(): self.parent.newfd(self, self.conn.socket.fileno()) def getdata(self): @@ -56,24 +60,14 @@ class Bot(object): 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.") + cmd = pieces[0].lower() - #TODO + if self.parent.hashook(cmd): + self.parent.gethook(cmd)(self, user, chan, *pieces[1:]) def msg(self, target, msg): if isinstance(target, self.parent.User): self.conn.send("NOTICE %s :%s" % (target.nick, msg))