Skip to content

Commit

Permalink
fix image send and recv for Lagrange.Core
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Nov 26, 2023
1 parent ad72529 commit 60c75a2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/MiraiCQ/MiraiCQ/center/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ static bool is_qq_url(const Json::Value & dat_json)
if (url.find("c2cpicdw") != url.npos) {
return true;
}
std::string file = StrTool::get_str_from_json(dat_json, "file", "");
if (file.find("gchat") != file.npos) {
return true;
}
if (file.find("c2cpicdw") != file.npos) {
return true;
}
return false;
}

Expand Down Expand Up @@ -431,6 +438,9 @@ static bool deal_json_array(Json::Value & json_arr)
if (md5_str == "") {
md5_str = get_md5_from_imgurl(StrTool::get_str_from_json(dat_json, "url", ""));
}
if (md5_str == "") {
md5_str = get_md5_from_imgurl(StrTool::get_str_from_json(dat_json, "file", ""));
}
url = "https://gchat.qpic.cn/gchatpic_new/0/0-0-" + md5_str + "/0?term=2";
}
else {
Expand Down
14 changes: 14 additions & 0 deletions src/MiraiCQ/MiraiCQ/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,17 @@ std::string Config::get_name()
}
return name;
}

std::string Config::get_is_support_multi_ws()
{
std::string config_path = PathTool::get_exe_dir() + "config\\";
PathTool::create_dir(config_path);
std::string config_file = config_path + "config.ini";
std::string is_support_multi_ws = StrTool::get_str_from_ini(config_file, "Setting", "is_support_multi_ws", "");
if (is_support_multi_ws == "")
{
WritePrivateProfileStringA("Setting", "is_support_multi_ws", this->is_support_multi_ws.c_str(), config_file.c_str());
return this->is_support_multi_ws;
}
return is_support_multi_ws;
}
2 changes: 2 additions & 0 deletions src/MiraiCQ/MiraiCQ/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Config
std::string get_access_token() ;
bool set_access_token(const std::string& access_token);
std::string get_name();
std::string get_is_support_multi_ws();
private:
Config();
~Config();
Expand All @@ -24,5 +25,6 @@ class Config
std::string http_url = "http://localhost:8080";
std::string adapter = "onebotv11";
std::string name = "";
std::string is_support_multi_ws = "true";
};

1 change: 1 addition & 0 deletions src/MiraiCQ/MiraiCQ/mainprocess/mainprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static bool login(LOGIN_INFO* login_info)
net->set_config("access_token", login_info->access_token);
net->set_config("verifyKey", Config::get_instance()->get_verifyKey());
net->set_config("http_url", Config::get_instance()->get_http_url());
net->set_config("is_support_multi_ws", Config::get_instance()->get_is_support_multi_ws());
if (!net->connect())
{
std::string str = StrTool::to_utf8("网络连接错误");
Expand Down
3 changes: 2 additions & 1 deletion src/MiraiCQ/MiraiCQ/net/OneBot/OneBotImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../tool/StrTool.h"
#include "../../tool/TimeTool.h"
#include "../../tool/AutoDoSth.h"
#include "../../config/config.h"

using namespace std;

Expand Down Expand Up @@ -250,7 +251,7 @@ MiraiNet::NetStruct OneBotNetImpl::call_fun(NetStruct senddat, int timeout,bool
auto send_json = Json::FastWriter().write(*api_json);
// MiraiLog::get_instance()->add_debug_log("OnebotImpl", "send_json_size:" + std::to_string(send_json.size()));
// 超过50kb的信息建立新的连接来发送
if ((send_json.size() > 1024 * 50) && (in_new_net == false))
if (get_config("is_support_multi_ws") == "true" && (send_json.size() > 1024 * 50) && (in_new_net == false))
{
auto new_net = MiraiNet::get_instance(this->get_config("net_type"));
if (!new_net)
Expand Down

0 comments on commit 60c75a2

Please sign in to comment.