bitbot-3.11-fork/modules/stats.py

38 lines
1.1 KiB
Python
Raw Normal View History

2016-05-09 15:14:12 +00:00
import time
2018-08-18 20:54:12 +00:00
import Utils
2016-05-09 15:14:12 +00:00
class Module(object):
def __init__(self, bot, events, exports):
2016-05-09 15:14:12 +00:00
self.boot_time = time.time()
self.bot = bot
events.on("received").on("command").on("uptime"
2018-08-09 14:16:35 +00:00
).hook(self.uptime, help="Show my uptime")
events.on("received").on("command").on("stats"
2018-08-09 14:16:35 +00:00
).hook(self.stats, help="Show my network/channel/user stats")
2016-05-09 15:14:12 +00:00
def uptime(self, event):
seconds = int(time.time()-self.boot_time)
2018-08-18 20:54:12 +00:00
event["stdout"].write("Uptime: %s" % Utils.to_pretty_time(
seconds))
2016-05-09 15:14:12 +00:00
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)