diff --git a/adapter/index.js b/adapter/index.js index 1bf905e5..1a28ebd1 100644 --- a/adapter/index.js +++ b/adapter/index.js @@ -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 { diff --git a/apps/index.js b/apps/index.js index 3e8f9dd0..1a16be07 100644 --- a/apps/index.js +++ b/apps/index.js @@ -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 } diff --git a/components/App.js b/components/App.js index 830b3ae3..2eb137ac 100644 --- a/components/App.js +++ b/components/App.js @@ -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 } diff --git a/index.js b/index.js index e3cd14f6..f7a4f638 100644 --- a/index.js +++ b/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}初始化~`)