import string from typing import TYPE_CHECKING from aiogram import Router from aiogram.filters import Command from karkas_core.modules_system.public_api import ( get_metainfo, get_module, register_router, ) if TYPE_CHECKING: from aiogram.types import Message from karkas_blocks.standard.config import IConfig config: "IConfig" = get_module("standard.config", "config") try: (register_command, get_user_commands) = get_module( "standard.command_helper", ["register_command", "get_user_commands"] ) COMMAND_HELPER_MODULE_LOADED = True except Exception: COMMAND_HELPER_MODULE_LOADED = False pass # We kindly ask you not to delete or change the following text without # the consent of the «Karkas» project team. FOOTER = """=============== Разработано командой ALT Gnome Infrastructure в рамках проекта Каркас. Исходный код: https://gitflic.ru/project/alt-gnome/karkas Оставить репорт: https://gitflic.ru/project/alt-gnome/karkas/issue/create Руководитель проекта: Семен Фомченков Ведущий разработчик: Максим Слипенко Почта для связи: help@karkas.chat Версия: $version """ def format_commands(commands_dict): formatted_commands = [] for command, details in commands_dict.items(): formatted_commands.append(f"/{command} - {details['long_description']}") return "\n".join(formatted_commands) async def help(message: "Message"): commands = "" version = "" if COMMAND_HELPER_MODULE_LOADED: commands = format_commands(get_user_commands()) metainfo = get_metainfo() if "app_version" in metainfo: version = metainfo["app_version"] await message.reply( string.Template(config.get("help::message") + "\n\n" + FOOTER).substitute( commands=commands, version=version or "не указана" ) ) async def module_init(): config.register( "help::message", "string", default_value="$commands", ) router = Router() router.message.register(help, Command("help")) register_router(router) if COMMAND_HELPER_MODULE_LOADED: register_command("help", "Cправка")