pythonverse

Python-based client for OpenVerse with extra features
git clone https://code.literati.org/pythonverse.git
Log | Files | Refs | README | LICENSE

commit fea74af58bb80cf74ceb0070c40fb34f4c96c4b0
parent 962f62fdaf4f3afd665e425ff9b1c423ae748f00
Author: seanl <seanl>
Date:   Sat,  9 Mar 2002 03:15:07 +0000

Added 'bot' frontend, which will call a subprocess via the python expect module. Also added client.py, which is a generic client object. The other frontends should probably inherit from Client in client.py.

Diffstat:
Abot.py | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aclient.py | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 151 insertions(+), 0 deletions(-)

diff --git a/bot.py b/bot.py @@ -0,0 +1,81 @@ +#!/usr/bin/python +# Copyright (c) 2002 Sean R. Lynch <seanl@chaosring.org> +# +# This file is part of PythonVerse. +# +# PythonVerse is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# PythonVerse is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with PythonVerse; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -*-Python-*- + +import sys, os, string, re, asyncore, expect, time +import OpenVerse, client + +class BotClient(client.Client): + def __init__(self, nick, pipe): + self.nick = nick + self.pipe = pipe + + def chat(self, nick, s): + global USER + if self.pipe is None: return + if nick == self.nick: return + m = re.match(self.nick + '[,:; ]*(.+)', s) + if m: + USER = nick + s = m.group(1) + + try: self.pipe.write(s + '\n\n') + except: + print "Couldn't write" + self.pipe = None + +def main(argv, env): + global USER + + USER = None + + nick = argv[1] + host = argv[2] + port = int(argv[3]) + avatar = argv[4] + command = string.join(argv[5:]) + + # Open a pipe to the command + pipe = expect.popen(command, 'b') + c = BotClient(nick, pipe) + server = OpenVerse.ServerConnection(host, port, c, nick, avatar) + c.set_server(server) + #asyncore.poll(5) + #asyncore.poll(5) + #server.chat('Lah hello') + while 1: + asyncore.poll(5) + try: + data = string.strip(c.pipe.read()) + print data + except: + print 'crashed' + pipe = expect.popen(command, 'b') + c.pipe = pipe + else: + #print >> sys.stderr, data + if data and USER: + for line in string.split(data, '\n'): + server.chat('%s: %s' % (USER, line)) + + USER = None + +if __name__ == '__main__': + main(sys.argv, os.environ) diff --git a/client.py b/client.py @@ -0,0 +1,69 @@ +# Copyright (c) 2002 Sean R. Lynch <seanl@chaosring.org> +# +# This file is part of PythonVerse. +# +# PythonVerse is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# PythonVerse is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with PythonVerse; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -*-Python-*- +import sys + +class Client: + def __init__(self): pass + + def set_server(self, server): + self.server = server + + def debug(self, t): + print >> sys.stderr, t + + def background_image(self, image): pass + + def background_progress(self, length, filename, size): pass + + def set_title(self, title): pass + + def raise_object(self, name): pass + + def mouseover(self, name, pos, image1, image2): pass + + def newimage(self, filename=None): return None + + def new_avatar(self, nick, pos, image, noffset, boffset): pass + + def del_avatar(self, nick): pass + + def exit_obj(self, name, host, port): pass + + def avatar(self, nick, image, noffset, boffset): pass + + def mouseover_image1(self, name, image): pass + + def mouseover_image2(self, name, image): pass + + def avatar_image(self, nick, image): pass + + def move_avatar(self, nick, x, y, speed): pass + + def effect(self, nick, action): pass + + def url(self, nick, url): pass + + def avatar_progress(self, nick, length, filename, size): pass + + def setmouseover(self, name): pass + + def privmsg(self, nick, s): pass + + def chat(self, nick, s): pass+ \ No newline at end of file