# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀ # █▀█ █ █ █ █▀█ █▀▄ █ # © Copyright 2022 # https://t.me/hikariatama # # 🔒 Licensed under the GNU AGPLv3 # 🌐 https://www.gnu.org/licenses/agpl-3.0.html import difflib import inspect import logging from telethon.tl.types import Message from .. import loader, utils logger = logging.getLogger(__name__) @loader.tds class HelpMod(loader.Module): """Shows help for modules and commands""" strings = { "name": "Help", "bad_module": "🚫 Module {} not found", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 No docs", "all_header": ( "🌘 {} mods available," " {} hidden:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 Specify module to hide", "hidden_shown": ( "🌘 {} modules hidden," " {} modules shown:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 No docs", "support": ( "{} Link to support chat" ), "partial_load": ( "☝️ Userbot is not" " fully loaded, so not all modules are shown" ), "not_exact": ( "☝️ No exact match" " occured, so the closest result is shown instead" ), "request_join": "You requested link for Hikka support chat", "core_notice": ( "☝️ This is a core" " module. You can't unload it nor replace" ), } strings_ru = { "bad_module": "🚫 Модуль {} не найден", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 Нет описания", "all_header": ( "🌘 {} модулей доступно," " {} скрыто:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 Укажи модуль(-и), которые нужно скрыть", "hidden_shown": ( "🌘 {} модулей скрыто," " {} модулей показано:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 Нет описания", "support": ( "{} Ссылка на чат помощи" ), "_cls_doc": "Показывает помощь по модулям", "partial_load": ( "☝️ Юзербот еще не" " загрузился полностью, поэтому показаны не все модули" ), "not_exact": ( "☝️ Точного совпадения" " не нашлось, поэтому было выбрано наиболее подходящее" ), "request_join": "Вы запросили ссылку на чат помощи Hikka", "core_notice": ( "☝️ Это встроенный" " модуль. Вы не можете его выгрузить или заменить" ), } strings_de = { "bad_module": "🚫 Modul {} nicht gefunden", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 Keine Dokumentation", "all_header": ( "🌘 {} Module verfügbar," " {} versteckt:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 Gib das Modul an, das du verstecken willst", "hidden_shown": ( "🌘 {} Module versteckt," " {} Module angezeigt:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 Keine Dokumentation", "support": ( "{} Link zum Supportchat" ), "_cls_doc": "Zeigt Hilfe zu Modulen an", "partial_load": ( "☝️ Der Userbot ist noch" " nicht vollständig geladen, daher werden nicht alle Module angezeigt" ), "not_exact": ( "☝️ Es wurde kein exakter" " Treffer gefunden, daher wird das nächstbeste Ergebnis angezeigt" ), "request_join": "Du hast den Link zum Supportchat angefordert", "core_notice": ( "☝️ Dies ist ein" " eingebauter Modul. Du kannst ihn nicht entladen oder ersetzen" ), } strings_tr = { "bad_module": "🚫 Modül {} bulunamadı", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 Dokümantasyon yok", "all_header": ( "🌘 {} modül mevcut," " {} gizli:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 Gizlemek istediğin modülü belirt", "hidden_shown": ( "🌘 {} modül gizlendi," " {} modül gösterildi:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 Dokümantasyon yok", "support": "{} Destek sohbeti", "_cls_doc": "Modül yardımını gösterir", "partial_load": ( "☝️ Kullanıcı botu" " henüz tam olarak yüklenmediğinden, tüm modüller görüntülenmez" ), "not_exact": ( "☝️ Herhangi bir" " eşleşme bulunamadığından, en uygun sonuç görüntülenir" ), "request_join": "Destek sohbeti bağlantısını istediniz", "core_notice": ( "☝️ Bu bir" " dahili modül. Sen onu kaldıramaz veya değiştiremezsin" ), } strings_hi = { "bad_module": "🚫 मॉड्यूल {} नहीं मिला", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 दस्तावेज़ीकरण नहीं", "all_header": ( "🌘 {} मॉड्यूल उपलब्ध हैं," " {} छिपा हुआ:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 छिपाने के लिए मॉड्यूल दर्ज करें", "hidden_shown": ( "🌘 {} मॉड्यूल छिपा हुआ," " {} मॉड्यूल दिखाया गया:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 दस्तावेज़ीकरण नहीं", "support": "{} सपोर्ट चैट", "_cls_doc": "मॉड्यूल सहायता दिखाता है", "partial_load": ( "☝️ उपयोगकर्ता बॉट अभी भी" " पूरी तरह से लोड नहीं हुई है, इसलिए सभी मॉड्यूल दिखाई नहीं देते हैं" ), "not_exact": ( "☝️ कोई मैच नहीं मिला," " इसलिए सबसे अनुकूल परिणाम दिखाया गया है" ), "request_join": "आपने सपोर्ट चैट लिंक का अनुरोध किया है", "core_notice": ( "☝️ यह एक अंतर्निहित" " मॉड्यूल है, आप इसे नहीं अटक सकते या बदल सकते हैं" ), } strings_uz = { "bad_module": "🚫 Modul {} topilmadi", "single_mod_header": ( "🌘 {}:" ), "single_cmd": "\n▫️ {}{} {}", "undoc_cmd": "🦥 Hujjatlanmagan", "all_header": ( "🌘 {} taqdim etilgan" " modullar, {} yashirin:" ), "mod_tmpl": "\n{} {}", "first_cmd_tmpl": ": ( {}", "cmd_tmpl": " | {}", "no_mod": "🚫 Yashirish uchun modul kiriting", "hidden_shown": ( "🌘 {} yashirin," " {} modullar ko'rsatilgan:\n{}\n{}" ), "ihandler": "\n🎹 {} {}", "undoc_ihandler": "🦥 Hujjatlanmagan", "support": "{} Yordam chat", "_cls_doc": "Modul yordamini ko'rsatadi", "partial_load": ( "☝️ Foydalanuvchi boti" " hali to'liq yuklanmaganligi sababli, barcha modullar ko'rsatilmaydi" ), "not_exact": ( "☝️ Hech qanday moslik" " topilmadi, shuning uchun eng mos natija ko'rsatildi" ), "request_join": "Siz yordam chat havolasini so'radingiz", "core_notice": ( "☝️ Bu bir qo'shimcha" " modul, uni o'chirib yoki o'zgartirib bo'lmaysiz" ), } def __init__(self): self.config = loader.ModuleConfig( loader.ConfigValue( "core_emoji", "▪️", lambda: "Core module bullet", validator=loader.validators.Emoji(length=1), ), loader.ConfigValue( "hikka_emoji", "🌘", lambda: "Hikka-only module bullet", validator=loader.validators.Emoji(length=1), ), loader.ConfigValue( "plain_emoji", "▫️", lambda: "Plain module bullet", validator=loader.validators.Emoji(length=1), ), loader.ConfigValue( "empty_emoji", "🙈", lambda: "Empty modules bullet", validator=loader.validators.Emoji(length=1), ), ) @loader.command( ru_doc=( "<модуль или модули> - Спрятать модуль(-и) из помощи\n*Разделяй модули" " пробелами" ) ) async def helphide(self, message: Message): """ - Hide module(-s) from help *Split modules by spaces""" modules = utils.get_args(message) if not modules: await utils.answer(message, self.strings("no_mod")) return mods = [i.__class__.__name__ for i in self.allmodules.modules] modules = list(filter(lambda module: module in mods, modules)) currently_hidden = self.get("hide", []) hidden, shown = [], [] for module in modules: if module in currently_hidden: currently_hidden.remove(module) shown += [module] else: currently_hidden += [module] hidden += [module] self.set("hide", currently_hidden) await utils.answer( message, self.strings("hidden_shown").format( len(hidden), len(shown), "\n".join([f"👁‍🗨 {m}" for m in hidden]), "\n".join([f"👁 {m}" for m in shown]), ), ) async def modhelp(self, message: Message, args: str): exact = True module = self.lookup(args) if not module: _args = args.lower() _args = _args[1:] if _args.startswith(self.get_prefix()) else _args if _args in self.allmodules.commands: module = self.allmodules.commands[_args].__self__ if not module: module = self.lookup( next( ( reversed( sorted( [ module.strings["name"] for module in self.allmodules.modules ], key=lambda x: difflib.SequenceMatcher( None, args.lower(), x, ).ratio(), ) ) ), None, ) ) exact = False try: name = module.strings("name") except KeyError: name = getattr(module, "name", "ERROR") _name = ( "{} (v{}.{}.{})".format( utils.escape_html(name), module.__version__[0], module.__version__[1], module.__version__[2], ) if hasattr(module, "__version__") else utils.escape_html(name) ) reply = self.strings("single_mod_header").format(_name) if module.__doc__: reply += "\nℹ️ " + utils.escape_html(inspect.getdoc(module)) + "\n" commands = { name: func for name, func in module.commands.items() if await self.allmodules.check_security(message, func) } if hasattr(module, "inline_handlers"): for name, fun in module.inline_handlers.items(): reply += self.strings("ihandler").format( f"@{self.inline.bot_username} {name}", ( utils.escape_html(inspect.getdoc(fun)) if fun.__doc__ else self.strings("undoc_ihandler") ), ) for name, fun in commands.items(): reply += self.strings("single_cmd").format( self.get_prefix(), name, ( utils.escape_html(inspect.getdoc(fun)) if fun.__doc__ else self.strings("undoc_cmd") ), ) await utils.answer( message, reply + (f"\n\n{self.strings('not_exact')}" if not exact else "") + ( f"\n\n{self.strings('core_notice')}" if module.__origin__.startswith("