mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added User.list command to list registered users.
This commit is contained in:
parent
4c4fbaccc1
commit
97b8bab611
29
src/User.py
29
src/User.py
@ -39,8 +39,10 @@ import fix
|
|||||||
|
|
||||||
import getopt
|
import getopt
|
||||||
import string
|
import string
|
||||||
|
from itertools import imap, ifilter
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
|
import utils
|
||||||
import ircdb
|
import ircdb
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
@ -54,6 +56,33 @@ class User(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def list(self, irc, msg, args):
|
||||||
|
"""[<glob>]
|
||||||
|
|
||||||
|
Returns the valid registered usernames matching <glob>. If <glob> 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):
|
def register(self, irc, msg, args):
|
||||||
"""[--hashed] <name> <password>
|
"""[--hashed] <name> <password>
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@ class UserTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.prefix = self.prefix2
|
self.prefix = self.prefix2
|
||||||
self.assertNotError('register biff quux')
|
self.assertNotError('register biff quux')
|
||||||
self.assertResponse('user list', 'biff and foo')
|
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.assertNotError('unregister biff quux')
|
||||||
self.assertResponse('user list', 'foo')
|
self.assertResponse('user list', 'foo')
|
||||||
self.assertNotError('unregister foo bar')
|
self.assertNotError('unregister foo bar')
|
||||||
|
Loading…
Reference in New Issue
Block a user