diff --git a/packages/plugin-common/src/index.ts b/packages/plugin-common/src/index.ts index c2bb4f3f88..4e0b94bf86 100644 --- a/packages/plugin-common/src/index.ts +++ b/packages/plugin-common/src/index.ts @@ -14,7 +14,6 @@ export interface Config extends HandlerOptions, RepeaterOptions, SenderConfig { contextify?: false echo?: false info?: false - usage?: false debug?: DebugOptions } @@ -29,5 +28,4 @@ export function apply(ctx: Context, config: Config = {}) { if (config.contextify !== false) ctx.plugin(require('./contextify')) if (config.debug) ctx.plugin(require('./debug'), config.debug) if (config.info !== false) ctx.plugin(require('./info')) - if (config.usage !== false) ctx.plugin(require('./usage')) } diff --git a/packages/plugin-schedule/src/index.ts b/packages/plugin-schedule/src/index.ts index 4e0e42ce78..4a2eb2e9b6 100644 --- a/packages/plugin-schedule/src/index.ts +++ b/packages/plugin-schedule/src/index.ts @@ -6,18 +6,23 @@ export * from './database' const logger = new Logger('schedule') -function inspectSchedule({ id, session, interval, command, time }: Schedule) { +function prepareSchedule({ id, session, interval, command, time }: Schedule) { const now = Date.now() const date = time.valueOf() const { database } = session.$app - logger.debug('inspect', command) + logger.debug('prepare %d: %c at %s', id, command, time) + + function executeSchedule() { + logger.debug('execute %d: %c', id, command) + return session.$execute(command) + } if (!interval) { if (date < now) return database.removeSchedule(id) return setTimeout(async () => { if (!await database.getSchedule(id)) return - session.$execute(command) - database.removeSchedule(id) + await database.removeSchedule(id) + await executeSchedule() }, date - now) } @@ -26,9 +31,9 @@ function inspectSchedule({ id, session, interval, command, time }: Schedule) { if (!await database.getSchedule(id)) return const timer = setInterval(async () => { if (!await database.getSchedule(id)) return clearInterval(timer) - session.$execute(command) + await executeSchedule() }, interval) - session.$execute(command) + await executeSchedule() }, timeout) } @@ -46,7 +51,7 @@ export function apply(ctx: Context) { schedules.forEach((schedule) => { if (!ctx.bots[schedule.assignee]) return schedule.session = new Session(ctx.app, schedule.session) - inspectSchedule(schedule) + prepareSchedule(schedule) }) }) @@ -96,7 +101,7 @@ export function apply(ctx: Context) { } const schedule = await database.createSchedule(time, interval, options.rest, session) - inspectSchedule(schedule) + prepareSchedule(schedule) return `日程已创建,编号为 ${schedule.id}。` }) }