From da25be73d439550c83e311d61362824d8699c6c0 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Sun, 13 Jun 2010 02:36:18 -0400 Subject: [PATCH] Channel: nicks: add --count argument, which outputs only the count of nicks in channel. also add tests for the nick command. --- plugins/Channel/plugin.py | 18 ++++++++++++------ plugins/Channel/test.py | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 982c9017a..f483c800b 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -814,11 +814,12 @@ class Channel(callbacks.Plugin): additional('commandName')]) @internationalizeDocstring - def nicks(self, irc, msg, args, channel): - """[] + def nicks(self, irc, msg, args, channel, optlist): + """[] [--count] Returns the nicks in . 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 # people or channels that shouldn't know @@ -828,9 +829,14 @@ class Channel(callbacks.Plugin): msg.nick not in irc.state.channels[channel].users): irc.error(_('You don\'t have access to that information.')) L = list(irc.state.channels[channel].users) - utils.sortBy(str.lower, L) - irc.reply(utils.str.commaAndify(L)) - nicks = wrap(nicks, ['inChannel']) + keys = [option for (option, arg) in optlist] + if 'count' not in keys: + utils.sortBy(str.lower, L) + irc.reply(utils.str.commaAndify(L)) + else: + irc.reply(str(len(L))) + nicks = wrap(nicks, ['inChannel', + getopts({'count':''})]) @internationalizeDocstring def alertOps(self, irc, channel, s, frm=None): diff --git a/plugins/Channel/test.py b/plugins/Channel/test.py index 67ba108a3..54ce68ac5 100644 --- a/plugins/Channel/test.py +++ b/plugins/Channel/test.py @@ -214,5 +214,9 @@ class ChannelTestCase(ChannelPluginTestCase): finally: 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: