From 264771fe989361544ac468af88d62a1e4838f9f9 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 14 Apr 2025 21:55:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=91=BD=E4=BB=A4=E6=97=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=88=E6=B3=95=E6=80=A7=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/telegram/tg_adapter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index 4a1cfab7e..e954f35de 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -1,4 +1,5 @@ import asyncio +import re import sys import uuid @@ -118,8 +119,6 @@ class TelegramPlatformAdapter(Platform): if commands: await self.client.set_my_commands(commands) - for cmd in commands: - logger.debug(f"已注册指令: /{cmd.command} - {cmd.description}") except Exception as e: logger.error(f"向 Telegram 注册指令时发生错误: {e!s}") @@ -167,6 +166,10 @@ class TelegramPlatformAdapter(Platform): if not cmd_name or cmd_name in skip_commands: return None + if not re.match(r"^[a-z0-9_]+$", cmd_name) or len(cmd_name) > 32: + logger.warning(f"跳过无法注册的命令: {cmd_name}") + return None + # Build description. description = handler_metadata.desc or ( f"指令组: {cmd_name} (包含多个子指令)" if is_group else f"指令: {cmd_name}"