优化token指令信息
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user