]> jfr.im git - erebus.git/blobdiff - modules/resources.py
added softdeps to modinfo - bumped APIVERSION
[erebus.git] / modules / resources.py
index 1a4e3c5ed902156efea58aedb695fc098cb611c2..016e4bdb85913ada2775615eff5f5b1becc4ffe0 100644 (file)
@@ -1,13 +1,14 @@
 # Erebus IRC bot - Author: Erebus Team
-# simple module example
+# resource-usage module
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble
@@ -19,9 +20,10 @@ modstop = lib.modstop
 # module code
 import resource
 
-@lib.hook('ram', needchan=False, glevel=lib.MANAGER)
-def cmd_ram(bot, user, chan, realtarget, *args):
-       if realtarget == chan.name: replyto = chan
+@lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help(None, "show RAM usage")
+def ram(bot, user, chan, realtarget, *args):
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        try:
@@ -29,11 +31,12 @@ def cmd_ram(bot, user, chan, realtarget, *args):
        except:
                res = resource.getrusage(resource.RUSAGE_SELF)
 
-       bot.msg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
+       bot.fastmsg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
 
-@lib.hook('resources', needchan=False, glevel=lib.MANAGER)
-def cmd_resources(bot, user, chan, realtarget, *args):
-       if realtarget == chan.name: replyto = chan
+@lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help(None, "show resource usage")
+def resources(bot, user, chan, realtarget, *args):
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        try:
@@ -41,16 +44,16 @@ def cmd_resources(bot, user, chan, realtarget, *args):
        except:
                res = resource.getrusage(resource.RUSAGE_SELF)
 
-       bot.msg(replyto, "Resource usage:")
-       for i, v in [
+       bot.slowmsg(replyto, "Resource usage:")
+       for i, v in (
                ('utime (s)', res.ru_utime),
                ('stime (s)', res.ru_stime),
-               ('memory (MiB)', (res.ru_maxrss/1024.0))
+               ('memory (MiB)', (res.ru_maxrss/1024.0)),
                ('I/O (blocks)', res.ru_inblock+res.ru_oublock),
                ('page faults', res.ru_majflt),
                ('signals', res.ru_nsignals),
                ('context switches (voluntary)', res.ru_nvcsw),
                ('context switches (involuntary)', res.ru_nivcsw),
-       ]:
-               bot.msg(replyto, "- %s: %r" % (i, v))
-       bot.msg(replyto, "EOL.")
+       ):
+               bot.slowmsg(replyto, "- %s: %r" % (i, v))
+       bot.slowmsg(replyto, "EOL.")