mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-10-05 19:37:25 +02:00
Added --capability to user list.
This commit is contained in:
parent
6a7981aac0
commit
44899740a6
@ -5,6 +5,11 @@
|
|||||||
* Fixed numerous bugs, high and low, big and small and
|
* Fixed numerous bugs, high and low, big and small and
|
||||||
in-between. Definitely worthy of a release.
|
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
|
* Added Utilities.success, mostly for making aliases such that
|
||||||
they can respond with success if no errors were encountered in
|
they can respond with success if no errors were encountered in
|
||||||
any nested commands.
|
any nested commands.
|
||||||
|
28
src/User.py
28
src/User.py
@ -56,27 +56,41 @@ class User(callbacks.Privmsg):
|
|||||||
raise callbacks.Error, conf.supybot.replies.requiresPrivacy()
|
raise callbacks.Error, conf.supybot.replies.requiresPrivacy()
|
||||||
|
|
||||||
def list(self, irc, msg, args):
|
def list(self, irc, msg, args):
|
||||||
"""[<glob>]
|
"""[--capability <capability>] [<glob>]
|
||||||
|
|
||||||
Returns the valid registered usernames matching <glob>. If <glob> is
|
Returns the valid registered usernames matching <glob>. If <glob> is
|
||||||
not given, returns all registered usernames.
|
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 glob:
|
||||||
if '*' not in glob and '?' not in glob:
|
if '*' not in glob and '?' not in glob:
|
||||||
glob = '*%s*' % glob
|
glob = '*%s*' % glob
|
||||||
r = re.compile(fnmatch.translate(glob), re.I)
|
r = re.compile(fnmatch.translate(glob), re.I)
|
||||||
def p(s):
|
def p(s):
|
||||||
return r.match(s) is not None
|
return r.match(s) is not None
|
||||||
else:
|
predicates.append(p)
|
||||||
def p(s):
|
users = []
|
||||||
return True
|
for u in ircdb.users.itervalues():
|
||||||
users = [u.name for u in ircdb.users.itervalues() if p(u.name)]
|
for predicate in predicates:
|
||||||
|
if not predicate(u):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
users.append(u.name)
|
||||||
if users:
|
if users:
|
||||||
utils.sortBy(str.lower, users)
|
utils.sortBy(str.lower, users)
|
||||||
irc.reply(utils.commaAndify(users))
|
irc.reply(utils.commaAndify(users))
|
||||||
else:
|
else:
|
||||||
if glob:
|
if predicates:
|
||||||
irc.reply('There are no matching registered users.')
|
irc.reply('There are no matching registered users.')
|
||||||
else:
|
else:
|
||||||
irc.reply('There are no registered users.')
|
irc.reply('There are no registered users.')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user