From 0d5323d2940c8ceeebcf55c6103e1f367d21dfa1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 25 Aug 2012 09:03:40 -0400 Subject: [PATCH] How to parse the channel spec. --- irker.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/irker.py b/irker.py index 396ac30..fe2b743 100755 --- a/irker.py +++ b/irker.py @@ -13,12 +13,30 @@ import threading, Queue class Session(): "IRC session and message queue processing." - def __init__(self, channel): - self.channel = channel + def __init__(self, url): + self.url = url + # The consumer thread self.queue = Queue.Queue() self.thread = threading.Thread(target=self.dequeue) self.thread.daemon = True self.thread.start() + # The channel specification + if not url.startswith("irc://") or url.count("/") != 3: + raise ValueError + else: + url = url[6:] + parts = url.split(":", 1) + if len(parts) == 2: + try: + self.port = int(parts[1]) + except ValueError: + print "Error: Erroneous port." + sys.exit(1) + else: + self.port = 6667 + (self.server, self.channel) = parts[0].split("/", 1) + # Client setup + self.client = irclib.SimpleIRCClient() def enqueue(self, message): "Enque a message for transmission." self.queue.put(message) -- 2.26.2