mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-24 03:04:05 +01:00
Merge branch 'wip/stats' into devel
This commit is contained in:
commit
1c19d82f53
@ -89,3 +89,6 @@ Remote versions of the `manage`, `list`, `sync`, and `clear` commands also exist
|
|||||||
|
|
||||||
## Servermaps
|
## Servermaps
|
||||||
- `servermaps.map` - Allows access to the `map` and `localmap` commands.
|
- `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
36
plugins/stats.py
Normal 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)))
|
||||||
|
|
2
world.py
2
world.py
@ -4,6 +4,7 @@ world.py: Stores global variables for PyLink, including lists of active IRC obje
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
# This indicates whether we're running in tests mode. What it actually does
|
# This indicates whether we're running in tests mode. What it actually does
|
||||||
# though is control whether IRC connections should be threaded or not.
|
# though is control whether IRC connections should be threaded or not.
|
||||||
@ -21,6 +22,7 @@ exttarget_handlers = {}
|
|||||||
|
|
||||||
# Trigger to be set when all IRC objects are initially created.
|
# Trigger to be set when all IRC objects are initially created.
|
||||||
started = threading.Event()
|
started = threading.Event()
|
||||||
|
start_ts = time.time()
|
||||||
|
|
||||||
# Source address.
|
# Source address.
|
||||||
source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
|
source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
|
||||||
|
Loading…
Reference in New Issue
Block a user