message to nick
This commit is contained in:
parent
f7f44d5556
commit
3f8cc40ac0
30
bot.py
30
bot.py
@ -6,7 +6,9 @@ from sys import argv
|
||||
channel = argv[1]
|
||||
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"]:
|
||||
@ -41,14 +43,14 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
if cmd.lower() == "uptime":
|
||||
result = subprocess.run(["uptime"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
output = result.stdout.decode().strip()
|
||||
c.privmsg(channel, output)
|
||||
c.privmsg(nick, 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)
|
||||
c.privmsg(nick, end)
|
||||
|
||||
elif cmd.lower() == "ram":
|
||||
svmem = psutil.virtual_memory()
|
||||
@ -56,45 +58,45 @@ class TestBot(irc.bot.SingleServerIRCBot):
|
||||
used = 'Used Ram: ' + get_size(svmem.used)
|
||||
percentage = 'Percent:' + str(svmem.percent) + '%'
|
||||
avail = 'Available:' + get_size(svmem.available)
|
||||
c.privmsg(channel, total)
|
||||
c.privmsg(channel, avail)
|
||||
c.privmsg(channel, used)
|
||||
c.privmsg(channel, percentage)
|
||||
c.privmsg(nick, total)
|
||||
c.privmsg(nick, avail)
|
||||
c.privmsg(nick, used)
|
||||
c.privmsg(nick, percentage)
|
||||
|
||||
elif cmd.lower() == "cpu":
|
||||
percent = psutil.cpu_percent()
|
||||
end = 'CPU load: {}%'.format(percent)
|
||||
#c.privmsg(channel, end)
|
||||
c.privmsg(channel, end)
|
||||
c.privmsg(nick, end)
|
||||
|
||||
elif cmd.lower() == "network":
|
||||
if_addrs = psutil.net_if_addrs()
|
||||
for interface_name, interface_addresses in if_addrs.items():
|
||||
header = 'Interface: ' + interface_name
|
||||
c.privmsg(channel, header)
|
||||
c.privmsg(nick, header)
|
||||
for address in interface_addresses:
|
||||
if str(address.family) == 'AddressFamily.AF_INET':
|
||||
ip = 'IP Address: ' + address.address
|
||||
mask = 'Netmask: ' + address.netmask
|
||||
c.privmsg(channel, ' {} / {}'.format(ip, mask))
|
||||
c.privmsg(nick, ' {} / {}'.format(ip, mask))
|
||||
|
||||
elif cmd.lower() == 'temp':
|
||||
temperatures = psutil.sensors_temperatures()
|
||||
for name, device_temp in temperatures.items():
|
||||
header = 'Device: ' + name
|
||||
c.privmsg(channel, header)
|
||||
c.privmsg(nick, header)
|
||||
for sensor in device_temp:
|
||||
sensor_name = sensor.label
|
||||
if not sensor_name: sensor_name = '<no name>'
|
||||
c.privmsg(channel, ' Sensor name: {}, current: {}'.format(sensor_name, sensor.current))
|
||||
c.privmsg(nick, ' Sensor name: {}, current: {}'.format(sensor_name, sensor.current))
|
||||
|
||||
elif cmd.lower() == "help":
|
||||
end = 'Available commands are: help, uptime, ram, cpu, uname, network, temp'
|
||||
c.privmsg(channel, end)
|
||||
c.privmsg(nick, end)
|
||||
|
||||
else:
|
||||
end = 'Unknow command. Sorry'
|
||||
c.privmsg(channel, end)
|
||||
c.privmsg(nick, end)
|
||||
def main():
|
||||
bot = TestBot(channel, nickname, server)
|
||||
bot.start()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user