fix: 优化解析

This commit is contained in:
ningmengchongshui 2024-06-09 23:18:36 +08:00
parent 8fc6650510
commit 068b0e60b7
3 changed files with 65 additions and 46 deletions

View File

@ -1,4 +1,3 @@
import fs from 'node:fs'
import lodash from 'lodash'
/**
@ -8,24 +7,28 @@ class ListenerLoader {
client = null
/**
*
* @param client Bot示例
*
* @param listener
* @param File
* @returns
*/
async load(client) {
this.client = client
const files = fs
.readdirSync('./src/core/events')
.filter(file => /(.ts|.js)$/.test(file))
for (let File of files) {
init = (listener, File: string) => {
try {
let listener = await import(`./events/${File}`)
if (!listener.default) return
/* eslint-disable new-cap */
if (!listener.default) continue
/**
*
*/
listener = new listener.default()
/**
*
*/
listener.client = this.client
/**
*
*/
const on = listener.once ? 'once' : 'on'
if (lodash.isArray(listener.event)) {
@ -44,6 +47,28 @@ class ListenerLoader {
logger.error(e)
}
}
/**
*
* @param client Bot示例
*/
async load(client) {
this.client = client
/**
* ****************
*
* *****************
*
*/
this.init(await import('./events/login.js'), './events/login.js')
this.init(await import('./events/message.js'), './events/message.js')
this.init(await import('./events/notice.js'), './events/notice.js')
this.init(await import('./events/offline.js'), './events/offline.js')
this.init(await import('./events/online.js'), './events/online.js')
this.init(await import('./events/request.js'), './events/request.js')
}
}

View File

@ -67,25 +67,18 @@ export class plugin {
event && (this.event = event)
priority && (this.priority = priority)
/** 插件名称 */
this.name = name
/** 插件描述 */
this.dsc = dsc
/** 监听事件默认message https://oicqjs.github.io/oicq/#events */
this.event = event
/** 优先级 */
this.priority = priority
/** 定时任务,可以是数组 */
this.task = {
task && (this.task = {
/** 任务名 */
name: '',
name: task?.name ?? '',
/** 任务方法名 */
fnc: task.fnc || '',
fnc: task?.fnc ?? '',
/** 任务cron表达式 */
cron: task.cron || ''
}
cron: task?.cron ?? ''
})
/** 命令规则 */
this.rule = rule
rule && (this.rule = rule)
if (handler) {
this.handler = handler

View File

@ -643,16 +643,17 @@ class PluginsLoader {
*/
collectTask(task) {
for (const i of Array.isArray(task) ? task : [task])
if (i.cron && i.name)
if (i?.cron && i?.name){
this.task.push(i)
}
}
/**
*
*/
createTask() {
for (const i of this.task)
i.job = schedule.scheduleJob(i.cron, async () => {
i.job = schedule.scheduleJob(i?.cron, async () => {
try {
if (i.log == true)
logger.mark(`开始定时任务:${i.name}`)