From 33bfc66a77b9eaa1dd67097f9184db33e71a498d Mon Sep 17 00:00:00 2001 From: leiyilu <1509167646@qq.com> Date: Thu, 23 Jun 2022 23:06:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=93=E5=8A=9B=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/Note.js | 6 ++++++ apps/admin.js | 50 +++++++++++++++++++++++++++++++++++++++++---- apps/help.js | 2 +- components/Cfg.js | 4 ++-- components/cfg.json | 3 ++- index.js | 4 ++-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/apps/Note.js b/apps/Note.js index f7bb7d3..343daf4 100644 --- a/apps/Note.js +++ b/apps/Note.js @@ -8,6 +8,9 @@ import format from "date-format"; import puppeteer from "puppeteer"; import common from "../../../lib/common.js"; import lodash from "lodash"; +import { + Cfg +} from "../components/index.js"; // import MysApi from "../components/MysApi.js" import { @@ -21,6 +24,9 @@ const _path = process.cwd(); export async function Note(e, { render }) { + if(!Cfg.get("sys.Note")){ + return false; + } let cookie, uid; if (NoteCookie[e.user_id]) { cookie = NoteCookie[e.user_id].cookie; diff --git a/apps/admin.js b/apps/admin.js index 8b95025..fd5713b 100644 --- a/apps/admin.js +++ b/apps/admin.js @@ -17,11 +17,12 @@ import { init } from "../apps/xiaoyao_image.js" - const require = createRequire( import.meta.url); - - +let cfgMap = { + "体力": "sys.Note", +}; +let sysCfgReg = `^#图鉴设置\s*(${lodash.keys(cfgMap).join("|")})?\s*(.*)$`; export const rule = { updateRes: { hashMark: true, @@ -33,7 +34,11 @@ export const rule = { reg: "^#图鉴插件(强制)?更新", describe: "【#管理】图鉴更新", }, - + sysCfg: { + hashMark: true, + reg: sysCfgReg, + describe: "【#管理】系统设置" + } }; @@ -41,6 +46,43 @@ const _path = process.cwd(); const resPath = `${_path}/plugins/xiaoyao-cvs-plugin/resources/`; const plusPath = `${resPath}/xiaoyao-plus/`; +export async function sysCfg(e, { + render +}) { + if (!await checkAuth(e)) { + return true; + } + + let cfgReg = new RegExp(sysCfgReg); + let regRet = cfgReg.exec(e.msg); + + if (!regRet) { + return true; + } + console.log(regRet) + if (regRet[1]) { + // 设置模式 + let val = regRet[2] || ""; + + let cfgKey = cfgMap[regRet[1]]; + + if (cfgKey === "sys.scale") { + val = Math.min(200, Math.max(50, val * 1 || 100)); + } else { + val = !/关闭/.test(val); + } + if (cfgKey) { + console.log(val) + Cfg.set(cfgKey, val); + } + } + e.reply("设置成功!!"); + return true; + // //渲染图像 + // return await Common.render("admin/index", { + // ...cfg, + // }, { e, render, scale: 1.4 }); +} const checkAuth = async function(e) { return await e.checkAuth({ auth: "master", diff --git a/apps/help.js b/apps/help.js index 7314b7a..65cf69d 100644 --- a/apps/help.js +++ b/apps/help.js @@ -9,4 +9,4 @@ export async function calendar(e) { export async function versionInfo(e) { e.reply("当前图鉴版本:1.0.1") return true; -} \ No newline at end of file +} diff --git a/components/Cfg.js b/components/Cfg.js index 2561a91..44557c5 100644 --- a/components/Cfg.js +++ b/components/Cfg.js @@ -2,7 +2,7 @@ import fs from "fs"; import lodash from "lodash"; const _path = process.cwd(); -const _cfgPath = `${_path}/plugins/miao-plugin/components/`; +const _cfgPath = `${_path}/plugins/xiaoyao-cvs-plugin/components/`; let cfg = {}; try { @@ -31,7 +31,7 @@ let Cfg = { if (Cfg.get(rote, true)) { return false; } - if (/^#*喵喵/.test(e.msg || "")) { + if (/^#*图鉴/.test(e.msg || "")) { return false; } return true; diff --git a/components/cfg.json b/components/cfg.json index 9135015..877284b 100644 --- a/components/cfg.json +++ b/components/cfg.json @@ -1,5 +1,6 @@ { "sys": { - "help": true + "help": true, + "Note": false } } \ No newline at end of file diff --git a/index.js b/index.js index 12c7d3a..d09579b 100644 --- a/index.js +++ b/index.js @@ -11,13 +11,13 @@ import { } from "./apps/Note.js" import { rule as adminRule, - updateRes, + updateRes,sysCfg, updateMiaoPlugin } from "./apps/admin.js"; export { updateRes, updateMiaoPlugin, - versionInfo, + versionInfo,sysCfg, calendar, AtlasAlias, Note