Open ganghua233 opened 7 months ago
首先这是一个脚本的注入漏洞——用户输入的内容不应该格式化,以免安全风险 这里附上我当时写的代码聊供参考,在这里用户文本被存入了msg.answer中而不会被二次转义
local question = msg.fromMsg:match(,"^[%s]*(.-)[%s]*$",msg.fromMsg:find("是")+#"是不是")
local answer = "是"
if(ranint(0,1)>0)then
answer = "并不是"
end
msg.answer = answer..(string.match(question,"^(.-)?$") or question)
if isFirstPerson then
return "{answer_yes_no_first_person}"
else
return "{answer_yes_no}"
end
然后就是花括号{}
为什么会打印出整个msg的内容的问题……这个是基于源码ManagerSystem.cpp
内getContextItem函数的特性,当item为空字符串时,返回context本身,至于当时为什么要设计这个特性……忘了。所以暂时应该不会改动。
机器人的“是不是”功能,在“是不是”后面的字符串包含大括号时,机器人将输出 Json 文本,如下所示: