From 7ee8fe567b6515bbbc11d82ff97d4c318d250bc6 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Mon, 31 Oct 2022 22:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=A7=BB=E9=99=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- apps/Note.js | 28 ++++++++++++++++++++-------- apps/index.js | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 161bbec..74c28f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ * 用户可通过`#开启、关闭体力推送` 来对体力推送进行操作 * 管理员可通过`#体力设置群推送关闭、开启` 以及推送阈值设置`#体力设置群阈值120` 仅支持群操作 * 新增`#我的体力模板列表` -* 优化体力模板设置,支持多个设置 +* 优化体力模板设置,支持多个设置、移除 * 新增`#图鉴模板更新` * 用于更新体力模板具体来源由**@SunRyK** **@地球生物** **@逍遥** 三位作者上传 * 不会冲突已添加的模板数据,有需求可通过指令拉取 diff --git a/apps/Note.js b/apps/Note.js index 4e5d067..f03ef5b 100644 --- a/apps/Note.js +++ b/apps/Note.js @@ -232,9 +232,13 @@ export async function Note(e, { objFile = objFile[lodash.random(0, objFile.length - 1)] } let img_path = `./plugins/xiaoyao-cvs-plugin/resources/dailyNote/${path_img[mb]}`; - if (tempData[e.user_id] && tempData[e.user_id].type > -1) { + if (tempData[e.user_id] && tempData[e.user_id].type > -1&&tempData[e.user_id]?.temp?.length!==0) { // mb = tempData[e.user_id].type; - objFile = tempData[e.user_id].temp[lodash.random(0, tempData[e.user_id].temp.length - 1)]; + if (typeof tempData[e.user_id]["temp"] === "string") { + objFile = tempData[e.user_id]["temp"] + } else { + objFile = tempData[e.user_id].temp[lodash.random(0, tempData[e.user_id].temp.length - 1)]; + } if (objFile.includes(".")) { //对于模板类型处理 mb = 0; } else { @@ -400,8 +404,8 @@ export async function pokeNote(e, { export async function Note_appoint(e) { let mbPath = `${_path}/plugins/xiaoyao-cvs-plugin/resources/dailyNote/`; - let msg = e.msg.replace(/#|井|体力|模板|设置/g, ""); - + let isDel= e.msg.includes("移除") + let msg = e.msg.replace(/#|井|体力|模板|设置|移除/g, ""); let All = ["默认", "随机", "0"]; let urlType = note_file(); let keyType = Object.keys(urlType); @@ -416,7 +420,7 @@ export async function Note_appoint(e) { if (msg.includes("列表")) { let isUser = msg.includes('我的') let temp = tempData[e.user_id]?.temp; - if (!temp && isUser) { + if ((!temp||temp?.length===0) && isUser) { e.reply("未获取到您设置的模板信息哦~") return true; } @@ -430,7 +434,7 @@ export async function Note_appoint(e) { for (let [index, item] of keyType.entries()) { let msg_pass = []; let imgurl; - let pathFile=urlType[item].replace(/\./,_path) + let pathFile = urlType[item].replace(/\./, _path) if (item.includes(".")) { imgurl = await segment.image(`file:///${pathFile}`); item = item.split(".")[0]; @@ -490,8 +494,16 @@ export async function Note_appoint(e) { if (typeof tempData[e.user_id]["temp"] === "string") { temp = [tempData[e.user_id]["temp"], msg] } else { + temp =tempData[e.user_id]["temp"] if (!tempData[e.user_id]["temp"]?.includes(msg)) { - temp = [...tempData[e.user_id]["temp"], msg] + temp.push(msg) + } + } + let sendMsg="诶~这是你选的模板吗,模板设置成功了快用指令来试试吧~!" + if(isDel){ + if(temp.includes(msg)){ + temp.splice(temp.indexOf(msg),1) + sendMsg=`模板${msg}已移除~` } } tempData[e.user_id] = { @@ -500,7 +512,7 @@ export async function Note_appoint(e) { } fs.writeFileSync(tempDataUrl + "/tempData.json", JSON.stringify(tempData)); init() - e.reply("诶~这是你选的模板吗,模板设置成功了快用指令来试试吧~!") + e.reply(sendMsg) return true; } diff --git a/apps/index.js b/apps/index.js index e2edc07..00d3ee4 100644 --- a/apps/index.js +++ b/apps/index.js @@ -99,7 +99,7 @@ let rule = { describe: "体力推送", }, Note_appoint: { - reg: "^#体力模板(设置(.*)|列表(.*))|(#我的体力模板列表)$", + reg: "^#体力模板(设置(.*)|列表(.*))|(#我的体力模板列表|#体力模板移除(.*))$", describe: "体力模板设置", }, genShenMap: {