新增 Bot 单独设置
This commit is contained in:
		
							parent
							
								
									222239b730
								
							
						
					
					
						commit
						067497fe20
					
				| 
						 | 
					@ -15,12 +15,23 @@ default:
 | 
				
			||||||
  enable:          #只启用功能,配置后只有该功能才响应
 | 
					  enable:          #只启用功能,配置后只有该功能才响应
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #禁用功能,功能名称,例如:十连、角色查询、体力查询、用户绑定、抽卡记录、添加表情、欢迎新人、退群通知
 | 
					  #禁用功能,功能名称,例如:十连、角色查询、体力查询、用户绑定、抽卡记录、添加表情、欢迎新人、退群通知
 | 
				
			||||||
  #禁用功能,功能名称,例如:云崽帮助、角色素材、今日素材、养成计算、米游社公告
 | 
					 | 
				
			||||||
  disable:
 | 
					  disable:
 | 
				
			||||||
    - 禁用示例
 | 
					    - 禁用示例
 | 
				
			||||||
    - 支持多个
 | 
					    - 支持多个
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 群单独设置,自动覆盖默认值
 | 
					# Bot单独设置
 | 
				
			||||||
 | 
					114514:default:
 | 
				
			||||||
 | 
					  onlyReplyAt: 1
 | 
				
			||||||
 | 
					  botAlias:
 | 
				
			||||||
 | 
					    - 臭崽
 | 
				
			||||||
 | 
					    - 臭宝
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 群单独设置
 | 
				
			||||||
123456:
 | 
					123456:
 | 
				
			||||||
  groupCD:  500    # 群聊中所有指令操作冷却时间,单位毫秒,0则无限制
 | 
					  groupCD:  500
 | 
				
			||||||
  singleCD: 2000   # 群聊中个人操作冷却时间,单位毫秒
 | 
					  singleCD: 2000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# [Bot:群]单独设置
 | 
				
			||||||
 | 
					114514:123456:
 | 
				
			||||||
 | 
					  enable:
 | 
				
			||||||
 | 
					  disable:
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
import YAML from 'yaml'
 | 
					import YAML from "yaml"
 | 
				
			||||||
import fs from 'node:fs'
 | 
					import fs from "node:fs"
 | 
				
			||||||
import chokidar from 'chokidar'
 | 
					import chokidar from "chokidar"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 配置文件 */
 | 
					/** 配置文件 */
 | 
				
			||||||
class Cfg {
 | 
					class Cfg {
 | 
				
			||||||
| 
						 | 
					@ -15,40 +15,40 @@ class Cfg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 初始化配置 */
 | 
					  /** 初始化配置 */
 | 
				
