diff --git a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/en-US.json b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/en-US.json index f0afe53f0c..c307908e4e 100644 --- a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/en-US.json +++ b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/en-US.json @@ -2,5 +2,20 @@ "metadata": { "display_name": "Built-in Commands", "desc": "AstrBot's internal plugin, providing built-in commands such as /reset, /help, and /sid." + }, + "config": { + "builtin_commands": { + "配置": "Config" + }, + "help_language": { + "description": "Command Response Language", + "hint": "Select the response language for /help and other commands", + "labels": { + "en-US": "English", + "zh-CN": "Simplified Chinese", + "zh-TW": "Traditional Chinese", + "ru-RU": "Russian" + } + } } -} +} \ No newline at end of file diff --git a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/ru-RU.json b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/ru-RU.json new file mode 100644 index 0000000000..42b08d9e21 --- /dev/null +++ b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/ru-RU.json @@ -0,0 +1,21 @@ +{ + "metadata": { + "display_name": "Встроенные команды", + "desc": "Встроенный плагин AstrBot, предоставляющий команды /reset, /help, /sid и другие." + }, + "config": { + "builtin_commands": { + "配置": "Конфигурация" + }, + "help_language": { + "description": "Язык ответа команды", + "hint": "Выберите язык ответа для команд /help и других", + "labels": { + "en-US": "Английский", + "zh-CN": "Упрощенный китайский", + "zh-TW": "Традиционный китайский", + "ru-RU": "Русский" + } + } + } +} \ No newline at end of file diff --git a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-CN.json b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-CN.json index 3e2be6cced..f80743e7bd 100644 --- a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-CN.json +++ b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-CN.json @@ -2,5 +2,20 @@ "metadata": { "display_name": "内置指令", "desc": "AstrBot 自带插件,提供 /reset、/help、/sid 等内置指令。" + }, + "config": { + "builtin_commands": { + "配置": "配置" + }, + "help_language": { + "description": "指令回复语言", + "hint": "选择 /help 等指令的回复语言", + "labels": { + "en-US": "英语", + "zh-CN": "简体中文", + "zh-TW": "繁体中文", + "ru-RU": "俄语" + } + } } -} +} \ No newline at end of file diff --git a/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-TW.json b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-TW.json new file mode 100644 index 0000000000..8bea1e1760 --- /dev/null +++ b/astrbot/builtin_stars/builtin_commands/.astrbot-plugin/i18n/zh-TW.json @@ -0,0 +1,21 @@ +{ + "metadata": { + "display_name": "內建指令", + "desc": "AstrBot 自帶插件,提供 /reset、/help、/sid 等內建指令。" + }, + "config": { + "builtin_commands": { + "配置": "配置" + }, + "help_language": { + "description": "指令回復語言", + "hint": "選擇 /help 等指令的回復語言", + "labels": { + "en-US": "英語", + "zh-CN": "簡體中文", + "zh-TW": "繁體中文", + "ru-RU": "俄語" + } + } + } +} \ No newline at end of file diff --git a/astrbot/builtin_stars/builtin_commands/_conf_schema.json b/astrbot/builtin_stars/builtin_commands/_conf_schema.json new file mode 100644 index 0000000000..4d0866d51f --- /dev/null +++ b/astrbot/builtin_stars/builtin_commands/_conf_schema.json @@ -0,0 +1,15 @@ +{ + "help_language": { + "description": "指令回复语言", + "type": "string", + "hint": "选择 /help 等指令的回复语言", + "default": "zh-CN", + "options": ["en-US", "zh-CN", "zh-TW", "ru-RU"], + "labels": { + "en-US": "English", + "zh-CN": "简体中文", + "zh-TW": "繁体中文", + "ru-RU": "俄语" + } + } +} \ No newline at end of file diff --git a/astrbot/builtin_stars/builtin_commands/commands/help.py b/astrbot/builtin_stars/builtin_commands/commands/help.py index af8e79708e..21888a2de1 100644 --- a/astrbot/builtin_stars/builtin_commands/commands/help.py +++ b/astrbot/builtin_stars/builtin_commands/commands/help.py @@ -6,10 +6,79 @@ from astrbot.core.star import command_management from astrbot.core.utils.io import get_dashboard_version +TRANSLATIONS = { + "en-US": { + "no_commands": "No enabled built-in commands.", + "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", + "commands": { + "help": "Show help message", + "sid": "Get session ID and other related information", + "reset": "Reset conversation history", + "stop": "Stop agent execution", + "new": "Create new conversation", + "stats": "Show token usage statistics for the current conversation", + "provider": "View or switch LLM Provider", + "dashboard_update": "Update AstrBot WebUI", + "set": "Set session variable", + "unset": "Unset session variable", + }, + }, + "zh-CN": { + "no_commands": "没有启用的内置指令。", + "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", + "commands": { + "help": "显示帮助信息", + "sid": "获取会话ID和其他相关信息", + "reset": "重置对话历史", + "stop": "停止Agent执行", + "new": "创建新对话", + "stats": "显示当前对话的Token使用统计", + "provider": "查看或切换LLM提供商", + "dashboard_update": "更新AstrBot WebUI", + "set": "设置会话变量", + "unset": "取消设置会话变量", + }, + }, + "zh-TW": { + "no_commands": "沒有啟用的內建指令。", + "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", + "commands": { + "help": "顯示幫助信息", + "sid": "獲取會話ID和其他相關信息", + "reset": "重置對話歷史", + "stop": "停止Agent執行", + "new": "創建新對話", + "stats": "顯示當前對話的Token使用統計", + "provider": "查看或切換LLM提供商", + "dashboard_update": "更新AstrBot WebUI", + "set": "設置會話變量", + "unset": "取消設置會話變量", + }, + }, + "ru-RU": { + "no_commands": "Нет включенных встроенных команд.", + "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", + "commands": { + "help": "Показать справку", + "sid": "Получить ID сессии и другую информацию", + "reset": "Сбросить историю диалога", + "stop": "Остановить выполнение агента", + "new": "Создать новый диалог", + "stats": "Показать статистику использования токенов", + "provider": "Просмотр или смена провайдера LLM", + "dashboard_update": "Обновить AstrBot WebUI", + "set": "Установить переменную сессии", + "unset": "Сбросить переменную сессии", + }, + }, +} + class HelpCommand: - def __init__(self, context: star.Context) -> None: + def __init__(self, context: star.Context, config: dict | None = None) -> None: self.context = context + self.config = config or {} + self.language = self.config.get("help_language", "zh-CN") async def _query_astrbot_notice(self): try: @@ -23,9 +92,6 @@ async def _query_astrbot_notice(self): return "" async def _build_reserved_command_lines(self) -> list[str]: - """ - 使用实时指令配置生成内置指令清单,确保重命名/禁用后与实际生效状态保持一致。 - """ try: commands = await command_management.list_commands() except BaseException: @@ -37,7 +103,6 @@ def walk(items: list[dict], indent: int = 0) -> None: for item in items: if not item.get("reserved") or not item.get("enabled"): continue - # 仅展示顶级指令或指令组 if item.get("type") == "sub_command": continue if item.get("parent_signature"): @@ -48,24 +113,28 @@ def walk(items: list[dict], indent: int = 0) -> None: or item.get("original_command") or item.get("handler_name") ) - if not effective or effective in [ - "set", - "unset", - "help", - "dashboard_update", - ]: + if not effective: continue description = item.get("description") or "" - desc_text = f" - {description}" if description else "" + handler_name = item.get("handler_name", "") + + lang_translations = TRANSLATIONS.get(self.language, {}) + cmd_translations = lang_translations.get("commands", {}) + translated_desc = cmd_translations.get(handler_name, description) + + desc_text = f" - {translated_desc}" if translated_desc else "" indent_prefix = " " * indent lines.append(f"{indent_prefix}/{effective}{desc_text}") walk(commands) return lines + def _get_translation(self, key: str) -> str: + lang_translations = TRANSLATIONS.get(self.language, TRANSLATIONS["zh-CN"]) + return lang_translations.get(key, key) + async def help(self, event: AstrMessageEvent) -> None: - """查看帮助""" notice = "" try: notice = await self._query_astrbot_notice() @@ -77,11 +146,15 @@ async def help(self, event: AstrMessageEvent) -> None: commands_section = ( "\n".join(command_lines) if command_lines - else "No enabled built-in commands." + else self._get_translation("no_commands") + ) + + version_str = self._get_translation("version_format").format( + version=VERSION, dashboard_version=dashboard_version ) msg_parts = [ - f"AstrBot v{VERSION}(WebUI: {dashboard_version})", + version_str, commands_section, ] if notice: diff --git a/astrbot/builtin_stars/builtin_commands/main.py b/astrbot/builtin_stars/builtin_commands/main.py index 4a0e78f81a..19c763c99c 100644 --- a/astrbot/builtin_stars/builtin_commands/main.py +++ b/astrbot/builtin_stars/builtin_commands/main.py @@ -12,12 +12,13 @@ class Main(star.Star): - def __init__(self, context: star.Context) -> None: + def __init__(self, context: star.Context, config: dict | None = None) -> None: self.context = context + self.config = config or {} self.admin_c = AdminCommands(self.context) self.conversation_c = ConversationCommands(self.context) - self.help_c = HelpCommand(self.context) + self.help_c = HelpCommand(self.context, self.config) self.provider_c = ProviderCommands(self.context) self.setunset_c = SetUnsetCommands(self.context) self.sid_c = SIDCommand(self.context) diff --git a/astrbot/core/cron/manager.py b/astrbot/core/cron/manager.py index 9f3116f65c..cbb15f5cfb 100644 --- a/astrbot/core/cron/manager.py +++ b/astrbot/core/cron/manager.py @@ -289,7 +289,6 @@ async def _woke_main_agent( from astrbot.core.astr_main_agent_resources import ( PROACTIVE_AGENT_CRON_WOKE_SYSTEM_PROMPT, ) - from astrbot.core.tools.message_tools import SendMessageToUserTool try: session = ( @@ -356,7 +355,7 @@ async def _woke_main_agent( if not req.func_tool: req.func_tool = ToolSet() req.func_tool.add_tool( - self.ctx.get_llm_tool_manager().get_builtin_tool(SendMessageToUserTool) + self.ctx.get_llm_tool_manager().get_builtin_tool("send_message_to_user") ) result = await build_main_agent(