2022-07-23 20:32:10 +00:00
|
|
|
import lodash from 'lodash'
|
|
|
|
import fs from 'fs'
|
2022-09-16 20:37:09 +00:00
|
|
|
import { Cfg, Version, Common, App } from '../components/index.js'
|
|
|
|
|
|
|
|
let app = App.init({
|
|
|
|
id: 'help',
|
|
|
|
name: '喵喵帮助',
|
|
|
|
desc: '喵喵帮助'
|
|
|
|
})
|
|
|
|
|
|
|
|
app.reg('help', help, {
|
|
|
|
rule: /^#?(喵喵)?(命令|帮助|菜单|help|说明|功能|指令|使用说明)$/,
|
|
|
|
desc: '【#帮助】 #喵喵帮助'
|
|
|
|
})
|
|
|
|
|
|
|
|
app.reg('version', versionInfo, {
|
|
|
|
rule: /^#?喵喵版本$/,
|
|
|
|
desc: '【#帮助】 喵喵版本介绍'
|
|
|
|
})
|
|
|
|
|
|
|
|
export default app
|
2022-04-10 20:48:53 +00:00
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
const _path = process.cwd()
|
|
|
|
const helpPath = `${_path}/plugins/miao-plugin/resources/help`
|
2022-04-10 20:48:53 +00:00
|
|
|
|
2022-09-16 20:37:09 +00:00
|
|
|
async function help (e) {
|
2022-07-23 20:32:10 +00:00
|
|
|
if (!/喵喵/.test(e.msg) && !Cfg.get('sys.help', false)) {
|
|
|
|
return false
|
2022-04-10 21:11:39 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:37:09 +00:00
|
|
|
let custom = {}
|
2022-08-18 10:13:42 +00:00
|
|
|
let help = {}
|
2022-06-28 20:30:34 +00:00
|
|
|
if (fs.existsSync(`${helpPath}/help-cfg.js`)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
help = await import(`file://${helpPath}/help-cfg.js?version=${new Date().getTime()}`)
|
2022-06-28 20:30:34 +00:00
|
|
|
} else if (fs.existsSync(`${helpPath}/help-list.js`)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
help = await import(`file://${helpPath}/help-list.js?version=${new Date().getTime()}`)
|
2022-06-28 20:30:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 兼容一下旧字段
|
|
|
|
if (lodash.isArray(help.helpCfg)) {
|
|
|
|
custom = {
|
|
|
|
helpList: help.helpCfg,
|
|
|
|
helpCfg: {}
|
2022-07-23 20:32:10 +00:00
|
|
|
}
|
2022-06-28 20:30:34 +00:00
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
custom = help
|
2022-06-28 20:30:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
let def = await import(`file://${helpPath}/help-cfg_default.js?version=${new Date().getTime()}`)
|
2022-06-28 20:30:34 +00:00
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
let helpCfg = lodash.defaults(custom.helpCfg, def.helpCfg)
|
|
|
|
let helpList = custom.helpList || def.helpList
|
2022-04-10 20:48:53 +00:00
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
let helpGroup = []
|
2022-04-10 20:48:53 +00:00
|
|
|
|
2022-06-28 20:30:34 +00:00
|
|
|
lodash.forEach(helpList, (group) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
if (group.auth && group.auth === 'master' && !e.isMaster) {
|
|
|
|
return
|
2022-04-12 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2022-04-10 20:48:53 +00:00
|
|
|
lodash.forEach(group.list, (help) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
let icon = help.icon * 1
|
2022-04-10 20:48:53 +00:00
|
|
|
if (!icon) {
|
2022-07-23 20:32:10 +00:00
|
|
|
help.css = 'display:none'
|
2022-04-10 20:48:53 +00:00
|
|
|
} else {
|
2022-09-16 20:37:09 +00:00
|
|
|
let x = (icon - 1) % 10
|
2022-08-18 10:13:42 +00:00
|
|
|
let y = (icon - x - 1) / 10
|
2022-07-23 20:32:10 +00:00
|
|
|
help.css = `background-position:-${x * 50}px -${y * 50}px`
|
2022-04-10 20:48:53 +00:00
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
})
|
2022-04-10 20:48:53 +00:00
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
helpGroup.push(group)
|
|
|
|
})
|
2022-04-12 19:28:01 +00:00
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
return await Common.render('help/index', {
|
2022-06-28 20:30:34 +00:00
|
|
|
helpCfg,
|
|
|
|
helpGroup,
|
2022-05-22 13:10:10 +00:00
|
|
|
element: 'default'
|
2022-08-24 01:07:06 +00:00
|
|
|
}, { e, scale: 1.2 })
|
2022-04-26 19:15:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:37:09 +00:00
|
|
|
async function versionInfo (e) {
|
2022-07-23 20:32:10 +00:00
|
|
|
return await Common.render('help/version-info', {
|
2022-08-18 10:13:42 +00:00
|
|
|
currentVersion: Version.version,
|
|
|
|
changelogs: Version.changelogs,
|
2022-07-23 20:32:10 +00:00
|
|
|
elem: 'cryo'
|
2022-08-24 01:07:06 +00:00
|
|
|
}, { e, scale: 1.2 })
|
2022-07-23 20:32:10 +00:00
|
|
|
}
|