diff --git a/docs/permissions-reference.md b/docs/permissions-reference.md index 78eb755..956d46d 100644 --- a/docs/permissions-reference.md +++ b/docs/permissions-reference.md @@ -89,3 +89,6 @@ Remote versions of the `manage`, `list`, `sync`, and `clear` commands also exist ## Servermaps - `servermaps.map` - Allows access to the `map` and `localmap` commands. + +## Stats +- `stats.uptime` - Allows access to the `stats` command. diff --git a/plugins/stats.py b/plugins/stats.py new file mode 100644 index 0000000..50705b4 --- /dev/null +++ b/plugins/stats.py @@ -0,0 +1,36 @@ +""" +stats.py: Simple statistics for PyLink IRC Services. +""" +import time +import datetime + +from pylinkirc import utils, world +from pylinkirc.log import log +from pylinkirc.coremods import permissions + +def _timesince(before, now): + return str(datetime.timedelta(seconds=now-before)) + +@utils.add_cmd +def uptime(irc, source, args): + """[] + + Returns the uptime for PyLink and the given network's connection (or the current network if not specified).""" + permissions.checkPermissions(irc, source, ['stats.uptime']) + + try: + network = args[0] + except IndexError: + network = irc.name + + try: + ircobj = world.networkobjects[network] + except KeyError: + irc.error("No such network %r." % network) + return + + current_time = int(time.time()) + + irc.reply("PyLink uptime: \x02%s\x02, Connected to %s: \x02%s\x02" % \ + (_timesince(world.start_ts, current_time), network, _timesince(irc.start_ts, current_time))) +