新增设置日志等级

This commit is contained in:
等风来
2024-04-29 23:13:05 +08:00
parent 09eef30498
commit bf3d705764
2 changed files with 40 additions and 15 deletions

View File

@@ -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}`)
}
}

View File

@@ -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)