From 4d3146004da537e82c3f9964653119218181fb22 Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Sat, 16 Apr 2022 17:40:30 +0800 Subject: [PATCH] =?UTF-8?q?#=E8=A7=92=E8=89=B2=E8=AF=A6=E6=83=85=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E5=A4=96=E9=83=A8API=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + apps/character.js | 6 ++++-- components/Cfg.js | 4 ---- components/Profile.js | 37 ++++++++++++++++++++++----------- config_default.js | 7 +++++++ index.js | 4 +++- resources/character/detail.html | 2 +- 7 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 config_default.js diff --git a/.gitignore b/.gitignore index c1978e67..165fa8a9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /components/cfg.json /resources/miao-res-plus/ /components/setting.json +/config.js diff --git a/apps/character.js b/apps/character.js index 14a0cb8c..6511451b 100644 --- a/apps/character.js +++ b/apps/character.js @@ -416,8 +416,10 @@ export async function getProfile(e) { return true; } let data = await Profile.request(selfUser.uid, e); - - if (!data || !data.chars) { + if(!data){ + return true; + } + if (!data.chars) { e.reply("请求游戏信息失败,请确认角色已在游戏内橱窗展示,并开放了查看详情。设置完毕后请5分钟后再进行请求~"); } else { let ret = []; diff --git a/components/Cfg.js b/components/Cfg.js index 35ec7192..2561a91f 100644 --- a/components/Cfg.js +++ b/components/Cfg.js @@ -4,10 +4,6 @@ import lodash from "lodash"; const _path = process.cwd(); const _cfgPath = `${_path}/plugins/miao-plugin/components/`; let cfg = {}; -console.log(cfg); -if (!fs.existsSync(_cfgPath)) { - fs.mkdirSync(_cfgPath); -} try { if (fs.existsSync(_cfgPath + "cfg.json")) { diff --git a/components/Profile.js b/components/Profile.js index 251bb544..7d28b385 100644 --- a/components/Profile.js +++ b/components/Profile.js @@ -5,15 +5,18 @@ import Format from "./Format.js"; import Character from "./models/Character.js"; const _path = process.cwd(); -const cfgPath = `${_path}/plugins/miao-plugin/components/setting.json`; -let cfg = {}; -try { - if (fs.existsSync(cfgPath)) { - cfg = JSON.parse(fs.readFileSync(cfgPath, "utf8")) || {}; +const cfgPath = `${_path}/plugins/miao-plugin/config.js`; +let config = {}; +//try { +if (fs.existsSync(cfgPath)) { + let fileData = await import (`file://${cfgPath}`); + if (fileData && fileData.config) { + config = fileData.config; } -} catch (e) { - // do nth } +//} catch (e) { +// do nth +//} const userPath = `${_path}/data/UserData/`; @@ -207,17 +210,27 @@ let Data = { let Profile = { async request(uid, e) { + let cfg = config.miaoApi || {}; if (!cfg.api) { e.reply("尚未配置更新Api,无法更新数据~"); return false; } + if (!cfg.qq || !cfg.token || cfg.token.length !== 32) { + e.reply("Token错误,无法请求数据~"); + return false; + } e.reply("开始获取角色展柜中展示的角色详情,请确认已经打开显示角色详情开关,数据获取可能会需要一定时间~"); - const api = cfg.api + uid; + const api = `${cfg.api}?uid=${uid}&qq=${cfg.qq}&token=${cfg.token}`; + console.log(api); let req = await fetch(api); - let data = await req.text(); - data = data.replace(/\x00/g, ''); - fs.writeFileSync(userPath + "/test.json", data); - data = JSON.parse(data); + let data = await req.json(); + //fs.writeFileSync(userPath + "/test.json", data); + if (data.status !== 0 || !data.data) { + e.reply(`请求错误:${data.msg || "未知错误"}`); + return false; + } + data = data.data; + let userData = {}; if (data && data["角色名称"]) { userData = Profile.save(uid, data) diff --git a/config_default.js b/config_default.js new file mode 100644 index 00000000..a2495cf8 --- /dev/null +++ b/config_default.js @@ -0,0 +1,7 @@ +export default { + miaoApi: { + api: "http://49.232.91.210:88/miaoPlugin/GetRoleAll", // Miao APi 地址 + qq: "", // 申请的主人qq + token: "" // 申请的token + } +} \ No newline at end of file diff --git a/index.js b/index.js index 47508e02..5816df28 100644 --- a/index.js +++ b/index.js @@ -47,4 +47,6 @@ lodash.forEach(rule, (r) => { r.hashMark = true; }); -export { rule }; \ No newline at end of file +export { rule }; + +console.log("喵喵插件初始化~"); \ No newline at end of file diff --git a/resources/character/detail.html b/resources/character/detail.html index e5546eb5..b09f7950 100644 --- a/resources/character/detail.html +++ b/resources/character/detail.html @@ -40,7 +40,7 @@
{{each cons con idx}}
-
+