2022-07-30 20:20:10 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import lodash from 'lodash'
|
2022-04-09 21:33:21 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
const _path = process.cwd()
|
|
|
|
const _cfgPath = `${_path}/plugins/miao-plugin/components/`
|
|
|
|
let cfg = {}
|
2022-04-09 21:33:21 +00:00
|
|
|
|
|
|
|
try {
|
2022-07-30 20:20:10 +00:00
|
|
|
if (fs.existsSync(_cfgPath + 'cfg.json')) {
|
|
|
|
cfg = JSON.parse(fs.readFileSync(_cfgPath + 'cfg.json', 'utf8')) || {}
|
2022-04-09 21:33:21 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// do nth
|
|
|
|
}
|
|
|
|
|
|
|
|
let Cfg = {
|
2022-07-30 20:20:10 +00:00
|
|
|
get (rote, def = '') {
|
|
|
|
return lodash.get(cfg, rote, def)
|
2022-04-09 21:33:21 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
set (rote, val) {
|
|
|
|
lodash.set(cfg, rote, val)
|
|
|
|
fs.writeFileSync(_cfgPath + 'cfg.json', JSON.stringify(cfg, null, '\t'))
|
2022-04-09 21:33:21 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
del (rote) {
|
|
|
|
lodash.set(cfg, rote, undefined)
|
|
|
|
fs.writeFileSync(_cfgPath + 'cfg.json', JSON.stringify(cfg, null, '\t'))
|
2022-05-28 21:18:13 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
scale (pct = 1) {
|
|
|
|
let scale = Cfg.get('sys.scale', 100)
|
|
|
|
scale = Math.min(2, Math.max(0.5, scale / 100))
|
|
|
|
pct = pct * scale
|
|
|
|
return `style=transform:scale(${pct})`
|
2022-04-09 21:33:21 +00:00
|
|
|
},
|
2022-07-30 20:20:10 +00:00
|
|
|
isDisable (e, rote) {
|
2022-04-09 21:33:21 +00:00
|
|
|
if (Cfg.get(rote, true)) {
|
2022-07-30 20:20:10 +00:00
|
|
|
return false
|
2022-04-09 21:33:21 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
if (/^#*喵喵/.test(e.msg || '')) {
|
|
|
|
return false
|
2022-04-09 21:33:21 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
return true
|
2022-04-09 21:33:21 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
}
|
2022-04-09 21:33:21 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
export default Cfg
|