From c8e0bde2844a51cc8615624575b297fbdd27fa96 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Fri, 28 Aug 2020 23:26:58 +0800 Subject: [PATCH] fix(schedule): check time misinterpretation, fix #89 --- packages/plugin-eval/src/index.ts | 2 +- packages/plugin-schedule/src/database.ts | 8 ++++---- packages/plugin-schedule/src/index.ts | 14 ++++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/plugin-eval/src/index.ts b/packages/plugin-eval/src/index.ts index 3cb870f495..c92ea8c839 100644 --- a/packages/plugin-eval/src/index.ts +++ b/packages/plugin-eval/src/index.ts @@ -2,7 +2,7 @@ import { Context, Session } from 'koishi-core' import { CQCode, Logger, defineProperty, Random } from 'koishi-utils' import { EvalWorker, UserTrap, EvalConfig, Config } from './main' -export { UserTrap, MainAPI } from './main' +export { UserTrap, MainAPI, Config, MainConfig } from './main' declare module 'koishi-core/dist/app' { interface App { diff --git a/packages/plugin-schedule/src/database.ts b/packages/plugin-schedule/src/database.ts index 22cd05690f..672078aae3 100644 --- a/packages/plugin-schedule/src/database.ts +++ b/packages/plugin-schedule/src/database.ts @@ -4,10 +4,10 @@ import MongoDatabase from 'koishi-plugin-mongo/dist/database' declare module 'koishi-core/dist/database' { interface Database { - createSchedule (time: Date, interval: number, command: string, session: Session): Promise - removeSchedule (id: number): Promise - getSchedule (id: number): Promise - getAllSchedules (assignees?: number[]): Promise + createSchedule(time: Date, interval: number, command: string, session: Session): Promise + removeSchedule(id: number): Promise + getSchedule(id: number): Promise + getAllSchedules(assignees?: number[]): Promise } interface Tables { diff --git a/packages/plugin-schedule/src/index.ts b/packages/plugin-schedule/src/index.ts index 3aed9c9ddb..4e0e42ce78 100644 --- a/packages/plugin-schedule/src/index.ts +++ b/packages/plugin-schedule/src/index.ts @@ -77,10 +77,16 @@ export function apply(ctx: Context) { if (!options.rest) return '请输入要执行的指令。' - const time = Time.parseDate(dateSegments.join('-')) - if (Number.isNaN(+time)) { - return '请输入合法的日期。' - } else if (!options.interval && +time <= Date.now()) { + const dateString = dateSegments.join('-') + const time = Time.parseDate(dateString) + const timestamp = +time + if (Number.isNaN(timestamp) || timestamp > 2147483647000) { + if (/^\d+$/.test(dateString)) { + return `请输入合法的日期。你要输入的是不是 ${dateString}s?` + } else { + return '请输入合法的日期。' + } + } else if (!options.interval && timestamp <= Date.now()) { return '不能指定过去的时间为起始时间。' }