Comments (4)
没有😂,因为我也没成功过。
本来想到mah提issues的,结果忘了。最近比较忙,我更加没时间整理资料去提issues了。
我分享下当时我遇到的一些问题,你可以复现后拿去提issues:
- 通过mah注册指令成功,在mirai-console执行help有显示刚注册的指令。
- 通过mah执行注册的指令失败。(没有提示原因)
- 通过mah执行内建指令失败。(这个我记不清了,印象中没成功)
- 通过mirai-console执行注册的指令失败。(好像是提示没有权限)
你可以再试一下在mirai-console能不能看到,以及能不能执行你注册的指令,如果不行,那我想有可能是mah方面有问题?或者我们没弄清楚指令系统的用法。
from mirai-cpp.
试了下,134是成功的。我不熟http就没试。估计是mirai-cpp某处代码有问题吧。
from mirai-cpp.
问题在于 mirai-cpp 的 mirai_bot 没有正确处理执行命令的流程,json 文件的第一条消息代表的不是一条指令。
错误码 400 经查 mirai-http-api 的文档得知为「错误的访问,如参数错误等」。可知 mirai-cpp 发送的指令不被 mirai-http-api 理解。
mirai-http-api 的 Command 实现是基于 mirai-console 的,在 mirai-console 文档 Command 部分中提到「指令目前通常是 "/commandName arg1 arg2 arg3" 格式的消息。」
通过 mirai-http-api 文档所给的例子可以发现执行命令时「若执行纯文本的命令, 构建多个 Plain 格式的消息 console 会将第一个消息作为指令名」。尝试将第一条消息前面加上 ‘/’,问题得以解决。
临时的 Patch(mirai_bot.cpp 第 958 行,SendCommand 函数):
void MiraiBot::SendCommand(const vector<string>& command)
{
MessageChain mc;
vector<string> commandCopy = command;
commandCopy[0] = '/' + commandCopy[0];
for (const auto& val : commandCopy)
{
mc.Plain(val);
}
json data =
{
{ "sessionKey", pmem->sessionKey },
{ "command", mc.ToJson() }
};
auto res = pmem->httpClient->Post("/cmd/execute", data.dump(), CONTENT_TYPE.c_str());
ParseOrThrowException(res);
}
另外可以看到消息的发送者信息为 null,考虑消息是由 mirai console 发出的。
from mirai-cpp.
问题在于 mirai-cpp 的 mirai_bot 没有正确处理执行命令的流程,json 文件的第一条消息代表的不是一条指令。
错误码 400 经查 mirai-http-api 的文档得知为「错误的访问,如参数错误等」。可知 mirai-cpp 发送的指令不被 mirai-http-api 理解。
mirai-http-api 的 Command 实现是基于 mirai-console 的,在 mirai-console 文档 Command 部分中提到「指令目前通常是 "/commandName arg1 arg2 arg3" 格式的消息。」
通过 mirai-http-api 文档所给的例子可以发现执行命令时「若执行纯文本的命令, 构建多个 Plain 格式的消息 console 会将第一个消息作为指令名」。尝试将第一条消息前面加上 ‘/’,问题得以解决。
临时的 Patch(mirai_bot.cpp 第 958 行,SendCommand 函数):
void MiraiBot::SendCommand(const vector<string>& command) { MessageChain mc; vector<string> commandCopy = command; commandCopy[0] = '/' + commandCopy[0]; for (const auto& val : commandCopy) { mc.Plain(val); } json data = { { "sessionKey", pmem->sessionKey }, { "command", mc.ToJson() } }; auto res = pmem->httpClient->Post("/cmd/execute", data.dump(), CONTENT_TYPE.c_str()); ParseOrThrowException(res); }另外可以看到消息的发送者信息为 null,考虑消息是由 mirai console 发出的。
原来是这样!感谢反馈!😂头大
现在应该可以通过手动补充 "/" 的方式临时补救: bot.SendCommand({ "/hello", "arg1", "arg2" });
后续更新这个函数会兼容两种方式(有“/”和没有“/”)
from mirai-cpp.
Related Issues (20)
- 发送语音消息时VoiceMessage::length_未初始化导致mirai-api-http可能返回400
- websocket 连接正常,但是无法触发事件处理函数 HOT 11
- 希望能给GroupMessage添加一个GroupId HOT 2
- 新增一系列无异常的 Try* 模式的接口
- 有关LostConnectionCallback的一些问题 HOT 3
- 目前的项目在使用mirai-cpp,可否在readme做下推广呢? HOT 1
- 关于MessageChain == 比较的问题 [Bug?] HOT 1
- 更新cpp-httplib以保证线程安全 HOT 1
- 拼写错误,解析json失败 HOT 1
- 将 const std::string& 替换为 std::string_view 以简化代码
- 在使用httplib::Client时出现错误 HOT 6
- 有时QQ客户端收不到消息 HOT 2
- 有关VoiceMessage的问题 HOT 2
- Command.Member->Group.GID 可能为空 HOT 3
- MFC开发 HOT 1
- 分享一个非常蒻的Bot HOT 1
- 关于VoiceMessage.Url() HOT 3
- 关于MessageChain().Add<VoiceMessage>(); HOT 9
- 无法上传文件 HOT 3
- mirai-cpp-template的main函数中的端口设置似乎不起作用
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mirai-cpp.