]> jfr.im git - z_archive/pyp10.git/blobdiff - pyp10.py
Updates, add modules/do.py (eval/exec for debugging)
[z_archive/pyp10.git] / pyp10.py
index 51ed06ffad0183ba13a842d1da4ce39c0284c500..d91b5596a68ff1b3eca322fc54a6cd238d9b5780 100755 (executable)
--- a/pyp10.py
+++ b/pyp10.py
@@ -16,14 +16,10 @@ class config(object):
                'password': 'password',
                'vhost': '', #bind to this ip - empty string '' for auto-select
        }
-       autoload = ['q']
+       autoload = ['q', 'do']
 
 b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]"
 
-def process(line):
-       words = line.split()
-       if words[1] == "G" or words[1] == "PING":
-               uplink.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']})
 
 class Uplink(object):
        def __init__(self):
@@ -32,6 +28,7 @@ class Uplink(object):
 
                self.lastnum = None # last numeric used, as [int,int,int]
                self.nicks = {} # 'nick': Pseudo-object
+               self.nums = {} # 'num': Pseudo-object
                self.data = "" # receive buffer
 
                self.sock = socket.socket()
@@ -54,7 +51,7 @@ class Uplink(object):
                        pieces = self.data.split("\n", 1)
                        line = pieces[0].strip()
                        print "<", line
-                       process(line)
+                       self._process(line)
                        self.data = pieces[1]
                return True
        def loop(self):
@@ -62,11 +59,30 @@ class Uplink(object):
                while keepgoing:
                        keepgoing = self._receive()
 
+       def _process(self, line):
+               words = line.split()
+               if words[1] == "G" or words[1] == "PING":
+                       self.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']})
+               elif words[1] == "P" or words[1] == "PRIVMSG":
+                       source = words[0]
+                       target = words[2]
+                       extra = ' '.join(words[3:])
+                       if extra[0] == ':':
+                               extra = extra[1:]
+                       if '@' in target:
+                               tonick = target.split('@', 1)
+                               self.nicks[tonick].gotmsg(extra, source, target)
+                       elif '#' in target:
+                               pass # no processing
+                       elif '$' in target:
+                               pass # no processing
+                       else:
+                               self.nums[target].gotmsg(extra, source, target)
        def _newnum(self):
                if self.lastnum is None:
                        self.lastnum = [0,0,0]
                else:
-                       self.lastnum = [i+1 for i in lastnum]
+                       self.lastnum = [i+1 for i in self.lastnum]
                num =  config.numeric
                num += b64[self.lastnum[2]]
                num += b64[self.lastnum[1]]
@@ -75,7 +91,8 @@ class Uplink(object):
 
        def makenick(self, obj, nick, ident, realname):
                newnum = self._newnum()
-               self.send("N %(nick)s 1 %(time)s %(ident)s %(host)s +oknXr pyp10 DAqAAB %(num)s :%(name)s", nick=nick, ident=ident, name=realname, time=time.time(), host=config.name, num=newnum)
+               self.send("N %(nick)s 1 %(time)s %(ident)s %(host)s +doknXr pyp10 DAqAAB %(num)s :%(name)s", nick=nick, ident=ident, name=realname, time=time.time(), host=config.name, num=newnum)
+               self.nums[newnum] = obj
                self.nicks[nick] = obj
                return newnum