From 70480b8830cbfedd913fe25c1e6251a8e46274f9 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 7 Jun 2015 09:43:13 -0700 Subject: [PATCH] Make IrcChannel.users a set and add part handling This should be everything needed for basic channel enumeration: closes #13. --- classes.py | 2 +- proto.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/classes.py b/classes.py index d2dd7fa..f1c0322 100644 --- a/classes.py +++ b/classes.py @@ -25,7 +25,7 @@ class IrcServer(): class IrcChannel(): def __init__(self): - self.users = [] + self.users = set() ''' self.ops = [] self.halfops = [] diff --git a/proto.py b/proto.py index 8a1e6ea..6ac4815 100644 --- a/proto.py +++ b/proto.py @@ -41,9 +41,7 @@ def removeClient(irc, numeric): Removes a client from our internal databases, regardless of whether it's one of our pseudoclients or not.""" for k, v in copy(irc.channels).items(): - if numeric in irc.channels[k].users: - print('Removing client %s from channel %s' % (numeric, k)) - irc.channels[k].users.remove(numeric) + irc.channels[k].users.discard(numeric) if not irc.channels[k].users: # Clear empty channels del irc.channels[k] @@ -102,6 +100,11 @@ def handle_privmsg(irc, source, command, args): msg(irc, source, 'Uncaught exception in command %r: %s: %s' % (cmd, type(e).__name__, str(e))) return +def handle_part(irc, source, command, args): + channel = args[0] + # We should only get PART commands for channels that exist, right?? + irc.channels[channel].users.discard(source) + def handle_error(irc, numeric, command, args): print('Received an ERROR, killing!') irc.connected = False @@ -128,7 +131,7 @@ def handle_fjoin(irc, servernumeric, command, args): if mode == 'v': irc.channels[channel].voices.append(user) ''' - irc.channels[channel].users.append(user) + irc.channels[channel].users.add(user) def handle_uid(irc, numeric, command, args): # :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname