2011-11-20 10:23:31 +01:00
|
|
|
import os
|
|
|
|
import re
|
2012-04-01 21:05:27 +02:00
|
|
|
import time
|
2012-03-30 02:16:31 +02:00
|
|
|
import platform
|
2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
2012-04-01 21:51:02 +02:00
|
|
|
from datetime import timedelta
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-03-30 18:17:31 +02:00
|
|
|
|
|
|
|
@hook.command(autohelp=False)
|
2012-03-31 01:46:10 +02:00
|
|
|
def system(inp):
|
|
|
|
".system -- Retrieves information about the host system."
|
2012-04-01 12:58:14 +02:00
|
|
|
hostname = platform.node()
|
2012-03-31 01:38:31 +02:00
|
|
|
os = platform.platform()
|
2012-04-01 12:58:14 +02:00
|
|
|
python_imp = platform.python_implementation()
|
|
|
|
python_ver = platform.python_version()
|
|
|
|
architecture = '-'.join(platform.architecture())
|
2012-03-30 18:17:31 +02:00
|
|
|
cpu = platform.machine()
|
2012-04-01 13:45:45 +02:00
|
|
|
return "Hostname: \x02%s\x02, Operating System: \x02%s\x02, Python " \
|
|
|
|
"Version: \x02%s %s\x02, Architecture: \x02%s\x02, CPU: \x02%s" \
|
|
|
|
"\x02" % (hostname, os, python_imp, python_ver, architecture, cpu)
|
2012-03-30 18:17:31 +02:00
|
|
|
|
|
|
|
|
2012-03-30 16:58:39 +02:00
|
|
|
@hook.command(autohelp=False)
|
2012-03-31 01:46:10 +02:00
|
|
|
def memory(inp):
|
|
|
|
".memory -- Displays the bot's current memory usage."
|
2012-04-01 13:45:45 +02:00
|
|
|
if os.name == "posix":
|
|
|
|
# get process info
|
|
|
|
status_file = open('/proc/self/status').read()
|
|
|
|
s = dict(re.findall(r'^(\w+):\s*(.*)\s*$', status_file, re.M))
|
|
|
|
# get the data we need and process it
|
|
|
|
data = s['VmRSS'], s['VmSize'], s['VmPeak'], s['VmStk'], s['VmData']
|
2012-04-01 23:29:42 +02:00
|
|
|
data = [float(i.replace(' kB', '')) for i in data]
|
|
|
|
strings = [str(round(i / 1024, 2)) + ' MB' for i in data]
|
2012-04-01 13:45:45 +02:00
|
|
|
# prepare the output
|
2012-04-02 03:45:37 +02:00
|
|
|
out = "Threads: \x02%s\x02, Real Memory: \x02%s\x02, Allocated Memory: \x02%s\x02, Peak " \
|
2012-04-01 13:45:45 +02:00
|
|
|
"Allocated Memory: \x02%s\x02, Stack Size: \x02%s\x02, Heap " \
|
2012-04-02 03:45:37 +02:00
|
|
|
"Size: \x02%s\x02" % (s['Threads'], strings[0], strings[1], strings[2],
|
2012-04-01 13:45:45 +02:00
|
|
|
strings[3], strings[4])
|
|
|
|
# return output
|
|
|
|
return out
|
2012-03-30 16:58:39 +02:00
|
|
|
|
2012-04-01 13:45:45 +02:00
|
|
|
elif os.name == "nt":
|
|
|
|
cmd = 'tasklist /FI "PID eq %s" /FO CSV /NH' % os.getpid()
|
2011-11-20 10:23:31 +01:00
|
|
|
out = os.popen(cmd).read()
|
2012-03-30 21:06:36 +02:00
|
|
|
memory = 0
|
2011-11-20 10:23:31 +01:00
|
|
|
for amount in re.findall(r'([,0-9]+) K', out):
|
2012-03-30 21:06:36 +02:00
|
|
|
memory += int(amount.replace(',', ''))
|
2012-03-31 01:38:31 +02:00
|
|
|
memory = str(round(float(memory) / 1024, 2))
|
2012-04-01 13:45:45 +02:00
|
|
|
return "Memory Usage: \x02%s MB\x02" % memory
|
|
|
|
|
2012-03-30 21:06:36 +02:00
|
|
|
else:
|
2012-04-01 15:01:01 +02:00
|
|
|
return "Sorry, this command is not supported on your OS."
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-03-30 02:16:31 +02:00
|
|
|
|
2012-03-30 18:03:34 +02:00
|
|
|
@hook.command(autohelp=False)
|
2012-04-01 21:05:27 +02:00
|
|
|
def uptime(inp, bot=None):
|
2012-03-31 01:46:10 +02:00
|
|
|
".uptime -- Shows the bot's uptime."
|
2012-04-01 21:51:02 +02:00
|
|
|
uptime_raw = round(time.time() - bot.start_time)
|
|
|
|
uptime = timedelta(seconds=uptime_raw)
|
2012-04-01 21:05:27 +02:00
|
|
|
return "Uptime: \x02%s\x02" % uptime
|
2012-04-01 13:45:45 +02:00
|
|
|
|
2012-03-30 18:03:34 +02:00
|
|
|
|
2012-03-30 02:16:31 +02:00
|
|
|
@hook.command(autohelp=False)
|
2012-03-30 18:17:31 +02:00
|
|
|
def pid(inp):
|
2012-03-30 18:31:36 +02:00
|
|
|
".pid -- Prints the bot's PID."
|
2012-04-01 13:45:45 +02:00
|
|
|
return "PID: \x02%s\x02" % os.getpid()
|