优化token指令信息

This commit is contained in:
liuwei
2026-01-04 16:49:49 +08:00
parent 25159bf764
commit bddc2500b9

View File

@@ -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: