Skip to content

Commit

Permalink
fix(schedule): check time misinterpretation, fix #89
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 28, 2020
1 parent c50bdfa commit c8e0bde
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-eval/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-schedule/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schedule>
removeSchedule (id: number): Promise<any>
getSchedule (id: number): Promise<Schedule>
getAllSchedules (assignees?: number[]): Promise<Schedule[]>
createSchedule(time: Date, interval: number, command: string, session: Session): Promise<Schedule>
removeSchedule(id: number): Promise<any>
getSchedule(id: number): Promise<Schedule>
getAllSchedules(assignees?: number[]): Promise<Schedule[]>
}

interface Tables {
Expand Down
14 changes: 10 additions & 4 deletions packages/plugin-schedule/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '不能指定过去的时间为起始时间。'
}

Expand Down

0 comments on commit c8e0bde

Please sign in to comment.