Added new commands; bug fixes
This commit is contained in:
1 parent
c779c5070d
commit
3604e52567
1 file changed
+23
-3
@@ -2,7 +2,14 @@
|
|||||||
#from irc import client, connection
|
#from irc import client, connection
|
||||||
import irc.bot, subprocess
|
import irc.bot, subprocess
|
||||||
import irc.strings
|
import irc.strings
|
||||||
#from irc import connection, client
|
import psutil, platform
|
||||||
|
|
||||||
|
def get_size(bytes, suffix="B"):
|
||||||
|
factor=1024
|
||||||
|
for unit in ["", "K", "M", "G", "T", "P"]:
|
||||||
|
if bytes < factor:
|
||||||
|
return f"{bytes:.2f}{unit}{suffix}"
|
||||||
|
bytes /= factor
|
||||||
|
|
||||||
class TestBot(irc.bot.SingleServerIRCBot):
|
class TestBot(irc.bot.SingleServerIRCBot):
|
||||||
def __init__(self, channel, nickname, server, port=6667):
|
def __init__(self, channel, nickname, server, port=6667):
|
||||||
@@ -24,6 +31,8 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
self.do_command(e, a[1].strip())
|
self.do_command(e, a[1].strip())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def do_command(self, e, cmd):
|
def do_command(self, e, cmd):
|
||||||
nick = e.source.nick
|
nick = e.source.nick
|
||||||
c = self.connection
|
c = self.connection
|
||||||
@@ -38,12 +47,23 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
c.notice(nick, "Opers: " + ", ".join(opers))
|
c.notice(nick, "Opers: " + ", ".join(opers))
|
||||||
voiced = sorted(chobj.voiced())
|
voiced = sorted(chobj.voiced())
|
||||||
c.notice(nick, "Voiced: " + ", ".join(voiced))
|
c.notice(nick, "Voiced: " + ", ".join(voiced))
|
||||||
if cmd == "load":
|
if cmd.lower() == "load":
|
||||||
result = subprocess.run(["uptime" ], stderr=subprocess.PIPE, stdout=subprocess.PIPE) #result.stdout.decode()
|
result = subprocess.run(["uptime" ], stderr=subprocess.PIPE, stdout=subprocess.PIPE) #result.stdout.decode()
|
||||||
output = result.stdout.decode().strip()
|
output = result.stdout.decode().strip()
|
||||||
res = output[output.find('load average'):]
|
res = output[output.find('load average'):]
|
||||||
c.notice(nick, res)
|
c.notice(nick, res)
|
||||||
|
|
||||||
|
if cmd.lower() == "ram":
|
||||||
|
svmem = psutil.virtual_memory()
|
||||||
|
end = 'Used Ram: '+ get_size(svmem.used)
|
||||||
|
c.notice(nick, end)
|
||||||
|
if cmd.lower() == "cpu":
|
||||||
|
percent = psutil.cpu_percent()
|
||||||
|
end = 'CPU load: ' + str(percent) + '%'
|
||||||
|
c.notice(nick, end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
channel = '#notifications'
|
channel = '#notifications'
|
||||||
nickname = 'GandCStat'
|
nickname = 'GandCStat'
|
||||||
|
|||||||
Reference in new issue
Block a user