diff options
| author | 2018-10-04 16:01:13 +0100 | |
|---|---|---|
| committer | 2018-10-04 16:01:13 +0100 | |
| commit | 82b40cc8b2d84d6e88b3be76b9f04ecb87429da0 (patch) | |
| tree | 75918ce74bea443834c4e07f5c42f16ebc990415 /modules/stats.py | |
| parent | Checking for the presence of the seperator in the return from .partition is a (diff) | |
| signature | ||
Add basics of (by-default disabled) REST API
Diffstat (limited to 'modules/stats.py')
| -rw-r--r-- | modules/stats.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/modules/stats.py b/modules/stats.py index 38cb8cd3..f9a35d13 100644 --- a/modules/stats.py +++ b/modules/stats.py @@ -2,27 +2,34 @@ import time from src import ModuleManager, utils class Module(ModuleManager.BaseModule): + def _uptime(self): + return utils.to_pretty_time(int(time.time()-self.bot.start_time)) + @utils.hook("received.command.uptime") def uptime(self, event): """ :help: Show my uptime """ - seconds = int(time.time()-self.bot.start_time) - event["stdout"].write("Uptime: %s" % utils.to_pretty_time( - seconds)) + event["stdout"].write("Uptime: %s" % self._uptime()) + @utils.hook("api.uptime") + def uptime_api(self, event): + return self._uptime() - @utils.hook("received.command.stats") - def stats(self, event): - """ - :help: Show my network/channel/user stats - """ + def _stats(self): networks = len(self.bot.servers) channels = 0 users = 0 for server in self.bot.servers.values(): channels += len(server.channels) users += len(server.users) + return [networks, channels, users] + @utils.hook("received.command.stats") + def stats(self, event): + """ + :help: Show my network/channel/user stats + """ + networks, channels, users = self._stats() response = "I currently have %d network" % networks if networks > 1: @@ -35,3 +42,8 @@ class Module(ModuleManager.BaseModule): response += "s" event["stdout"].write(response) + + @utils.hook("api.stats") + def stats_api(self, event): + networks, channels, users = self._stats() + return {"networks": networks, "channels": channels, "users": users} |
