]> jfr.im git - erebus.git/blobdiff - bot.py
Added extra parameter to callbacks, "realtarget"
[erebus.git] / bot.py
diff --git a/bot.py b/bot.py
index 68cd8aeb0416522f2f78b6c40ef865d711c86b1e..376495337b76a06654b39ae0f0c5e49a5df733f1 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -18,8 +18,7 @@ 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):
@@ -45,29 +44,66 @@ if self.conn.connect():
                if pieces[1] == "PRIVMSG":
                        nick = pieces[0].split('!')[0][1:]
                        user = self.parent.user(nick)
-                       chan = self.parent.channel(pieces[2])
+                       target = pieces[2]
                        msg = ' '.join(pieces[3:])[1:]
-                       self.parsemsg(user, chan, msg)
+                       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]
+                       if auth != '0':
+                               self.parent.user(nick).authed(auth)
+
                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
+                       chan = self.parent.channel(pieces[2])
 
+                       if nick == self.nick:
+                               self.conn.send("WHO %s %%ant,1" % (chan))
+                       else:
+                               pass #TODO TODO TODO add to common chans!
+                       
+       def parsemsg(self, user, target, msg):
+               chan = None
+               triggerused = msg[0] == self.parent.trigger
+               if triggerused: msg = msg[1:]
                pieces = msg.split()
+
+               if target == self.nick:
+                       chanword = pieces[1]
+                       if chanword[0] == '#':
+                               chan = self.parent.channel(chanword)
+                               pieces.pop(1)
+
+               else: # message was sent to a channel
+                       chan = self.parent.channel(target) #TODO check if bot's on channel --- in Erebus.channel() maybe?
+                       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:
+                               return # not to bot, don't process!
+
                cmd = pieces[0].lower()
 
+               print "%r %r %r %r" % (cmd, user, target, msg)
+
                if self.parent.hashook(cmd):
-                       self.parent.gethook(cmd)(self, user, chan, *pieces[1:])
+                       callback = self.parent.gethook(cmd)
+                       if chan is None and callback.needchan:
+                               self.msg(user, "You need to specify a channel for that command.")
+                               return
+                       if user.glevel >= callback.reqglevel:
+                               #TODO TODO TODO check reqclevel
+                               callback(self, user, chan, target, *pieces[1:])
+                               return
+
+               self.msg(user, "No such command, or you don't have access.")
 
        def msg(self, target, msg):
                if isinstance(target, self.parent.User): self.conn.send("NOTICE %s :%s" % (target.nick, msg))