Added cmdstats command.

This commit is contained in:
Jeremy Fincher 2003-09-30 11:04:44 +00:00
parent ce3043a50f
commit 8b04e1c537
2 changed files with 28 additions and 6 deletions

View File

@ -97,16 +97,37 @@ class Status(callbacks.Privmsg):
'children have taken %s seconds of user time and %s seconds'\
' of system time for a total of %s seconds of CPU time. ' \
'I\'ve taken a total of %s%% of this computer\'s time. ' \
'Out of %s I have %s active. ' \
'I have processed %s.' %\
'Out of %s I have %s active. ' % \
(user, system, user + system,
childUser, childSystem, childUser + childSystem,
(user+system+childUser+childSystem)/timeRunning,
utils.nItems(world.threadsSpawned, 'thread', 'spawned'),
activeThreads,
utils.nItems(world.commandsProcessed, 'command'))
activeThreads)
irc.reply(msg, response)
def cmdstats(self, irc, msg, args):
"""takes no arguments
Returns some interesting command-related statistics.
"""
commands = sets.Set()
callbacksPrivmsgs = 0
for cb in irc.callbacks:
if isinstance(cb, callbacks.Privmsg) and cb.public:
callbacksPrivmsgs += 1
for attr in dir(cb):
if cb.isCommand(attr):
commands.add(attr)
commands = list(commands)
commands.sort()
s = 'I offer a total of %s in %s. ' \
'I have processed %s. My public commands include %s.' % \
(utils.nItems(len(commands), 'command'),
utils.nItems(callbacksPrivmsgs, 'plugin', 'command-based'),
utils.nItems(world.commandsProcessed, 'command'),
utils.commaAndify(commands))
irc.reply(msg, s)
def uptime(self, irc, msg, args):
"""takes no arguments.
@ -117,8 +138,6 @@ class Status(callbacks.Privmsg):
irc.reply(msg, response)
Class = Status
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -42,6 +42,9 @@ class StatusTestCase(PluginTestCase, PluginDocumentation):
def testUptime(self):
self.assertNotError('uptime')
def testCmdstats(self):
self.assertNotError('cmdstats')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: