improvements
This commit is contained in:
11
bot.py
11
bot.py
@@ -21,6 +21,10 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
def __init__(self, channel, nickname, server, port=6667):
|
def __init__(self, channel, nickname, server, port=6667):
|
||||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
||||||
self.channel = channel
|
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):
|
def on_welcome(self, c, e):
|
||||||
c.mode(self._nickname, '+B')
|
c.mode(self._nickname, '+B')
|
||||||
@@ -38,7 +42,7 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def do_command(self, e, cmd):
|
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
|
c = self.connection
|
||||||
if cmd.lower() == "uptime":
|
if cmd.lower() == "uptime":
|
||||||
result = subprocess.run(["uptime"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
result = subprocess.run(["uptime"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
@@ -46,8 +50,6 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
c.privmsg(channel, output)
|
c.privmsg(channel, output)
|
||||||
|
|
||||||
elif cmd.lower() == "uname":
|
elif cmd.lower() == "uname":
|
||||||
# >>> print(f"Version: {uname.version}")
|
|
||||||
# Version: #1 SMP Debian 4.19.208-1 (2021-09-29)
|
|
||||||
uname = platform.uname()
|
uname = platform.uname()
|
||||||
end = 'System name:' + uname.version
|
end = 'System name:' + uname.version
|
||||||
c.privmsg(channel, end)
|
c.privmsg(channel, end)
|
||||||
@@ -66,7 +68,6 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
elif cmd.lower() == "cpu":
|
elif cmd.lower() == "cpu":
|
||||||
percent = psutil.cpu_percent()
|
percent = psutil.cpu_percent()
|
||||||
end = 'CPU load: {}%'.format(percent)
|
end = 'CPU load: {}%'.format(percent)
|
||||||
#c.privmsg(channel, end)
|
|
||||||
c.privmsg(channel, end)
|
c.privmsg(channel, end)
|
||||||
|
|
||||||
elif cmd.lower() == "network":
|
elif cmd.lower() == "network":
|
||||||
@@ -94,6 +95,8 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
|||||||
end = 'Available commands are: help, uptime, ram, cpu, uname, network, temp'
|
end = 'Available commands are: help, uptime, ram, cpu, uname, network, temp'
|
||||||
c.privmsg(channel, end)
|
c.privmsg(channel, end)
|
||||||
|
|
||||||
|
elif cmd.lower() == "stop":
|
||||||
|
exit(1)
|
||||||
else:
|
else:
|
||||||
end = 'Unknow command. Sorry'
|
end = 'Unknow command. Sorry'
|
||||||
c.privmsg(channel, end)
|
c.privmsg(channel, end)
|
||||||
|
|||||||
Reference in New Issue
Block a user