mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
群管定时提醒检查参数错误、修复按周提醒判断错误
This commit is contained in:
parent
3058badffa
commit
6f437cda85
@ -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
|
||||
})
|
||||
// 取消定时
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user