2016-05-09 15:14:12 +00:00
|
|
|
import time
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-05-09 15:14:12 +00:00
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-04 15:01:13 +00:00
|
|
|
def _uptime(self):
|
|
|
|
return utils.to_pretty_time(int(time.time()-self.bot.start_time))
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.uptime")
|
2016-05-09 15:14:12 +00:00
|
|
|
def uptime(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show my uptime
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-10-04 15:01:13 +00:00
|
|
|
event["stdout"].write("Uptime: %s" % self._uptime())
|
|
|
|
@utils.hook("api.uptime")
|
|
|
|
def uptime_api(self, event):
|
|
|
|
return self._uptime()
|
2016-05-09 15:14:12 +00:00
|
|
|
|
2018-10-04 15:01:13 +00:00
|
|
|
def _stats(self):
|
2016-05-09 15:14:12 +00:00
|
|
|
networks = len(self.bot.servers)
|
|
|
|
channels = 0
|
|
|
|
users = 0
|
|
|
|
for server in self.bot.servers.values():
|
|
|
|
channels += len(server.channels)
|
|
|
|
users += len(server.users)
|
2018-10-04 15:01:13 +00:00
|
|
|
return [networks, channels, users]
|
2016-05-09 15:14:12 +00:00
|
|
|
|
2018-10-04 15:01:13 +00:00
|
|
|
@utils.hook("received.command.stats")
|
|
|
|
def stats(self, event):
|
|
|
|
"""
|
|
|
|
:help: Show my network/channel/user stats
|
|
|
|
"""
|
|
|
|
networks, channels, users = self._stats()
|
2016-05-09 15:14:12 +00:00
|
|
|
|
|
|
|
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)
|
2018-10-04 15:01:13 +00:00
|
|
|
|
|
|
|
@utils.hook("api.stats")
|
|
|
|
def stats_api(self, event):
|
|
|
|
networks, channels, users = self._stats()
|
|
|
|
return {"networks": networks, "channels": channels, "users": users}
|