Added new commands
This commit is contained in:
parent
4e5ff636ef
commit
53e7c01a3c
21
README.md
Normal file
21
README.md
Normal 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
36
bot.py
@ -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)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user