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

Commit 546fbbb

Browse files
authored
Merge pull request #118 from cyanray/dev/cyanray
适配 mirai-api-http v2.1.0;
2 parents e62c380 + 4c836c1 commit 546fbbb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

include/mirai/mirai_bot.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ namespace Cyan
410410
*/
411411
void SendCommand(const vector<string>& command);
412412

413+
/**
414+
* @brief 获取 Session 信息
415+
* @return 关于 Bot 的信息
416+
*/
417+
Friend_t GetSessionInfo();
418+
413419
/**
414420
* \brief 监听事件
415421
* \tparam T 事件类型

src/mirai_bot.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,23 @@ namespace Cyan
184184
pmem->sessionOptions = std::make_shared<SessionOptions>(opts);
185185
pmem->threadPool = std::make_unique<ThreadPool>(opts.ThreadPoolSize.Get());
186186
pmem->httpClient = std::make_shared<httplib::Client>(opts.HttpHostname.Get(), opts.HttpPort.Get());
187-
pmem->botQQ = opts.BotQQ.Get();
187+
188188
string& sessionKey = pmem->sessionKey;
189189
if (opts.EnableVerify.Get())
190190
{
191191
sessionKey = pmem->Verify(opts.VerifyKey.Get());
192192
}
193193
if (!opts.SingleMode.Get())
194194
{
195+
pmem->botQQ = opts.BotQQ.Get();
195196
pmem->SessionBind(sessionKey, opts.BotQQ.Get());
196197
}
198+
else
199+
{
200+
auto info = GetSessionInfo();
201+
pmem->sessionOptions->BotQQ = info.QQ;
202+
pmem->botQQ = info.QQ;
203+
}
197204

198205
pmem->eventClient.Connect(
199206
opts.WebSocketHostname.Get(),
@@ -970,4 +977,15 @@ namespace Cyan
970977
auto res = pmem->httpClient->Post("/cmd/execute", data.dump(), CONTENT_TYPE.c_str());
971978
ParseOrThrowException(res);
972979
}
980+
981+
Friend_t MiraiBot::GetSessionInfo()
982+
{
983+
auto res = pmem->httpClient->Get("/sessionInfo?sessionKey="s.append(pmem->sessionKey).data());
984+
json re_json = ParseOrThrowException(res);
985+
Friend_t result;
986+
result.Set(re_json["data"]["qq"]);
987+
return result;
988+
989+
}
990+
973991
} // namespace Cyan

0 commit comments

Comments
 (0)