Channel: nicks: add --count argument, which outputs only the count of nicks in channel.

also add tests for the nick command.
This commit is contained in:
Daniel Folkinshteyn 2010-06-13 02:36:18 -04:00 committed by Valentin Lorentz
parent 8e80e7b657
commit da25be73d4
2 changed files with 16 additions and 6 deletions

View File

@ -814,11 +814,12 @@ class Channel(callbacks.Plugin):
additional('commandName')]) additional('commandName')])
@internationalizeDocstring @internationalizeDocstring
def nicks(self, irc, msg, args, channel): def nicks(self, irc, msg, args, channel, optlist):
"""[<channel>] """[<channel>] [--count]
Returns the nicks in <channel>. <channel> is only necessary if the Returns the nicks in <channel>. <channel> is only necessary if the
message isn't sent in the channel itself. message isn't sent in the channel itself. Returns only the number of
nicks if --count option is provided.
""" """
# Make sure we don't elicit information about private channels to # Make sure we don't elicit information about private channels to
# people or channels that shouldn't know # people or channels that shouldn't know
@ -828,9 +829,14 @@ class Channel(callbacks.Plugin):
msg.nick not in irc.state.channels[channel].users): msg.nick not in irc.state.channels[channel].users):
irc.error(_('You don\'t have access to that information.')) irc.error(_('You don\'t have access to that information.'))
L = list(irc.state.channels[channel].users) L = list(irc.state.channels[channel].users)
utils.sortBy(str.lower, L) keys = [option for (option, arg) in optlist]
irc.reply(utils.str.commaAndify(L)) if 'count' not in keys:
nicks = wrap(nicks, ['inChannel']) utils.sortBy(str.lower, L)
irc.reply(utils.str.commaAndify(L))
else:
irc.reply(str(len(L)))
nicks = wrap(nicks, ['inChannel',
getopts({'count':''})])
@internationalizeDocstring @internationalizeDocstring
def alertOps(self, irc, channel, s, frm=None): def alertOps(self, irc, channel, s, frm=None):

View File

@ -214,5 +214,9 @@ class ChannelTestCase(ChannelPluginTestCase):
finally: finally:
conf.supybot.protocols.irc.banmask.setValue(orig) conf.supybot.protocols.irc.banmask.setValue(orig)
def testNicks(self):
self.assertResponse('channel nicks', 'bar, foo, and test')
self.assertResponse('channel nicks --count', '3')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: