Added new commands; bug fixes

This commit is contained in:
GandC Snow 2021-10-10 18:53:20 +03:00
parent c779c5070d
commit 3604e52567

26
bot.py
View File

@ -2,7 +2,14 @@
#from irc import client, connection
import irc.bot, subprocess
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):
def __init__(self, channel, nickname, server, port=6667):
@ -24,6 +31,8 @@ class TestBot(irc.bot.SingleServerIRCBot):
self.do_command(e, a[1].strip())
return
def do_command(self, e, cmd):
nick = e.source.nick
c = self.connection
@ -38,12 +47,23 @@ class TestBot(irc.bot.SingleServerIRCBot):
c.notice(nick, "Opers: " + ", ".join(opers))
voiced = sorted(chobj.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()
output = result.stdout.decode().strip()
res = output[output.find('load average'):]
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():
channel = '#notifications'
nickname = 'GandCStat'