optimized uptime code, fixed bug in ping.py

This commit is contained in:
neersighted 2012-03-30 15:04:11 -07:00
parent c0cb9671a1
commit 17ab4e436d
2 changed files with 5 additions and 8 deletions

View file

@ -10,9 +10,9 @@ ping_regex = re.compile(r"(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)")
@hook.command @hook.command
def ping(inp, reply=None): def ping(inp, reply=None):
".ping <host> [count] -- Pings <host> [count] times." ".ping <host> [count] -- Pings <host> [count] times."
if os.name == "nt": if os.name == "nt":
return "Sorry, this command is not supported on Windows systems." return "Sorry, this command is not supported on Windows systems."
args = inp.split(' ') args = inp.split(' ')
host = args[0] host = args[0]

View file

@ -2,8 +2,8 @@ import os
import re import re
import time import time
import string import string
import psutil
import platform import platform
import subprocess
from util import hook from util import hook
def replace(text, wordDic): def replace(text, wordDic):
@ -69,11 +69,8 @@ def mem(inp):
@hook.command(autohelp=False) @hook.command(autohelp=False)
def up(inp): def up(inp):
".up -- Shows the bot's uptime." ".up -- Shows the bot's uptime."
proc = psutil.Process(os.getpid()) up_time = subprocess.check_output("ps -eo pid,etime | grep %s | awk '{print $2}'" % os.getpid(), shell=True)
up_time = proc.create_time up_time = "Uptime: " + up_time
up_time = time.time() - up_time
up_time = time.localtime(up_time)
up_time = time.strftime("Uptime: \x02%M:%S\x02", up_time)
return up_time return up_time
@hook.command("proc", autohelp=False) @hook.command("proc", autohelp=False)