Added new commands

This commit is contained in:
GandC Snow 2021-10-17 20:28:34 +03:00
parent 4e5ff636ef
commit 53e7c01a3c
2 changed files with 53 additions and 4 deletions

21
README.md Normal file
View File

@ -0,0 +1,21 @@
Info bot
========
Statbot -- это irc бот, который может рассказать вам о загруженности вашего пк.
installing
----------
```bash
pip3 install irc psutil
```
Using
-----
```bash
python3 bot.py
```
Commands
--------
Всего доступно 7 команд: help, stats, uptime, ram, cpu, uname, network. По желанию вы можете добавить свои.

36
bot.py
View File

@ -50,17 +50,45 @@ class TestBot(irc.bot.SingleServerIRCBot):
output = result.stdout.decode().strip()
#res = output[output.find('load average'):]
c.notice(nick, output)
if 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.notice(nick, end)
if cmd.lower() == "ram":
svmem = psutil.virtual_memory()
end = 'Used Ram: '+ get_size(svmem.used)
c.notice(nick, end)
total = 'Total RAM:' + get_size(svmem.total)
used = 'Used Ram: '+ get_size(svmem.used)
percentage ='Percent:' + str(svmem.percent) + '%'
avail = 'Available:' + get_size(svmem.available)
c.notice(nick, total)
c.notice(nick, avail)
c.notice(nick, used)
c.notice(nick, percentage)
if cmd.lower() == "cpu":
percent = psutil.cpu_percent()
end = 'CPU load: ' + str(percent) + '%'
c.notice(nick, end)
if cmd.lower() == "network":
if_addrs = psutil.net_if_addrs()
for interface_name, interface_addresses in if_addrs.items():
for address in interface_addresses:
#print(f"=== Interface: {interface_name} ===")
header = 'Interface:' + interface_name
c.notice(nick, header)
if str(address.family) == 'AddressFamily.AF_INET':
IP = 'IP Address:' + address.address
mask = 'Netmask:' + address.netmask
c.notice(nick, IP)
c.notice(nick, mask)
if cmd.lower() == "help":
end = 'Available commands are: help, stats, uptime, ram, cpu'
end = 'Available commands are: help, stats, uptime, ram, cpu, uname, network'
c.notice(nick, end)