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

Commit ffd779d

Browse files
committed
支持mirai重启后自动auth;
1 parent 009c6b6 commit ffd779d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/mirai_bot.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace Cyan
134134
}
135135

136136
}
137-
137+
string authKey_;
138138
QQ_t qq_;
139139
string sessionKey_;
140140
string api_url_prefix_ = "http://127.0.0.1:8080";

src/mirai_bot.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Cyan
2121
if (code == 0)
2222
{
2323
this->sessionKey_ = reJson["session"].get<string>();
24+
this->authKey_ = authKey;
2425
this->qq_ = qq;
2526
// 启动消息循环
2627
//std::async(std::launch::async, [&]() { EventLoop(); });
@@ -677,7 +678,7 @@ namespace Cyan
677678

678679
int received_count = 0;
679680

680-
HTTP http;
681+
HTTP http; http.SetTimeout(5);
681682
auto res = http.Get(api_url.str());
682683
if (res.Ready)
683684
{
@@ -686,6 +687,18 @@ namespace Cyan
686687
json reJson;
687688
reJson = reJson.parse(res.Content);
688689
if (!reJson.is_object()) throw runtime_error("解析返回 JSON 时出错");
690+
int code = reJson["code"].get<int>();
691+
if (code != 0)
692+
{
693+
// 特判,code=3为session失效,releas后重新auth
694+
if (code == 3)
695+
{
696+
Release();
697+
Auth(authKey_, qq_);
698+
}
699+
string msg = reJson["msg"].get<string>();
700+
throw runtime_error(msg);
701+
}
689702
for (const auto& ele : reJson["data"])
690703
{
691704
string event_name = ele["type"].get<string>();

0 commit comments

Comments
 (0)