From b1e08362e2455f2190c3daf55f992e7bef023e8b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 25 Aug 2012 07:27:29 -0400 Subject: [PATCH] Initial creation of session object. --- irker.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/irker.py b/irker.py index 3c66e1a..d99a5da 100755 --- a/irker.py +++ b/irker.py @@ -8,13 +8,22 @@ and relays to IRC channels. """ import os, sys, json, irclib, getopt +class Session: + "IRC session and message queue processing." + def __init__(self, channel): + self.channel = channel + self.queue = [] + def enqueue(self, message): + "Enque a message for transmission." + self.queue.append(message) + class Irker: "Persistent IRC multiplexer." def __init__(self): - self.botpool = {} + self.sessions = {} def logerr(self, errmsg): "Log a processing error." - sys.stderr.write(errmsg) + sys.stderr.write("irker: " + errmsg + "\n") def run(self, ifp): "Accept JSON relay requests from specified stream." while True: @@ -24,11 +33,18 @@ class Irker: try: request = json.loads(inp.strip()) except ValueError: - self.logerr("irker: can't recognize JSON on input.\n") + self.logerr("can't recognize JSON on input.") break self.relay(request) def relay(self, request): - print request + if "channel" not in request or "message" not in request: + self.logerr("ill-formed reqest") + else: + channel = request['channel'] + message = request['message'] + if channel not in self.sessions: + self.sessions[channel] = Session(channel) + self.sessions[channel].enqueue(message) if __name__ == '__main__': irker = Irker() -- 2.26.2