123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- # ©️ 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 = '<b><a href="tg://user?id={}">{}</a></b>'.format(
- self._client.hikka_me.id,
- utils.escape_html(get_display_name(self._client.hikka_me)),
- )
- build = utils.get_commit_url()
- _version = f'<i>{".".join(list(map(str, list(version.__version__))))}</i>'
- prefix = f"«<code>{utils.escape_html(self.get_prefix())}</code>»"
- platform = utils.get_named_platform()
- for emoji, icon in [
- ("🍊", "<emoji document_id=5449599833973203438>🧡</emoji>"),
- ("🍇", "<emoji document_id=5449468596952507859>💜</emoji>"),
- ("❓", "<emoji document_id=5407025283456835913>📱</emoji>"),
- ("🍀", "<emoji document_id=5395325195542078574>🍀</emoji>"),
- ("🦾", "<emoji document_id=5386766919154016047>🦾</emoji>"),
- ("🚂", "<emoji document_id=5359595190807962128>🚂</emoji>"),
- ("🐳", "<emoji document_id=5431815452437257407>🐳</emoji>"),
- ("🕶", "<emoji document_id=5407025283456835913>📱</emoji>"),
- ("🐈⬛", "<emoji document_id=6334750507294262724>🐈⬛</emoji>"),
- ("✌️", "<emoji document_id=5469986291380657759>✌️</emoji>"),
- ("📻", "<emoji document_id=5471952986970267163>💎</emoji>"),
- ]:
- platform = platform.replace(emoji, icon)
- return (
- (
- "<b>🌘 Hikka</b>\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'<b>{{}}</b>\n\n<b>{{}} {self.strings("owner")}:</b> {me}\n\n<b>{{}}'
- f' {self.strings("version")}:</b> {_version} {build}\n<b>{{}}'
- f' {self.strings("branch")}:'
- f"</b> <code>{version.branch}</code>\n{upd}\n\n<b>{{}}"
- f' {self.strings("prefix")}:</b> {prefix}\n<b>{{}}'
- f' {self.strings("uptime")}:'
- f"</b> {utils.formatted_uptime()}\n\n<b>{{}}"
- f' {self.strings("cpu_usage")}:'
- f"</b> <i>~{utils.get_cpu_usage()} %</i>\n<b>{{}}"
- f' {self.strings("ram_usage")}:'
- f"</b> <i>~{utils.get_ram_usage()} MB</i>\n<b>{{}}</b>"
- ).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"
- ),
- "<emoji document_id=5373141891321699086>😎</emoji>",
- "<emoji document_id=5469741319330996757>💫</emoji>",
- "<emoji document_id=5449918202718985124>🌳</emoji>",
- "<emoji document_id=5472111548572900003>⌨️</emoji>",
- "<emoji document_id=5451646226975955576>⌛️</emoji>",
- "<emoji document_id=5431449001532594346>⚡️</emoji>",
- "<emoji document_id=5359785904535774578>💼</emoji>",
- 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"))
|