Switched to cross-platform uptime code

This commit is contained in:
Luke Rogers 2012-04-02 07:05:27 +12:00
parent c4df4c5b2b
commit 0894908ad5
2 changed files with 6 additions and 6 deletions

1
bot.py
View file

@ -16,6 +16,7 @@ class Bot(object):
print 'Welcome to Cloudbot - Version DEV - http://git.io/cloudbotirc' print 'Welcome to Cloudbot - Version DEV - http://git.io/cloudbotirc'
bot = Bot() bot = Bot()
bot.start_time = time.time()
print 'Loading plugins...' print 'Loading plugins...'

View file

@ -1,5 +1,6 @@
import os import os
import re import re
import time
import platform import platform
import subprocess import subprocess
from util import hook from util import hook
@ -52,13 +53,11 @@ def memory(inp):
@hook.command(autohelp=False) @hook.command(autohelp=False)
def uptime(inp): def uptime(inp, bot=None):
".uptime -- Shows the bot's uptime." ".uptime -- Shows the bot's uptime."
if os.name != "posix": uptime_raw = time.time() - bot.start_time
return "Sorry, this command is not supported on your OS." uptime = time.strftime('%H:%M:%S', time.gmtime(uptime_raw))
up = subprocess.check_output("ps -eo pid,etime | grep %s | awk " \ return "Uptime: \x02%s\x02" % uptime
"'{print $2}'" % os.getpid(), shell=True)
return "Uptime: \x02%s\x02" % up
@hook.command(autohelp=False) @hook.command(autohelp=False)