Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #118 from cyanray/dev/cyanray
Browse files Browse the repository at this point in the history
适配 mirai-api-http v2.1.0;
  • Loading branch information
cyanray authored Sep 22, 2021
2 parents e62c380 + 4c836c1 commit 546fbbb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/mirai/mirai_bot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ namespace Cyan
*/
void SendCommand(const vector<string>& command);

/**
* @brief 获取 Session 信息
* @return 关于 Bot 的信息
*/
Friend_t GetSessionInfo();

/**
* \brief 监听事件
* \tparam T 事件类型
Expand Down
20 changes: 19 additions & 1 deletion src/mirai_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,23 @@ namespace Cyan
pmem->sessionOptions = std::make_shared<SessionOptions>(opts);
pmem->threadPool = std::make_unique<ThreadPool>(opts.ThreadPoolSize.Get());
pmem->httpClient = std::make_shared<httplib::Client>(opts.HttpHostname.Get(), opts.HttpPort.Get());
pmem->botQQ = opts.BotQQ.Get();

string& sessionKey = pmem->sessionKey;
if (opts.EnableVerify.Get())
{
sessionKey = pmem->Verify(opts.VerifyKey.Get());
}
if (!opts.SingleMode.Get())
{
pmem->botQQ = opts.BotQQ.Get();
pmem->SessionBind(sessionKey, opts.BotQQ.Get());
}
else
{
auto info = GetSessionInfo();
pmem->sessionOptions->BotQQ = info.QQ;
pmem->botQQ = info.QQ;
}

pmem->eventClient.Connect(
opts.WebSocketHostname.Get(),
Expand Down Expand Up @@ -970,4 +977,15 @@ namespace Cyan
auto res = pmem->httpClient->Post("/cmd/execute", data.dump(), CONTENT_TYPE.c_str());
ParseOrThrowException(res);
}

Friend_t MiraiBot::GetSessionInfo()
{
auto res = pmem->httpClient->Get("/sessionInfo?sessionKey="s.append(pmem->sessionKey).data());
json re_json = ParseOrThrowException(res);
Friend_t result;
result.Set(re_json["data"]["qq"]);
return result;

}

} // namespace Cyan

0 comments on commit 546fbbb

Please sign in to comment.