From bf3d70576404f1b0b2b1769e3ecdf57462c2265c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=89=E9=A3=8E=E6=9D=A5?= <3139373986@qq.com> Date: Mon, 29 Apr 2024 23:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=A5=E5=BF=97=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assistant.js | 22 ++++++++++++++++++++++ components/Config.js | 33 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/apps/assistant.js b/apps/assistant.js index f81afda..ec0b2a7 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -2,7 +2,9 @@ import _ from "lodash" import { status } from "../constants/other.js" import { common, QQApi } from "../model/index.js" import { sleep } from "../tools/index.js" +import { Config } from "../components/index.js" import { API_ERROR } from "../constants/errorMsg.js" +import cfg from "../../../lib/config/config.js" // 命令正则 @@ -90,6 +92,10 @@ export class Assistant extends plugin { { reg: "^#?(查?看|取)头像", fnc: "LookAvatar" + }, + { + reg: "^#?(设置|修改)日志等级(.*)", + fnc: "logs" } ] }) @@ -624,4 +630,20 @@ export class Assistant extends plugin { await this.reply("❎ 获取头像错误", true) return false } + + // 设置日志等级 + async logs() { + if (!common.checkPermission(this.e, "master")) return + + const logs = [ "trace", "debug", "info", "warn", "fatal", "mark", "error", "off" ] + const level = this.e.msg.replace(/^#?(设置|修改)日志等级/, "").trim() + + if (!logs.includes(level)) return this.e.reply("❎ 请输入正确的参数,可选:\ntrace,debug,info,warn,fatal,mark,error,off") + + const { log_level } = cfg.bot + if (log_level === level) return this.e.reply(`❎ 日志等级已是${level}了`) + + Config.modify("bot", "log_level", level, "config", true) + this.e.reply(`✅ 已将日志等级设置为${level}`) + } } diff --git a/components/Config.js b/components/Config.js index 99fa246..03d3d1c 100644 --- a/components/Config.js +++ b/components/Config.js @@ -107,6 +107,7 @@ class Config { return this.getDefOrConfig("state") } + /** 群管 */ get groupAdmin() { return this.getDefOrConfig("groupAdmin") } @@ -181,19 +182,6 @@ class Config { this.watcher[key] = watcher } - /** - * 修改设置 - * @param {string} name 文件名 - * @param {string} key 修改的key值 - * @param {string | number} value 修改的value值 - * @param {'config'|'default_config'} type 配置文件或默认 - */ - modify(name, key, value, type = "config") { - let path = `${Plugin_Path}/config/${type}/${name}.yaml` - new YamlReader(path).set(key, value) - delete this.config[`${type}.${name}`] - } - /** * 群单独设置 * @param {string | number} groupId 群号 @@ -210,6 +198,20 @@ class Config { delete this.config["config.group"] } + /** + * 修改设置 + * @param {string} name 文件名 + * @param {string} key 修改的key值 + * @param {string | number} value 修改的value值 + * @param {'config'|'default_config'} type 配置文件或默认 + * @param {boolean} bot 是否修改Bot的配置 + */ + modify(name, key, value, type = "config", bot = false) { + let path = `${bot ? Path : Plugin_Path}/config/${type}/${name}.yaml` + new YamlReader(path).set(key, value) + delete this.config[`${type}.${name}`] + } + /** * 修改配置数组 * @param {string} name 文件名 @@ -217,9 +219,10 @@ class Config { * @param {string | number} value value * @param {'add'|'del'} category 类别 add or del * @param {'config'|'default_config'} type 配置文件或默认 + * @param {boolean} bot 是否修改Bot的配置 */ - modifyarr(name, key, value, category = "add", type = "config") { - let path = `${Plugin_Path}/config/${type}/${name}.yaml` + modifyarr(name, key, value, category = "add", type = "config", bot = false) { + let path = `${bot ? Path : Plugin_Path}/config/${type}/${name}.yaml` let yaml = new YamlReader(path) if (category == "add") { yaml.addIn(key, value)