]> jfr.im git - z_archive/pyp10.git/commitdiff
Updates, add modules/do.py (eval/exec for debugging)
authorJohn Runyon <redacted>
Sat, 17 Aug 2013 18:49:27 +0000 (13:49 -0500)
committerJohn Runyon <redacted>
Sat, 17 Aug 2013 18:49:27 +0000 (13:49 -0500)
modules/do.py [new file with mode: 0644]
modules/q.py
pyp10.py

diff --git a/modules/do.py b/modules/do.py
new file mode 100644 (file)
index 0000000..76cd134
--- /dev/null
@@ -0,0 +1,27 @@
+import sys
+
+class Pseudo(object):
+       def __init__(self, uplink):
+               self.uplink = uplink
+               self.nick = 'Do'
+               self.num = self.uplink.makenick(self, self.nick, 'TheDoBot','PyP10 Do')
+               self._send("J #p10 780000000")
+       def _send(self, line, **kwargs):
+               self.uplink.send(line, self.num, **kwargs)
+       def gotmsg(self, msg, source, target):
+               command, args = msg.split(None, 1)
+               if command == 'exec':
+                       try:
+                               exec(args, globals(), locals())
+                       except:
+                               self._send("P #p10 :!%(fromnum)s! exec - Exception: %(exc)r", fromnum=source, exc=sys.exc_info()[1])
+                       else:
+                               self._send("P #p10 :!%(fromnum)s! exec - Done.", fromnum=source)
+               elif command == 'eval':
+                       retval = None
+                       try:
+                               retval = eval(args, globals(), locals())
+                       except:
+                               self._send("P #p10 :!%(fromnum)s! eval - Exception: %(exc)r", fromnum=source, exc=sys.exc_info()[1])
+                       else:
+                               self._send("P #p10 :!%(fromnum)s! eval - Return: %(retval)r", fromnum=source, retval=retval)
index 85c5b94b68a6f17c3eff28745f4e639cce83945d..ac8761fb77316390c01480cd2df7cda2ad8bdab7 100644 (file)
@@ -1,7 +1,10 @@
 class Pseudo(object):
        def __init__(self, uplink):
                self.uplink = uplink
-               self.num = self.uplink.makenick(self, 'Q','TheQBot','PyP10 Q')
-               self.send("J #p10 780000000")
-       def send(self, line, **kwargs):
+               self.nick = 'Q'
+               self.num = self.uplink.makenick(self, self.nick, 'TheQBot','PyP10 Q')
+               self._send("J #p10 780000000")
+       def _send(self, line, **kwargs):
                self.uplink.send(line, self.num, **kwargs)
+       def gotmsg(self, msg, source, target):
+               self._send("P #p10 :<%(fromnum)s> %(msg)s", fromnum=source, msg=msg)
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