From bddc2500b9689f8076443599f61273666bea30f3 Mon Sep 17 00:00:00 2001 From: liuwei Date: Sun, 4 Jan 2026 16:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96token=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/jd_sign_token/main.py | 36 ++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/plugins/jd_sign_token/main.py b/plugins/jd_sign_token/main.py index 937ae1a..ee0a2ea 100644 --- a/plugins/jd_sign_token/main.py +++ b/plugins/jd_sign_token/main.py @@ -249,25 +249,39 @@ class JDTokenPlugin(MessagePluginInterface): gbm: GroupBotManager = message.get("gbm") bot: WechatAPIClient = message.get("bot") - # 检查命令格式 - 修改正则表达式,使用非贪婪匹配捕获token部分 - pattern = r'^设置京东\s+(.+?)\s+([^\s].+)$' - match = re.match(pattern, content) - - if not match: + # 先去除内容中"设置京东"之后的所有空格,便于后续处理 + # 保留命令部分,去除后面的所有空格 + parts = content.split(" ", 1) # 只分割一次 + if len(parts) < 2: await bot.send_text_message((roomid if roomid else sender), f"❌命令格式错误!\n{self.command_format}" , sender) return False, "命令格式错误" + # 去除token部分的空格(只去除空格,保留分号) + token_part = parts[1].replace(" ", "") + + # 检查格式:token部分应该包含 pt_key= 和 pt_pin=,以及最后的备注 + # 备注可能包含在分号后面,所以需要智能分割 + # 查找最后一个分号的位置,最后一个分号后面是备注 + last_semicolon_pos = token_part.rfind(";") + if last_semicolon_pos == -1 or last_semicolon_pos == len(token_part) - 1: + await bot.send_text_message((roomid if roomid else sender), f"❌命令格式错误!\n{self.command_format}" + , sender) + return False, "命令格式错误" + + token = token_part[:last_semicolon_pos + 1] # 包含最后一个分号 + remark = token_part[last_semicolon_pos + 1:] # 分号后面的内容 + + if not remark: + await bot.send_text_message((roomid if roomid else sender), f"❌命令格式错误!\n{self.command_format}" + , sender) + return False, "备注不能为空" + # 检查权限 if roomid and gbm.get_group_permission(roomid, self.feature) == PermissionStatus.DISABLED: return False, "没有权限" - # 提取token和备注 - token = match.group(1) - remark = match.group(2) - - # 清理token中的空格 - token = token.replace(" ", "") + # token已经去除空格,直接验证格式 # 确保token格式正确 if "pt_key=" not in token or "pt_pin=" not in token: