Skip to content

Commit

Permalink
#铃推送fix: 修复Karin设置失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yusheng929 committed Aug 28, 2024
1 parent 4d33b69 commit e7c08da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
24 changes: 13 additions & 11 deletions apps/KarinSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const CfgReg = `^#?(Karin|karin|卡莲)设置\\s*(${lodash.keys(cfgMap).join('|'

export const set = karin.command(CfgReg, async (e) => {
const reg = new RegExp(CfgReg).exec(e.msg)

if (reg && reg[1]) {
let val = reg[2] || ''
let cfgKey = cfgMap[reg[1]]
if (reg && reg[2]) {
let val = reg[3] || ''
let cfgKey = cfgMap[reg[2]]
if (val.includes('开启') || val.includes('关闭')) {
val = !/关闭/.test(val)
} else {
Expand Down Expand Up @@ -57,9 +56,7 @@ const setCfg = function (rote, value, def = false) {
const arr = rote?.split('_') || []
if (arr.length > 0) {
const type = arr[0]; const name = arr[1]
const data = Cfg.getYaml(def ? 'defSet' : 'config', type) || {}
data[name] = value
Config.save(type, def ? 'defSet' : 'config', data)
Config.save(type, def ? 'defSet' : 'config', name, value)
}
}

Expand All @@ -70,11 +67,16 @@ const getStatus = function (rote, def = false) {
if (arr.length > 0) {
const type = arr[0]; const name = arr[1]
const data = Cfg.getYaml(def ? 'defSet' : 'config', type) || {}
if (data[name] === true || data[name] === false) {
_class = data[name] === false ? `${_class} status-off` : _class
value = data[name] === true ? '已开启' : '已关闭'
const keys = name.split('.')
let datas = data
for (const types of keys) {
datas = datas[types];
}
if (datas === true || datas === false) {
_class = datas === false ? `${_class} status-off` : _class
value = datas === true ? '已开启' : '已关闭'
} else {
value = data[name]
value = datas
}
}
if (!value) {
Expand Down
21 changes: 11 additions & 10 deletions lib/Config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import YAML from 'yaml'
import fs from 'node:fs'
import lodash from 'lodash'
import { YamlEditor } from 'node-karin'


class Config {
Expand All @@ -17,15 +16,17 @@ class Config {
return file;
}

save (name, type, data) {
let file = this.getFilePath(name, type)
if (lodash.isEmpty(data)) {
fs.existsSync(file) && fs.unlinkSync(file)
} else {
let yaml = YAML.stringify(data)
fs.writeFileSync(file, yaml, 'utf8')
}
save (name, type, data, other) {
try {
let file = this.getFilePath(name, type)
const Yaml = new YamlEditor(file)
const ConfigFile = Yaml.get(other)
Yaml.set(data, other)
Yaml.save()
} catch (error) {
console.error(error)
}
}

}
export default new Config()
2 changes: 1 addition & 1 deletion state/Disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ const Disk = () => {
}

export default {
getDisk
Disk
}

0 comments on commit e7c08da

Please sign in to comment.