diff --git a/manager/manager.go b/manager/manager.go index 025cef23..7e103974 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -235,14 +235,18 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { dateStrs := ctx.State["regex_matched"].([]string) ts := getFilledTimeStamp(dateStrs, false) - go timer(ts, func() { - if ts.url == "" { - ctx.SendChain(AtAll(), message.Text(ts.alert)) - } else { - ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url)) - } - }) - ctx.Send("记住了~") + if ts.enable { + go timer(ts, func() { + if ts.url == "" { + ctx.SendChain(AtAll(), message.Text(ts.alert)) + } else { + ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url)) + } + }) + ctx.Send("记住了~") + } else { + ctx.Send("参数非法!") + } return }) // 取消定时 diff --git a/manager/timer.go b/manager/timer.go index ecf0ea97..65c12be1 100644 --- a/manager/timer.go +++ b/manager/timer.go @@ -63,32 +63,54 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { var ts TimeStamp ts.month = chineseNum2Int(monthStr) + if (ts.month != -1 && ts.month <= 0) || ts.month > 12 { //月份非法 + return ts + } lenOfDW := len(dayWeekStr) if lenOfDW == 4 { //包括末尾的"日" dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} //去除中间的十 ts.day = chineseNum2Int(dayWeekStr) + if (ts.day != -1 && ts.day <= 0) || ts.day > 31 { //日期非法 + return ts + } } else if dayWeekStr[lenOfDW-1] == rune('日') { //xx日 dayWeekStr = dayWeekStr[:lenOfDW-1] ts.day = chineseNum2Int(dayWeekStr) + if (ts.day != -1 && ts.day <= 0) || ts.day > 31 { //日期非法 + return ts + } } else if dayWeekStr[0] == rune('每') { //每周 ts.week = -1 } else { //周x ts.week = chineseNum2Int(dayWeekStr[1:]) + if ts.week == 7 { //周天是0 + ts.week = 0 + } + if ts.week < 0 || ts.week > 6 { //星期非法 + ts.week = -11 + return ts + } } if len(hourStr) == 3 { hourStr = []rune{hourStr[0], hourStr[2]} //去除中间的十 } ts.hour = chineseNum2Int(hourStr) + if ts.hour < -1 || ts.hour > 23 { //小时非法 + return ts + } if len(minuteStr) == 3 { minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十 } ts.minute = chineseNum2Int(minuteStr) + if ts.minute < -1 || ts.minute > 59 { //分钟非法 + return ts + } if !matchDateOnly { urlStr := dateStrs[5] if urlStr != "" { //是图片url ts.url = urlStr[3:] //utf-8下用为3字节 if !strings.HasPrefix(ts.url, "http") { - ts.url = "illeagal" + ts.url = "illegal" return ts } } @@ -129,13 +151,17 @@ func chineseNum2Int(rs []rune) int8 { //处理单个字符的映射0~10 func chineseChar2Int(c rune) int { - match := []rune("零一二三四五六七八九十") - for i, m := range match { - if c == m { - return i + if c == rune('日') || c == rune('天') { //周日/周天 + return 7 + } else { + match := []rune("零一二三四五六七八九十") + for i, m := range match { + if c == m { + return i + } } + return 0 } - return 0 } //@全体成员