from .. import loader, utils
import git
import platform
import psutil
import time
import os
from telethon.tl.types import MessageEntityUrl
import re
__version__ = (1, 1, 0)
# meta developer: @kmodules
@loader.tds
class CustomInfoMod(loader.Module):
"""Улучшенная информация о юзерботе - ping, и т.д."""
strings = {
"name": "K:CustomInfo",
"update_available": "Доступно обновление!",
"latest_version": "У вас последняя версия.",
"old_format_warning": "✏️ Тег {system_info} устарел. Используйте:\n\n{ram_using} - использованная RAM\n{ram_total} - всего RAM\n{rom_using} - использованная память\n{rom_total} - всего памяти"
}
def __init__(self):
self.config = loader.ModuleConfig(
"custom_info_text",
"✅ K:CustomInfo\n\n"
"©️ Владелец: {owner}\n\n"
"⚡ Версия: {version}\n"
"✨ Ветка: {branch}\n"
"🔥 {update_status}\n\n"
"⭐ Ping: {ping} мс\n"
"⌛ Аптайм: {uptime}\n"
"💡 Префикс: «{prefix}»\n\n"
"🎤 RAM сервера: {ram_using} GB | {ram_total} GB\n"
"⚙ Память: {rom_using} GB | {rom_total} GB\n\n"
"🥷 OC: {os_name} {os_version}\n"
"🎲 Процессор: {cpu_info}",
lambda: "Шаблон для вывода информации",
"banner_url",
"https://x0.at/7uTU.mp4",
lambda: "URL баннера, который будет отправлен с информацией (None чтобы отключить)"
)
async def client_ready(self, client, db):
self.client = client
self.db = db
self._client = client
def get_cpu_info(self):
try:
with open("/proc/cpuinfo", "r") as f:
for line in f:
if "model name" in line:
return line.split(":")[1].strip()
except:
return platform.processor() or "Unknown"
def get_ram_info(self):
try:
ram = psutil.virtual_memory()
total = round(ram.total / (1024**3), 2)
used = round(ram.used / (1024**3), 2)
return used, total
except:
return 0, 0
def get_disk_info(self):
try:
disk = psutil.disk_usage('/')
total = round(disk.total / (1024**3), 2)
used = round(disk.used / (1024**3), 2)
return used, total
except:
return 0, 0
@loader.command()
async def cinfo(self, message):
"""Показать информацию о юзерботе"""
try:
repo = git.Repo(search_parent_directories=True)
branch = repo.active_branch.name
diff = repo.git.log([f"HEAD..origin/{branch}", "--oneline"])
update_status = self.strings["update_available"] if diff else self.strings["latest_version"]
except:
branch = "unknown"
update_status = "Невозможно проверить обновления"
start = time.perf_counter_ns()
msg = await message.client.send_message("me", '⏳')
ping = round((time.perf_counter_ns() - start) / 10**6, 3)
await msg.delete()
ram_used, ram_total = self.get_ram_info()
disk_used, disk_total = self.get_disk_info()
template = self.config["custom_info_text"]
# Create format dict
format_dict = {
"owner": self._client.hikka_me.first_name + ' ' + (self._client.hikka_me.last_name or ''),
"version": '3.0.0',
"branch": branch,
"update_status": update_status,
"prefix": self.get_prefix(),
"ping": ping,
"uptime": utils.formatted_uptime(),
"ram_using": ram_used,
"ram_total": ram_total,
"rom_using": disk_used,
"rom_total": disk_total,
"os_name": platform.system(),
"os_version": platform.release(),
"cpu_info": self.get_cpu_info()
}
# If old format is used, add system_info to format dict
if "{system_info}" in template:
format_dict["system_info"] = self.strings["old_format_warning"]
info = template.format(**format_dict)
reply_to = await message.get_reply_message()
thread = getattr(message, 'message_thread_id', None)
if self.config["banner_url"]:
await self.client.send_file(
message.peer_id,
self.config["banner_url"],
caption=info,
reply_to=reply_to.id if reply_to else None,
message_thread_id=thread
)
if message.out:
await message.delete()
else:
await utils.answer(
message,
info
)
@loader.command()
async def setcinfo(self, message):
"""Установить кастомный текст информации: .setcinfo <текст>"""
args = utils.get_args_raw(message)
if not args:
await utils.answer(message, "🧠 Укажите текст для кастомной информации!")
return
self.config["custom_info_text"] = args
await utils.answer(message, "🧠 K:CustomInfo - текст поставлен.")