From f4a068d5a49deddc4ebaa7f77e535bad2df45e9d Mon Sep 17 00:00:00 2001 From: "Lain." <1072411694@qq.com> Date: Mon, 15 Apr 2024 20:14:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=97=A5=E5=BF=97=EF=BC=8C=E7=B1=BB=E5=9E=8B=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.cjs | 1 - .vscode/settings.json | 4 ++-- index.js | 2 +- lib/adapter/onebot/OneBot11.js | 2 +- lib/index.js | 1 - lib/plugins/loader.js | 18 ++++++------------ 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 227680c4..7b8cd14b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -9,7 +9,6 @@ module.exports = { sourceType: 'module' }, globals: { - Karin: true, logger: true }, rules: { diff --git a/.vscode/settings.json b/.vscode/settings.json index 0303e9ef..ee6f6c53 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "editor.detectIndentation": false, "editor.tabSize": 2, - "editor.formatOnSave": false, + "editor.formatOnSave": true, "javascript.format.insertSpaceBeforeFunctionParenthesis": true, "javascript.format.insertSpaceAfterConstructor": true -} +} \ No newline at end of file diff --git a/index.js b/index.js index 12d106d5..6e441c7c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -import Bot from './lib/config/index.js' import logger from './lib/config/log.js' +import Bot from './lib/config/index.js' /** 初始化Bot */ await Bot.start() diff --git a/lib/adapter/onebot/OneBot11.js b/lib/adapter/onebot/OneBot11.js index db3a97d4..c393ed18 100644 --- a/lib/adapter/onebot/OneBot11.js +++ b/lib/adapter/onebot/OneBot11.js @@ -94,7 +94,7 @@ class OneBot11 { const timer = setInterval(() => { if (this.account.nickname) { const { app_name, app_version } = this.version - this.logger('info', `建立连接成功:[${app_name}(${app_version})]${this.url}`) + this.logger('info', `建立连接成功:[${app_name}(${app_version})] ${this.url}`) clearInterval(timer) resolve(true) } diff --git a/lib/index.js b/lib/index.js index 88d4ad3f..743c9652 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,4 +10,3 @@ import Renderer from './Renderer/Renderer.js' import { kritor } from './adapter/kritor/protos/compiled.js' export { App, Bot, Cfg, common, logger, plugin, redis, segment, Renderer, kritor } -export default { App, Bot, Cfg, common, logger, plugin, redis, segment, Renderer, kritor } diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 6bad585b..23862139 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -27,7 +27,7 @@ class Plugins { * priority: number, * permission: string, * accept: boolean, - * rule: Array<{reg: RegExp, fnc: string, event?: string, permission?: string, log?: boolean}>, + * rule: Array<{reg: RegExp, fnc: string, event?: string, permission?: string, log?: Function}>, * }[]} */ this.Apps = [] @@ -38,7 +38,8 @@ class Plugins { * file: { name: string, dir: string }, * cron: string, * fnc: string, - * log: boolean + * log: Function, + * name: string * }>} */ this.task = [] @@ -172,13 +173,6 @@ class Plugins { /** 执行初始化 */ Class.init && Class.init() - /** 注册handler */ - lodash.forEach(Class.handler, ({ fnc, key, name = Class.name, priority = Class.priority }) => { - const self = Class - fnc = Class[fnc] - Handler.add({ name, key, priority, self, fnc }) - }) - /** 收集定时任务 */ lodash.forEach(Class.task, (val) => { if (!val.name) return logger.error(`[${dir}][${name}] 定时任务name错误`) @@ -237,13 +231,13 @@ class Plugins { val.log = val.log === false ? () => '' : (log) => logger.mark(log) val.schedule = schedule.scheduleJob(val.cron, async () => { try { - val.log(`[定时任务][${val.name}] 开始执行`) + val.log(`[定时任务][${val.file.dir}][${val.name}] 开始执行`) const App = new val.App() let res = App[val.fnc] && App[val.fnc]() if (util.types.isPromise(res)) res = await res - val.log(`[定时任务][${val.name}] 执行完毕`) + val.log(`[定时任务][${val.file.dir}][${val.name}] 执行完毕`) } catch (error) { - logger.error(`[定时任务][${val.name}] 执行报错`) + logger.error(`[定时任务][${val.file.dir}][${val.name}] 执行报错`) logger.error(error) } })