diff --git a/include/mirai/mirai_bot.hpp b/include/mirai/mirai_bot.hpp index 7fbfa62..0b8223e 100644 --- a/include/mirai/mirai_bot.hpp +++ b/include/mirai/mirai_bot.hpp @@ -410,6 +410,12 @@ namespace Cyan */ void SendCommand(const vector& command); + /** + * @brief 获取 Session 信息 + * @return 关于 Bot 的信息 + */ + Friend_t GetSessionInfo(); + /** * \brief 监听事件 * \tparam T 事件类型 diff --git a/src/mirai_bot.cpp b/src/mirai_bot.cpp index dc012bb..1f9a34e 100644 --- a/src/mirai_bot.cpp +++ b/src/mirai_bot.cpp @@ -184,7 +184,7 @@ namespace Cyan pmem->sessionOptions = std::make_shared(opts); pmem->threadPool = std::make_unique(opts.ThreadPoolSize.Get()); pmem->httpClient = std::make_shared(opts.HttpHostname.Get(), opts.HttpPort.Get()); - pmem->botQQ = opts.BotQQ.Get(); + string& sessionKey = pmem->sessionKey; if (opts.EnableVerify.Get()) { @@ -192,8 +192,15 @@ namespace Cyan } 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(), @@ -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 \ No newline at end of file