aboutsummaryrefslogtreecommitdiff
path: root/modules/stats.py
diff options
context:
space:
mode:
authorGravatar jesopo2016-05-09 16:14:12 +0100
committerGravatar jesopo2016-05-09 16:14:12 +0100
commite31d606d16859cc743ebf757d48445f244cf0253 (patch)
tree3924f07999aa0c06bce7c3deb8d66b3a0f6d3e4d /modules/stats.py
parentAnother quote (diff)
added stats.py.
Diffstat (limited to 'modules/stats.py')
-rw-r--r--modules/stats.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/stats.py b/modules/stats.py
new file mode 100644
index 00000000..7318ea5c
--- /dev/null
+++ b/modules/stats.py
@@ -0,0 +1,52 @@
+import time
+
+class Module(object):
+ def __init__(self, bot):
+ self.boot_time = time.time()
+ self.bot = bot
+ bot.events.on("received").on("command").on("uptime"
+ ).hook(self.uptime)
+ bot.events.on("received").on("command").on("stats"
+ ).hook(self.stats)
+
+ def uptime(self, event):
+ seconds = int(time.time()-self.boot_time)
+ minutes = int(seconds/60)
+ if not minutes:
+ event["stdout"].write("Uptime: %s seconds" % seconds)
+ return
+ hours, minutes = int(minutes/60), int(minutes%60)
+ days, hours = int(hours/24), int(hours%24)
+
+ days_str = ""
+ hours_str = "00"
+ minutes_str = "00"
+ if days:
+ days_str = "days "
+ if hours:
+ hours_str = str(hours).zfill(2)
+ if minutes:
+ minutes_str = str(minutes).zfill(2)
+ event["stdout"].write("Uptime: %s%s:%s" % (days_str, hours_str,
+ minutes_str))
+
+ def stats(self, event):
+ networks = len(self.bot.servers)
+ channels = 0
+ users = 0
+ for server in self.bot.servers.values():
+ channels += len(server.channels)
+ users += len(server.users)
+
+
+ response = "I currently have %d network" % networks
+ if networks > 1:
+ response += "s"
+ response += ", %d channel" % channels
+ if channels > 1:
+ response += "s"
+ response += " and %d visible user" % users
+ if users > 1:
+ response += "s"
+
+ event["stdout"].write(response)