From 97b8bab6115e2365aba5a62a697731df8146baa0 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 1 Dec 2003 20:57:00 +0000 Subject: [PATCH] Added User.list command to list registered users. --- src/User.py | 29 +++++++++++++++++++++++++++++ test/test_User.py | 3 +++ 2 files changed, 32 insertions(+) diff --git a/src/User.py b/src/User.py index 0aeae9f92..443a2c637 100755 --- a/src/User.py +++ b/src/User.py @@ -39,8 +39,10 @@ import fix import getopt import string +from itertools import imap, ifilter import conf +import utils import ircdb import ircutils import privmsgs @@ -54,6 +56,33 @@ class User(callbacks.Privmsg): else: return True + def list(self, irc, msg, args): + """[] + + Returns the valid registered usernames matching . If is + not given, returns all registered usernames. + """ + glob = privmsgs.getArgs(args, required=0, optional=1) + if glob: + if '*' not in glob and '?' not in glob: + glob = '*%s*' % glob + def p(s): + return fnmatch.fnmatch(s, glob) + else: + def p(s): + return True + users = ifilter(p, ifilter(None, ircdb.users.users)) + users = [u.name for u in users] + assert users, 'There should be a bot user first.' + if users[0] != irc.nick: + self.log.warning('First user isn\'t the bot nick: %s' % users[0]) + del users[0] # The bot user. Implementation detail. + if users: + utils.sortBy(str.lower, users) + irc.reply(msg, utils.commaAndify(users)) + else: + irc.reply(msg, 'There are no registered users.') + def register(self, irc, msg, args): """[--hashed] diff --git a/test/test_User.py b/test/test_User.py index 31d4c4e8a..94ca36a19 100644 --- a/test/test_User.py +++ b/test/test_User.py @@ -52,6 +52,9 @@ class UserTestCase(PluginTestCase, PluginDocumentation): self.prefix = self.prefix2 self.assertNotError('register biff quux') self.assertResponse('user list', 'biff and foo') + self.assertResponse('user list f', 'biff and foo') + self.assertResponse('user list f*', 'foo') + self.assertResponse('user list *f', 'biff') self.assertNotError('unregister biff quux') self.assertResponse('user list', 'foo') self.assertNotError('unregister foo bar')