diff --git a/README.md b/README.md index 5128206472..4b7abd4cfc 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,8 @@ A Game Assistant for Arknights - [C 接口](https://github.com/MistEO/MeoAssistantArknights/blob/dev/include/AsstCaller.h) - [Python 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Python-%E6%8E%A5%E5%8F%A3) -- [Golang 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Golang-%E6%8E%A5%E5%8F%A3) +- [Golang 接口](https://github.com/MistEO/MeoAssistantArknights/wiki/Golang-%E6%8E%A5%E5%8F%A3) 已停止维护 orz +- [集成文档](docs/集成文档.md) 龟速更新中_(:з」∠)_ - [回调消息协议](docs/回调消息协议.md) ## 声明 diff --git a/docs/集成文档.md b/docs/集成文档.md new file mode 100644 index 0000000000..da8ee79830 --- /dev/null +++ b/docs/集成文档.md @@ -0,0 +1,34 @@ +# 集成文档 + +## 接口介绍 + +### AsstSetParam + +#### 接口原型 + +```c++ +bool ASSTAPI AsstSetParam(AsstHandle handle, const char* param_id, const char* param_value); +``` + +#### 接口说明 + +设置实例级参数 + +#### 返回值 + +- bool + 返回是否设置成功 + +#### 参数说明 + +- AsstHandle handle + 实例句柄 +- const char* param_id + 参数 id +- const char* param_value + 参数值,json string + +| 参数作用 | 参数 id | 参数值 | 参数示例 | +| ------- | ------- | ----- | -------- | +| 设置企鹅数据 id | penguin_id | { "id" : string } | { "id" : "1234567" } | +| 设置 OCR 任务要识别的文字 | ocr_text | { TaskName: [ string, ...]} | { "Roguelike1ChooseOper" : [ "帕拉斯", "银灰" ] } | diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index 1e78747067..b2ebc39caf 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -424,7 +424,7 @@ bool asst::Assistant::set_param(const std::string& param_id, const std::string& { Log.info(__FUNCTION__, param_id, param_value); - using SetParamFuncType = std::function; + using SetParamFuncType = std::function; static const std::unordered_map ParamsMapping = { {AsstParamIdPenguinId, std::bind(&Assistant::set_penguid_id, this, std::placeholders::_1)}, @@ -433,7 +433,13 @@ bool asst::Assistant::set_param(const std::string& param_id, const std::string& if (const auto iter = ParamsMapping.find(param_id); iter != ParamsMapping.cend()) { - return iter->second(param_value); + const auto json_opt = json::parse(param_value); + if (!json_opt) { + return false; + } + const auto& root = json_opt.value(); + + return iter->second(root); } else { Log.error("Invaild Param Id", param_id); @@ -595,26 +601,25 @@ void Assistant::clear_cache() //Task.clear_cache(); } -bool asst::Assistant::set_penguid_id(const std::string& param_value) +bool asst::Assistant::set_penguid_id(const json::value& root) { + if (!(root.is_object() && root.contains("id") && root.at("id").is_string())) { + return false; + } auto& opt = Resrc.cfg().get_options(); - if (param_value.empty()) { + std::string id = root.at("id").as_string(); + if (id.empty()) { opt.penguin_report.extra_param.clear(); } else { - opt.penguin_report.extra_param = "-H \"authorization: PenguinID " + param_value + "\""; + opt.penguin_report.extra_param = "-H \"authorization: PenguinID " + id + "\""; } return true; } -bool asst::Assistant::set_ocr_text(const std::string& param_value) +bool asst::Assistant::set_ocr_text(const json::value& root) { - const auto json_opt = json::parse(param_value); - if (!json_opt) { - return false; - } - const auto& root = json_opt.value(); - + bool ret = true; for (auto&& [key, text] : root.as_object()) { if (!text.is_array()) { return false; @@ -626,8 +631,8 @@ bool asst::Assistant::set_ocr_text(const std::string& param_value) } text_vec.emplace_back(text.as_string()); } - m_task_data->set_ocr_text(key, std::move(text_vec)); + ret &= m_task_data->set_ocr_text(key, std::move(text_vec)); } - return true; + return ret; } diff --git a/src/MeoAssistant/Assistant.h b/src/MeoAssistant/Assistant.h index 06b05c17e3..8838a093e5 100644 --- a/src/MeoAssistant/Assistant.h +++ b/src/MeoAssistant/Assistant.h @@ -97,8 +97,8 @@ namespace asst void clear_cache(); /* set params */ - bool set_penguid_id(const std::string& param_value); - bool set_ocr_text(const std::string& param_value); + bool set_penguid_id(const json::value& root); + bool set_ocr_text(const json::value& root); bool m_inited = false; std::string m_uuid;