improvements
This commit is contained in:
parent
994a5425da
commit
41fe31f477
13
bot.py
13
bot.py
@ -8,7 +8,7 @@ nickname = argv[2]
|
||||
server = argv[3]
|
||||
if len(argv) !=4:
|
||||
print('Usage: {} channel nickname server'.format(argv[0]))
|
||||
|
||||
|
||||
def get_size(bytes, suffix="B"):
|
||||
factor = 1024
|
||||
for unit in ["", "K", "M", "G", "T", "P"]:
|
||||
@ -21,6 +21,10 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
def __init__(self, channel, nickname, server, port=6667):
|
||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
||||
self.channel = channel
|
||||
self.connection.add_global_handler('disconnect', self.on_disconnect)
|
||||
|
||||
def on_disconnect(self, connection, event):
|
||||
exit(1)
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
c.mode(self._nickname, '+B')
|
||||
@ -38,7 +42,7 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
return
|
||||
|
||||
def do_command(self, e, cmd):
|
||||
#nick = e.source.nick
|
||||
#nick = e.source.nick ## Uncomment when need to send to user not channel
|
||||
c = self.connection
|
||||
if cmd.lower() == "uptime":
|
||||
result = subprocess.run(["uptime"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
@ -46,8 +50,6 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
c.privmsg(channel, output)
|
||||
|
||||
elif cmd.lower() == "uname":
|
||||
# >>> print(f"Version: {uname.version}")
|
||||
# Version: #1 SMP Debian 4.19.208-1 (2021-09-29)
|
||||
uname = platform.uname()
|
||||
end = 'System name:' + uname.version
|
||||
c.privmsg(channel, end)
|
||||
@ -66,7 +68,6 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
elif cmd.lower() == "cpu":
|
||||
percent = psutil.cpu_percent()
|
||||
end = 'CPU load: {}%'.format(percent)
|
||||
#c.privmsg(channel, end)
|
||||
c.privmsg(channel, end)
|
||||
|
||||
elif cmd.lower() == "network":
|
||||
@ -94,6 +95,8 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
end = 'Available commands are: help, uptime, ram, cpu, uname, network, temp'
|
||||
c.privmsg(channel, end)
|
||||
|
||||
elif cmd.lower() == "stop":
|
||||
exit(1)
|
||||
else:
|
||||
end = 'Unknow command. Sorry'
|
||||
c.privmsg(channel, end)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user