123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- # █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
- # █▀█ █ █ █ █▀█ █▀▄ █
- # © Copyright 2022
- # https://t.me/hikariatama
- #
- # 🔒 Licensed under the GNU AGPLv3
- # 🌐 https://www.gnu.org/licenses/agpl-3.0.html
- # scope: inline
- import logging
- import git
- from telethon.tl.types import Message
- from telethon.utils import get_display_name
- from .. import loader, utils, version
- from ..inline.types import InlineQuery
- logger = logging.getLogger(__name__)
- @loader.tds
- class HikkaInfoMod(loader.Module):
- """Show userbot info"""
- strings = {
- "name": "HikkaInfo",
- "owner": "Owner",
- "version": "Version",
- "build": "Build",
- "prefix": "Prefix",
- "uptime": "Uptime",
- "branch": "Branch",
- "send_info": "Send userbot info",
- "description": "ℹ This will not compromise any sensitive info",
- "up-to-date": "<b>😌 Up-to-date</b>",
- "update_required": "<b>😕 Update required </b><code>.update</code>",
- "_cfg_cst_msg": (
- "Custom message for info. May contain {me}, {version}, {build}, {prefix},"
- " {platform}, {upd}, {uptime}, {branch} keywords"
- ),
- "_cfg_cst_btn": "Custom button for info. Leave empty to remove button",
- "_cfg_banner": "URL to image banner",
- }
- strings_ru = {
- "owner": "Владелец",
- "version": "Версия",
- "build": "Сборка",
- "prefix": "Префикс",
- "uptime": "Аптайм",
- "branch": "Ветка",
- "send_info": "Отправить информацию о юзерботе",
- "description": "ℹ Это не раскроет никакой личной информации",
- "_ihandle_doc_info": "Отправить информацию о юзерботе",
- "up-to-date": "<b>😌 Актуальная версия</b>",
- "update_required": "<b>😕 Требуется обновление </b><code>.update</code>",
- "_cfg_cst_msg": (
- "Кастомный текст сообщения в info. Может содержать ключевые слова {me},"
- " {version}, {build}, {prefix}, {platform}, {upd}, {uptime}, {branch}"
- ),
- "_cfg_cst_btn": (
- "Кастомная кнопка в сообщении в info. Оставь пустым, чтобы убрать кнопку"
- ),
- "_cfg_banner": "Ссылка на баннер-картинку",
- }
- 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.png",
- lambda: self.strings("_cfg_banner"),
- validator=loader.validators.Link(),
- ),
- )
- async def client_ready(self):
- self._me = await self._client.get_me()
- def _render_info(self) -> 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"
- f' href="tg://user?id={self._me.id}">{utils.escape_html(get_display_name(self._me))}</a></b>'
- )
- 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()
- 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(),
- branch=version.branch,
- )
- if self.config["custom_message"]
- else (
- "<b>🌘 Hikka</b>\n"
- f'<b>🤴 {self.strings("owner")}: </b>{me}\n\n'
- f"<b>🔮 {self.strings('version')}: </b>{_version} {build}\n"
- f"<b>🌳 {self.strings('branch')}: </b><code>{version.branch}</code>\n"
- f"{upd}\n\n"
- f"<b>📼 {self.strings('prefix')}: </b>{prefix}\n"
- f"<b>⌚️ {self.strings('uptime')}: </b>{utils.formatted_uptime()}\n"
- f"<b>{platform}</b>\n"
- )
- )
- 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_everyone
- async def info_inline_handler(self, _: InlineQuery) -> dict:
- """Send userbot info"""
- return {
- "title": self.strings("send_info"),
- "description": self.strings("description"),
- "message": self._render_info(),
- "thumb": (
- "https://github.com/hikariatama/Hikka/raw/master/assets/hikka_pfp.png"
- ),
- "reply_markup": self._get_mark(),
- }
- @loader.unrestricted
- async def infocmd(self, message: Message):
- """Send userbot info"""
- await self.inline.form(
- message=message,
- text=self._render_info(),
- reply_markup=self._get_mark(),
- **(
- {"photo": self.config["banner_url"]}
- if self.config["banner_url"]
- else {}
- ),
- )
- @loader.unrestricted
- async def hikkainfocmd(self, message: Message):
- """[en/ru - default en] - Send info aka 'What is Hikka?'"""
- args = utils.get_args_raw(message)
- args = args if args in {"en", "ru"} else "en"
- await utils.answer(
- message,
- "<emoji document_id=6318565919471699564>🌌</emoji>"
- " <b>Hikka</b>\n\nTelegram userbot with a lot of features, like inline"
- " galleries, forms, lists and animated emojis support. Userbot - software,"
- " running on your Telegram account. If you write a command to any chat, it"
- " will get executed right there. Check out live examples at <a"
- ' href="https://github.com/hikariatama/Hikka">GitHub</a>'
- if args == "en"
- else (
- "<emoji document_id=6318565919471699564>🌌</emoji>"
- " <b>Hikka</b>\n\nTelegram юзербот с огромным количеством функций, из"
- " которых: инлайн галереи, формы, списки, а также поддержка"
- " анимированных эмодзи. Юзербот - программа, которая запускается на"
- " твоем Telegram-аккаунте. Когда ты пишешь команду в любом чате, она"
- " сразу же выполняется. Обрати внимание на живые примеры на <a"
- ' href="https://github.com/hikariatama/Hikka">GitHub</a>'
- ),
- )
|