3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-02 15:44:06 +01:00

Initial pass at a Stats plugin (#121, #381)

This commit is contained in:
James Lu 2017-01-11 23:35:35 -08:00
parent 165f8fa4a7
commit b1918f5392
2 changed files with 39 additions and 0 deletions

View File

@ -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.

36
plugins/stats.py Normal file
View File

@ -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):
"""[<network>]
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)))