From 44899740a694eb503a2bb18709c92fbc13b738e0 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 16 Apr 2004 21:05:41 +0000 Subject: [PATCH] Added --capability to user list. --- ChangeLog | 5 +++++ src/User.py | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c7bcfc11..0fd519ad6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ * Fixed numerous bugs, high and low, big and small and in-between. Definitely worthy of a release. + * Added a --capability option to User.list, to allow people to + list all the users possessing a certain capability. The main + reason this was added is so jemfinch can tell who owns which + Supybots on #supybot :) + * Added Utilities.success, mostly for making aliases such that they can respond with success if no errors were encountered in any nested commands. diff --git a/src/User.py b/src/User.py index f96a1e0e5..97be3f2e1 100755 --- a/src/User.py +++ b/src/User.py @@ -56,27 +56,41 @@ class User(callbacks.Privmsg): raise callbacks.Error, conf.supybot.replies.requiresPrivacy() def list(self, irc, msg, args): - """[] + """[--capability ] [] Returns the valid registered usernames matching . If is not given, returns all registered usernames. """ - glob = privmsgs.getArgs(args, required=0, optional=1) + (optlist, rest) = getopt.getopt(args, '', ['capability=']) + predicates = [] + for (option, arg) in optlist: + if option == '--capability': + def p(u, cap=arg): + try: + return u.checkCapability(cap) + except KeyError: + return False + predicates.append(p) + glob = privmsgs.getArgs(rest, required=0, optional=1) if glob: if '*' not in glob and '?' not in glob: glob = '*%s*' % glob r = re.compile(fnmatch.translate(glob), re.I) def p(s): return r.match(s) is not None - else: - def p(s): - return True - users = [u.name for u in ircdb.users.itervalues() if p(u.name)] + predicates.append(p) + users = [] + for u in ircdb.users.itervalues(): + for predicate in predicates: + if not predicate(u): + break + else: + users.append(u.name) if users: utils.sortBy(str.lower, users) irc.reply(utils.commaAndify(users)) else: - if glob: + if predicates: irc.reply('There are no matching registered users.') else: irc.reply('There are no registered users.')