			||||||
  initCfg () {
 | 
					  initCfg () {
 | 
				
			||||||
    let path = './config/config/'
 | 
					    let path = "./config/config/"
 | 
				
			||||||
    let pathDef = './config/default_config/'
 | 
					    let pathDef = "./config/default_config/"
 | 
				
			||||||
    const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'))
 | 
					    const files = fs.readdirSync(pathDef).filter(file => file.endsWith(".yaml"))
 | 
				
			||||||
    for (let file of files)
 | 
					    for (let file of files)
 | 
				
			||||||
      if (!fs.existsSync(`${path}${file}`))
 | 
					      if (!fs.existsSync(`${path}${file}`))
 | 
				
			||||||
        fs.copyFileSync(`${pathDef}${file}`, `${path}${file}`)
 | 
					        fs.copyFileSync(`${pathDef}${file}`, `${path}${file}`)
 | 
				
			||||||
    if (!fs.existsSync('./data')) fs.mkdirSync('./data')
 | 
					    if (!fs.existsSync("./data")) fs.mkdirSync("./data")
 | 
				
			||||||
    if (!fs.existsSync('./resources')) fs.mkdirSync('./resources')
 | 
					    if (!fs.existsSync("./resources")) fs.mkdirSync("./resources")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** Bot配置 */
 | 
					  /** Bot配置 */
 | 
				
			||||||
  get bot () {
 | 
					  get bot () {
 | 
				
			||||||
    let bot = this.getConfig('bot')
 | 
					    let bot = this.getConfig("bot")
 | 
				
			||||||
    let defbot = this.getdefSet('bot')
 | 
					    let defbot = this.getdefSet("bot")
 | 
				
			||||||
    bot = { ...defbot, ...bot }
 | 
					    bot = { ...defbot, ...bot }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return bot
 | 
					    return bot
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get other () {
 | 
					  get other () {
 | 
				
			||||||
    return this.getConfig('other')
 | 
					    return this.getConfig("other")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get redis () {
 | 
					  get redis () {
 | 
				
			||||||
    return this.getConfig('redis')
 | 
					    return this.getConfig("redis")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get renderer() {
 | 
					  get renderer() {
 | 
				
			||||||
    return this.getConfig('renderer');
 | 
					    return this.getConfig("renderer");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 主人账号 */
 | 
					  /** 主人账号 */
 | 
				
			||||||
  get masterQQ () {
 | 
					  get masterQQ () {
 | 
				
			||||||
    let masterQQ = this.getConfig('other').masterQQ || []
 | 
					    let masterQQ = this.getConfig("other").masterQQ || []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!Array.isArray(masterQQ))
 | 
					    if (!Array.isArray(masterQQ))
 | 
				
			||||||
      masterQQ = [masterQQ]
 | 
					      masterQQ = [masterQQ]
 | 
				
			||||||
| 
						 | 
					@ -61,14 +61,14 @@ class Cfg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** Bot账号:[主人帐号] */
 | 
					  /** Bot账号:[主人帐号] */
 | 
				
			||||||
  get master () {
 | 
					  get master () {
 | 
				
			||||||
    let master = this.getConfig('other').master || []
 | 
					    let master = this.getConfig("other").master || []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!Array.isArray(master))
 | 
					    if (!Array.isArray(master))
 | 
				
			||||||
      master = [master]
 | 
					      master = [master]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const masters = {}
 | 
					    const masters = {}
 | 
				
			||||||
    for (let i of master) {
 | 
					    for (let i of master) {
 | 
				
			||||||
      i = i.split(':')
 | 
					      i = i.split(":")
 | 
				
			||||||
      if (Array.isArray(masters[i[0]]))
 | 
					      if (Array.isArray(masters[i[0]]))
 | 
				
			||||||
        masters[i[0]].push(i[1])
 | 
					        masters[i[0]].push(i[1])
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
| 
						 | 
					@ -89,24 +89,27 @@ class Cfg {
 | 
				
			||||||
  get package () {
 | 
					  get package () {
 | 
				
			||||||
    if (this._package) return this._package
 | 
					    if (this._package) return this._package
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this._package = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
 | 
					    this._package = JSON.parse(fs.readFileSync("./package.json", "utf8"))
 | 
				
			||||||
    return this._package
 | 
					    return this._package
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 群配置 */
 | 
					  /** 群配置 */
 | 
				
			||||||
  getGroup (groupId = '') {
 | 
					  getGroup (bot_id = "", group_id = "") {
 | 
				
			||||||
    let config = this.getConfig('group')
 | 
					    const config = this.getConfig("group")
 | 
				
			||||||
    let defCfg = this.getdefSet('group')
 | 
					    const defCfg = this.getdefSet("group")
 | 
				
			||||||
    if (config[groupId]) {
 | 
					    return {
 | 
				
			||||||
      return { ...defCfg.default, ...config.default, ...config[groupId] }
 | 
					      ...defCfg.default,
 | 
				
			||||||
 | 
					      ...config.default,
 | 
				
			||||||
 | 
					      ...config[`${bot_id}:default`],
 | 
				
			||||||
 | 
					      ...config[group_id],
 | 
				
			||||||
 | 
					      ...config[`${bot_id}:${group_id}`],
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return { ...defCfg.default, ...config.default }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** other配置 */
 | 
					  /** other配置 */
 | 
				
			||||||
  getOther () {
 | 
					  getOther () {
 | 
				
			||||||
    let def = this.getdefSet('other')
 | 
					    let def = this.getdefSet("other")
 | 
				
			||||||
    let config = this.getConfig('other')
 | 
					    let config = this.getConfig("other")
 | 
				
			||||||
    return { ...def, ...config }
 | 
					    return { ...def, ...config }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,12 +118,12 @@ class Cfg {
 | 
				
			||||||
   * @param name 配置文件名称
 | 
					   * @param name 配置文件名称
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  getdefSet (name) {
 | 
					  getdefSet (name) {
 | 
				
			||||||
    return this.getYaml('default_config', name)
 | 
					    return this.getYaml("default_config", name)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 用户配置 */
 | 
					  /** 用户配置 */
 | 
				
			||||||
  getConfig (name) {
 | 
					  getConfig (name) {
 | 
				
			||||||
    return this.getYaml('config', name)
 | 
					    return this.getYaml("config", name)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -134,7 +137,7 @@ class Cfg {
 | 
				
			||||||
    if (this.config[key]) return this.config[key]
 | 
					    if (this.config[key]) return this.config[key]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.config[key] = YAML.parse(
 | 
					    this.config[key] = YAML.parse(
 | 
				
			||||||
      fs.readFileSync(file, 'utf8')
 | 
					      fs.readFileSync(file, "utf8")
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.watch(file, name, type)
 | 
					    this.watch(file, name, type)
 | 
				
			||||||
| 
						 | 
					@ -143,15 +146,15 @@ class Cfg {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 监听配置文件 */
 | 
					  /** 监听配置文件 */
 | 
				
			||||||
  watch (file, name, type = 'default_config') {
 | 
					  watch (file, name, type = "default_config") {
 | 
				
			||||||
    let key = `${type}.${name}`
 | 
					    let key = `${type}.${name}`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (this.watcher[key]) return
 | 
					    if (this.watcher[key]) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const watcher = chokidar.watch(file)
 | 
					    const watcher = chokidar.watch(file)
 | 
				
			||||||
    watcher.on('change', path => {
 | 
					    watcher.on("change", path => {
 | 
				
			||||||
      delete this.config[key]
 | 
					      delete this.config[key]
 | 
				
			||||||
      if (typeof Bot == 'undefined') return
 | 
					      if (typeof Bot == "undefined") return
 | 
				
			||||||
      logger.mark(`[修改配置文件][${type}][${name}]`)
 | 
					      logger.mark(`[修改配置文件][${type}][${name}]`)
 | 
				
			||||||
      if (this[`change_${name}`]) {
 | 
					      if (this[`change_${name}`]) {
 | 
				
			||||||
        this[`change_${name}`]()
 | 
					        this[`change_${name}`]()
 | 
				
			||||||
| 
						 | 
					@ -163,9 +166,9 @@ class Cfg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async change_bot () {
 | 
					  async change_bot () {
 | 
				
			||||||
    /** 修改日志等级 */
 | 
					    /** 修改日志等级 */
 | 
				
			||||||
    let log = await import('./log.js')
 | 
					    let log = await import("./log.js")
 | 
				
			||||||
    log.default()
 | 
					    log.default()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default new Cfg()
 | 
					export default new Cfg()
 | 
				
			||||||
| 
						 | 
					@ -431,7 +431,7 @@ class PluginsLoader {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 只关注主动at msg处理 */
 | 
					    /** 只关注主动at msg处理 */
 | 
				
			||||||
    if (e.msg && e.isGroup) {
 | 
					    if (e.msg && e.isGroup) {
 | 
				
			||||||
      let groupCfg = cfg.getGroup(e.group_id)
 | 
					      let groupCfg = cfg.getGroup(e.self_id, e.group_id)
 | 
				
			||||||
      let alias = groupCfg.botAlias
 | 
					      let alias = groupCfg.botAlias
 | 
				
			||||||
      if (!Array.isArray(alias)) {
 | 
					      if (!Array.isArray(alias)) {
 | 
				
			||||||
        alias = [alias]
 | 
					        alias = [alias]
 | 
				
			||||||
| 
						 | 
					@ -605,7 +605,7 @@ class PluginsLoader {
 | 
				
			||||||
    if (e.isGroup && e?.group?.mute_left > 0) return false
 | 
					    if (e.isGroup && e?.group?.mute_left > 0) return false
 | 
				
			||||||
    if (!e.message || e.isPrivate) return true
 | 
					    if (!e.message || e.isPrivate) return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = cfg.getGroup(e.group_id)
 | 
					    let config = cfg.getGroup(e.self_id, e.group_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.groupCD && this.groupCD[e.group_id]) {
 | 
					    if (config.groupCD && this.groupCD[e.group_id]) {
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
| 
						 | 
					@ -631,7 +631,7 @@ class PluginsLoader {
 | 
				
			||||||
  /** 设置冷却cd */
 | 
					  /** 设置冷却cd */
 | 
				
			||||||
  setLimit(e) {
 | 
					  setLimit(e) {
 | 
				
			||||||
    if (!e.message || e.isPrivate) return
 | 
					    if (!e.message || e.isPrivate) return
 | 
				
			||||||
    let config = cfg.getGroup(e.group_id)
 | 
					    let config = cfg.getGroup(e.self_id, e.group_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.groupCD) {
 | 
					    if (config.groupCD) {
 | 
				
			||||||
      this.groupCD[e.group_id] = true
 | 
					      this.groupCD[e.group_id] = true
 | 
				
			||||||
| 
						 | 
					@ -652,7 +652,7 @@ class PluginsLoader {
 | 
				
			||||||
  onlyReplyAt(e) {
 | 
					  onlyReplyAt(e) {
 | 
				
			||||||
    if (!e.message || e.isPrivate) return true
 | 
					    if (!e.message || e.isPrivate) return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let groupCfg = cfg.getGroup(e.group_id)
 | 
					    let groupCfg = cfg.getGroup(e.self_id, e.group_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (groupCfg.onlyReplyAt != 1 || !groupCfg.botAlias) return true
 | 
					    if (groupCfg.onlyReplyAt != 1 || !groupCfg.botAlias) return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -693,7 +693,7 @@ class PluginsLoader {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 判断是否启用功能 */
 | 
					  /** 判断是否启用功能 */
 | 
				
			||||||
  checkDisable(e, p) {
 | 
					  checkDisable(e, p) {
 | 
				
			||||||
    let groupCfg = cfg.getGroup(e.group_id)
 | 
					    let groupCfg = cfg.getGroup(e.self_id, e.group_id)
 | 
				
			||||||
    if (!lodash.isEmpty(groupCfg.enable)) {
 | 
					    if (!lodash.isEmpty(groupCfg.enable)) {
 | 
				
			||||||
      if (groupCfg.enable.includes(p.name)) {
 | 
					      if (groupCfg.enable.includes(p.name)) {
 | 
				
			||||||
        return true
 | 
					        return true
 | 
				
			||||||
| 
						 | 
					@ -831,4 +831,4 @@ class PluginsLoader {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default new PluginsLoader()
 | 
					export default new PluginsLoader()
 | 
				
			||||||
| 
						 | 
					@ -121,7 +121,7 @@ export class add extends plugin {
 | 
				
			||||||
  checkAuth () {
 | 
					  checkAuth () {
 | 
				
			||||||
    if (this.e.isMaster) return true
 | 
					    if (this.e.isMaster) return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
    if (groupCfg.imgAddLimit == 2) {
 | 
					    if (groupCfg.imgAddLimit == 2) {
 | 
				
			||||||
      this.e.reply('暂无权限,只有主人才能操作')
 | 
					      this.e.reply('暂无权限,只有主人才能操作')
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
| 
						 | 
					@ -204,7 +204,7 @@ export class add extends plugin {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 过滤别名 */
 | 
					  /** 过滤别名 */
 | 
				
			||||||
  trimAlias (msg) {
 | 
					  trimAlias (msg) {
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
    let alias = groupCfg.botAlias
 | 
					    let alias = groupCfg.botAlias
 | 
				
			||||||
    if (!Array.isArray(alias)) {
 | 
					    if (!Array.isArray(alias)) {
 | 
				
			||||||
      alias = [alias]
 | 
					      alias = [alias]
 | 
				
			||||||
| 
						 | 
					@ -284,7 +284,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async saveImg (url, keyWord) {
 | 
					  async saveImg (url, keyWord) {
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
    let savePath = `${this.facePath}${this.group_id}/`
 | 
					    let savePath = `${this.facePath}${this.group_id}/`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!fs.existsSync(savePath)) {
 | 
					    if (!fs.existsSync(savePath)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue