mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-22 06:58:24 +00:00
V3版本App格式适配
This commit is contained in:
parent
9b6122a25b
commit
97de796ea7
@ -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 {
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
6
index.js
6
index.js
@ -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}初始化~`)
|
||||
|
Loading…
Reference in New Issue
Block a user