# ______ ___ ___ _ _
# ____ | ___ \ | \/ | | | | |
# / __ \| |_/ / _| . . | ___ __| |_ _| | ___
# / / _` | __/ | | | |\/| |/ _ \ / _` | | | | |/ _ \
# | | (_| | | | |_| | | | | (_) | (_| | |_| | | __/
# \ \__,_\_| \__, \_| |_/\___/ \__,_|\__,_|_|\___|
# \____/ __/ |
# |___/
# На модуль распространяется лицензия "GNU General Public License v3.0"
# https://github.com/all-licenses/GNU-General-Public-License-v3.0
# meta developer: @pymodule
# requires: psutil
from .. import loader, utils
import platform, psutil, socket, time, getpass, telethon
import os
def bytes2human(n):
symbols = ('B','K','M','G','T','P')
prefix = {s:1<<(i*10) for i,s in enumerate(symbols[1:],1)}
for s in reversed(symbols[1:]):
if n >= prefix[s]:
return f"{n/prefix[s]:.2f}{s}"
return f"{n}B"
def format_uptime(sec):
m, s = divmod(sec, 60); h, m = divmod(m, 60); d, h = divmod(h, 24)
return f"{int(d)}d {int(h)}h {int(m)}m"
def get_distro_info():
name = ver = "N/A"
try:
with open("/etc/os-release") as f:
data = dict(line.strip().split("=", 1) for line in f if "=" in line)
name = data.get("PRETTY_NAME", data.get("NAME", "Unknown")).strip('"')
ver = data.get("VERSION_ID", "").strip('"')
except: pass
return name, ver
def get_cpu_model():
try:
with open("/proc/cpuinfo") as f:
for line in f:
if "model name" in line:
return line.split(":",1)[1].strip()
except: pass
return platform.processor() or "Unknown"
@loader.tds
class SysInfoMod(loader.Module):
"""System information."""
strings = {"name": "SysInfo"}
@loader.command(doc="🔧 Shows information about the system.", ru_doc="🔧 Показывает информацию о системе.")
async def sysinfo(self, message):
me = await message.client.get_me()
is_saved = message.chat_id == me.id
uname = platform.uname()
boot = psutil.boot_time()
uptime = time.time() - boot
freq = psutil.cpu_freq()
load = psutil.cpu_percent(interval=0.5)
user = getpass.getuser()
vm, sm = psutil.virtual_memory(), psutil.swap_memory()
net = psutil.net_io_counters()
io = psutil.disk_io_counters()
distro_name, distro_ver = get_distro_info()
cpu_model = get_cpu_model()
ip_addrs = []
mac_addrs = []
net_info = []
for iface, addrs in psutil.net_if_addrs().items():
ip = mac = "—"
for addr in addrs:
if addr.family == socket.AF_INET:
ip = addr.address
ip_addrs.append(ip)
elif hasattr(socket, 'AF_PACKET') and addr.family == socket.AF_PACKET:
mac = addr.address
mac_addrs.append(mac)
net_info.append(f"{iface}: IP {ip}, MAC {mac}")
freq_str = f"{freq.current:.0f} MHz" if freq else "N/A"
text = (
f"
" ) await utils.answer(message, text)📟 System Info\n\n" f"🖥️ ОС и система:\n" f"OS:{uname.system} {uname.release}\n" f"Distro:{distro_name} {distro_ver}\n" f"Kernel:{uname.version}\n" f"Arch:{uname.machine}\n" f"User:{user}\n\n" f"⚙️ CPU:\n" f"Model:{cpu_model}\n" f"Cores:{psutil.cpu_count(logical=False)}/{psutil.cpu_count(logical=True)}\n" f"Freq:{freq_str}\n" f"Load:{load}%\n\n" f"🧠 RAM:\n" f"Used:{bytes2human(vm.used)}/{bytes2human(vm.total)}\n" f"Swap:{bytes2human(sm.used)}/{bytes2human(sm.total)}\n\n" f"💾 Диск:\n" f"Read:{bytes2human(io.read_bytes)}\n" f"Write:{bytes2human(io.write_bytes)}\n\n" f"📡 Сеть:\n" f"Recv:{bytes2human(net.bytes_recv)}\n" f"Sent:{bytes2human(net.bytes_sent)}\n" f"{chr(10).join(net_info)}\n\n" f"⏱ Аптайм:\n" f"Since:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(boot))}\n" f"Uptime:{format_uptime(uptime)}\n\n" f"📦 Версии:\n" f"Python:{platform.python_version()}\n" f"Telethon:{telethon.__version__}