# ยฉ๏ธ Dan Gazizullin, 2021-2023
# This file is a part of Hikka Userbot
# ๐ https://github.com/hikariatama/Hikka
# You can redistribute it and/or modify it under the terms of the GNU AGPLv3
# ๐ https://www.gnu.org/licenses/agpl-3.0.html
import git
from hikkatl.tl.types import Message
from hikkatl.utils import get_display_name
from .. import loader, utils, version
from ..inline.types import InlineQuery
@loader.tds
class HikkaInfoMod(loader.Module):
"""Show userbot info"""
strings = {"name": "HikkaInfo"}
def __init__(self):
self.config = loader.ModuleConfig(
loader.ConfigValue(
"custom_message",
doc=lambda: self.strings("_cfg_cst_msg"),
),
loader.ConfigValue(
"custom_button",
["๐ Support chat", "https://t.me/hikka_talks"],
lambda: self.strings("_cfg_cst_btn"),
validator=loader.validators.Union(
loader.validators.Series(fixed_len=2),
loader.validators.NoneType(),
),
),
loader.ConfigValue(
"banner_url",
"https://github.com/hikariatama/assets/raw/master/hikka_banner.mp4",
lambda: self.strings("_cfg_banner"),
validator=loader.validators.Link(),
),
)
def _render_info(self, inline: bool) -> str:
try:
repo = git.Repo(search_parent_directories=True)
diff = repo.git.log([f"HEAD..origin/{version.branch}", "--oneline"])
upd = (
self.strings("update_required") if diff else self.strings("up-to-date")
)
except Exception:
upd = ""
me = '{}'.format(
self._client.hikka_me.id,
utils.escape_html(get_display_name(self._client.hikka_me)),
)
build = utils.get_commit_url()
_version = f'{".".join(list(map(str, list(version.__version__))))}'
prefix = f"ยซ{utils.escape_html(self.get_prefix())}
ยป"
platform = utils.get_named_platform()
for emoji, icon in [
("๐", "๐งก"),
("๐", "๐"),
("โ", "๐ฑ"),
("๐", "๐"),
("๐ฆพ", "๐ฆพ"),
("๐", "๐"),
("๐ณ", "๐ณ"),
("๐ถ", "๐ฑ"),
("๐โโฌ", "๐โโฌ"),
("โ๏ธ", "โ๏ธ"),
("๐ป", "๐"),
]:
platform = platform.replace(emoji, icon)
return (
(
"๐ Hikka\n"
if "hikka" not in self.config["custom_message"].lower()
else ""
)
+ self.config["custom_message"].format(
me=me,
version=_version,
build=build,
prefix=prefix,
platform=platform,
upd=upd,
uptime=utils.formatted_uptime(),
cpu_usage=utils.get_cpu_usage(),
ram_usage=f"{utils.get_ram_usage()} MB",
branch=version.branch,
)
if self.config["custom_message"]
else (
f'{{}}\n\n{{}} {self.strings("owner")}: {me}\n\n{{}}'
f' {self.strings("version")}: {_version} {build}\n{{}}'
f' {self.strings("branch")}:'
f" {version.branch}
\n{upd}\n\n{{}}"
f' {self.strings("prefix")}: {prefix}\n{{}}'
f' {self.strings("uptime")}:'
f" {utils.formatted_uptime()}\n\n{{}}"
f' {self.strings("cpu_usage")}:'
f" ~{utils.get_cpu_usage()} %\n{{}}"
f' {self.strings("ram_usage")}:'
f" ~{utils.get_ram_usage()} MB\n{{}}"
).format(
*map(
lambda x: utils.remove_html(x) if inline else x,
(
(
utils.get_platform_emoji()
if self._client.hikka_me.premium and not inline
else "๐ Hikka"
),
"๐",
"๐ซ",
"๐ณ",
"โจ๏ธ",
"โ๏ธ",
"โก๏ธ",
"๐ผ",
platform,
),
)
)
)
def _get_mark(self):
return (
{
"text": self.config["custom_button"][0],
"url": self.config["custom_button"][1],
}
if self.config["custom_button"]
else None
)
@loader.inline_handler(
thumb_url="https://img.icons8.com/external-others-inmotus-design/344/external-Moon-round-icons-others-inmotus-design-2.png"
)
@loader.inline_everyone
async def info(self, _: InlineQuery) -> dict:
"""Send userbot info"""
return {
"title": self.strings("send_info"),
"description": self.strings("description"),
**(
{"photo": self.config["banner_url"], "caption": self._render_info(True)}
if self.config["banner_url"]
else {"message": self._render_info(True)}
),
"thumb": (
"https://github.com/hikariatama/Hikka/raw/master/assets/hikka_pfp.png"
),
"reply_markup": self._get_mark(),
}
@loader.command()
async def infocmd(self, message: Message):
if self.config["custom_button"]:
await self.inline.form(
message=message,
text=self._render_info(True),
reply_markup=self._get_mark(),
**(
{"photo": self.config["banner_url"]}
if self.config["banner_url"]
else {}
),
)
else:
await utils.answer_file(
message,
self.config["banner_url"],
self._render_info(False),
)
@loader.command()
async def hikkainfo(self, message: Message):
await utils.answer(message, self.strings("desc"))
@loader.command()
async def setinfo(self, message: Message):
if not (args := utils.get_args_html(message)):
return await utils.answer(message, self.strings("setinfo_no_args"))
self.config["custom_message"] = args
await utils.answer(message, self.strings("setinfo_success"))