Initial creation of session object.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 11:27:29 +0000 (07:27 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 11:27:29 +0000 (07:27 -0400)
irker.py

index 3c66e1a8f588e69b3a3cbe8c95d52635c283e141..d99a5da9a9581577bf7de962b0b2744bc186bfb8 100755 (executable)
--- 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()