]> jfr.im git - erebus.git/blobdiff - modules/resources.py
userinfo - create json file if it doesnt exist
[erebus.git] / modules / resources.py
index 110b4d55024df076f269f227a1b267d51fbd6f78..27cc7da8c75f7bcfc067fb824c2b974abfac41dd 100644 (file)
@@ -19,9 +19,9 @@ modstop = lib.modstop
 # module code
 import resource
 
-@lib.hook('ram', needchan=False, glevel=lib.MANAGER)
-def cmd_ram(bot, user, chan, realtarget, *args):
-       if chan is not None: replyto = chan
+@lib.hook(needchan=False, glevel=lib.MANAGER)
+def ram(bot, user, chan, realtarget, *args):
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        try:
@@ -31,9 +31,9 @@ def cmd_ram(bot, user, chan, realtarget, *args):
 
        bot.msg(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 chan is not None: replyto = chan
+@lib.hook(needchan=False, glevel=lib.MANAGER)
+def resources(bot, user, chan, realtarget, *args):
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        try:
@@ -42,15 +42,15 @@ def cmd_resources(bot, user, chan, realtarget, *args):
                res = resource.getrusage(resource.RUSAGE_SELF)
 
        bot.msg(replyto, "Resource usage:")
-       for i, v in [
+       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.")