V3版本App格式适配

This commit is contained in:
yoimiya-kokomi 2022-09-17 05:45:10 +08:00
parent 9b6122a25b
commit 97de796ea7
4 changed files with 45 additions and 19 deletions

View File

@ -10,7 +10,7 @@ const importV3 = async function (file, def, key = 'default') {
return def
}
let MysInfo = await importV3('/plugins/genshin/model/mys/mysInfo.js')
let MysInfo = await importV3('/plugins/genshin/model/mys/mysInfo.js', {})
let plugin = await importV3('lib/plugins/plugin.js', _plugin)
let puppeteer = _puppeteer
export {

View File

@ -10,12 +10,12 @@ export const helpApp = help.v2()
export const statApp = stat.v2()
export const wikiApp = wiki.v2()
let rule = {
characterApp: character.rule(),
adminApp: character.rule(),
helpApp: help.rule(),
statApp: stat.rule(),
wikiApp: wiki.rule()
let apps = { character, admin, help, stat, wiki }
let rule = {} // v2
let rules = {} // v3
for (let key in apps) {
rule[`${key}App`] = apps[key].rule()
rules[`${key}`] = apps[key].app()
}
export { rule }
export { rule, rules as apps }

View File

@ -1,4 +1,6 @@
import lodash from 'lodash'
import { plugin } from '../adapter/index.js'
import { getMysApi, checkAuth } from '../adapter/mys.js'
class App {
constructor (cfg) {
@ -8,16 +10,16 @@ class App {
}
reg (key, fn, cfg = {}) {
//TODO: 参数校验
this.apps[key] = {
fn,
...cfg
}
}
getPlugins () {
app () {
let cfg = this.cfg || {}
let rule = this.getV3Rule()
let rules = []
let cls = class extends plugin {
constructor () {
super({
@ -25,14 +27,42 @@ class App {
desc: cfg.desc || '喵喵插件',
event: 'message',
priority: 50,
rule
rule: rules
})
}
}
async app (e) {
for (let key in this.apps) {
let app = this.apps[key]
key = lodash.camelCase(key)
let rule = app.rule || app.reg || 'noCheck'
if (typeof (rule) === 'string') {
if (rule === '#poke#') {
continue
} else if (rule === 'noCheck') {
rule = '.+'
}
} else {
rule = lodash.trim(rule.toString(), '/')
}
rules.push({
reg: rule,
fnc: key
})
cls.prototype[key] = async function () {
let e = this.e
e.original_msg = e.original_msg || e.msg
e.checkAuth = e.checkAuth || async function (cfg) {
return await checkAuth(e, cfg)
}
e.getMysApi = e.getMysApi || async function (cfg) {
return await getMysApi(e, cfg)
}
return await app.fn.call(this, e)
}
}
cls.test = 1
return cls
}

View File

@ -1,11 +1,7 @@
import { Data, Version } from './components/index.js'
export * from './apps/index.js'
let index = { miao: {} }
if (Version.isV3) {
index = await Data.importModule('adapter/v3-entrance.js')
}
export const miao = index.miao || {}
if (Bot?.logger?.info) {
Bot.logger.info('---------^_^---------')
Bot.logger.info(`喵喵插件${Version.version}初始化~`)