Merge pull request #20 from fumiama/master

群管定时提醒bug修复
This commit is contained in:
Kanri 2021-05-10 03:05:27 -05:00 committed by GitHub
commit 333cfdcb04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 14 deletions

View File

@ -235,14 +235,18 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string) dateStrs := ctx.State["regex_matched"].([]string)
ts := getFilledTimeStamp(dateStrs, false) ts := getFilledTimeStamp(dateStrs, false)
go timer(ts, func() { if ts.enable {
if ts.url == "" { go timer(ts, func() {
ctx.SendChain(AtAll(), message.Text(ts.alert)) if ts.url == "" {
} else { ctx.SendChain(AtAll(), message.Text(ts.alert))
ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url)) } else {
} ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url))
}) }
ctx.Send("记住了~") })
ctx.Send("记住了~")
} else {
ctx.Send("参数非法!")
}
return return
}) })
// 取消定时 // 取消定时

View File

@ -63,32 +63,54 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp {
var ts TimeStamp var ts TimeStamp
ts.month = chineseNum2Int(monthStr) ts.month = chineseNum2Int(monthStr)
if (ts.month != -1 && ts.month <= 0) || ts.month > 12 { //月份非法
return ts
}
lenOfDW := len(dayWeekStr) lenOfDW := len(dayWeekStr)
if lenOfDW == 4 { //包括末尾的"日" if lenOfDW == 4 { //包括末尾的"日"
dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} //去除中间的十 dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} //去除中间的十
ts.day = chineseNum2Int(dayWeekStr) ts.day = chineseNum2Int(dayWeekStr)
if (ts.day != -1 && ts.day <= 0) || ts.day > 31 { //日期非法
return ts
}
} else if dayWeekStr[lenOfDW-1] == rune('日') { //xx日 } else if dayWeekStr[lenOfDW-1] == rune('日') { //xx日
dayWeekStr = dayWeekStr[:lenOfDW-1] dayWeekStr = dayWeekStr[:lenOfDW-1]
ts.day = chineseNum2Int(dayWeekStr) ts.day = chineseNum2Int(dayWeekStr)
if (ts.day != -1 && ts.day <= 0) || ts.day > 31 { //日期非法
return ts
}
} else if dayWeekStr[0] == rune('每') { //每周 } else if dayWeekStr[0] == rune('每') { //每周
ts.week = -1 ts.week = -1
} else { //周x } else { //周x
ts.week = chineseNum2Int(dayWeekStr[1:]) 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 { if len(hourStr) == 3 {
hourStr = []rune{hourStr[0], hourStr[2]} //去除中间的十 hourStr = []rune{hourStr[0], hourStr[2]} //去除中间的十
} }
ts.hour = chineseNum2Int(hourStr) ts.hour = chineseNum2Int(hourStr)
if ts.hour < -1 || ts.hour > 23 { //小时非法
return ts
}
if len(minuteStr) == 3 { if len(minuteStr) == 3 {
minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十 minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十
} }
ts.minute = chineseNum2Int(minuteStr) ts.minute = chineseNum2Int(minuteStr)
if ts.minute < -1 || ts.minute > 59 { //分钟非法
return ts
}
if !matchDateOnly { if !matchDateOnly {
urlStr := dateStrs[5] urlStr := dateStrs[5]
if urlStr != "" { //是图片url if urlStr != "" { //是图片url
ts.url = urlStr[3:] //utf-8下用为3字节 ts.url = urlStr[3:] //utf-8下用为3字节
if !strings.HasPrefix(ts.url, "http") { if !strings.HasPrefix(ts.url, "http") {
ts.url = "illeagal" ts.url = "illegal"
return ts return ts
} }
} }
@ -129,13 +151,17 @@ func chineseNum2Int(rs []rune) int8 {
//处理单个字符的映射0~10 //处理单个字符的映射0~10
func chineseChar2Int(c rune) int { func chineseChar2Int(c rune) int {
match := []rune("零一二三四五六七八九十") if c == rune('日') || c == rune('天') { //周日/周天
for i, m := range match { return 7
if c == m { } else {
return i match := []rune("零一二三四五六七八九十")
for i, m := range match {
if c == m {
return i
}
} }
return 0
} }
return 0
} }
//@全体成员 //@全体成员