diff --git a/control/rule.go b/control/rule.go index 70aae98815..9c99164b9c 100644 --- a/control/rule.go +++ b/control/rule.go @@ -10,8 +10,6 @@ import ( "strings" "sync" - "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" - log "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension" @@ -19,6 +17,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/FloatTech/ZeroBot-Plugin/utils/sql" + "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" ) var ( diff --git a/plugin_book_review/book_review.go b/plugin_book_review/book_review.go index 75ea2a0a17..aa2e6b9c93 100644 --- a/plugin_book_review/book_review.go +++ b/plugin_book_review/book_review.go @@ -7,9 +7,8 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/utils/helper" - "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" - "github.com/FloatTech/ZeroBot-Plugin/control" + "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" ) func init() { diff --git a/plugin_manager/timer/msg.go b/plugin_manager/timer/msg.go index 0f0338619b..64de291044 100644 --- a/plugin_manager/timer/msg.go +++ b/plugin_manager/timer/msg.go @@ -5,12 +5,12 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" ) -func (ts *Timer) sendmsg(grp int64, ctx *zero.Ctx) { +func (t *Timer) sendmsg(grp int64, ctx *zero.Ctx) { ctx.Event = new(zero.Event) ctx.Event.GroupID = grp - if ts.URL == "" { - ctx.SendChain(atall, message.Text(ts.Alert)) + if t.URL == "" { + ctx.SendChain(atall, message.Text(t.Alert)) } else { - ctx.SendChain(atall, message.Text(ts.Alert), message.Image(ts.URL).Add("cache", "0")) + ctx.SendChain(atall, message.Text(t.Alert), message.Image(t.URL).Add("cache", "0")) } } diff --git a/plugin_manager/timer/parse.go b/plugin_manager/timer/parse.go index 337352fe60..744b21172a 100644 --- a/plugin_manager/timer/parse.go +++ b/plugin_manager/timer/parse.go @@ -14,29 +14,29 @@ import ( ) // GetTimerInfo 获得标准化定时字符串 -func (ts *Timer) GetTimerInfo() string { - if ts.Cron != "" { - return fmt.Sprintf("[%d]%s", ts.GrpID, ts.Cron) +func (t *Timer) GetTimerInfo() string { + if t.Cron != "" { + return fmt.Sprintf("[%d]%s", t.GrpID, t.Cron) } - return fmt.Sprintf("[%d]%d月%d日%d周%d:%d", ts.GrpID, ts.Month(), ts.Day(), ts.Week(), ts.Hour(), ts.Minute()) + return fmt.Sprintf("[%d]%d月%d日%d周%d:%d", t.GrpID, t.Month(), t.Day(), t.Week(), t.Hour(), t.Minute()) } // GetTimerID 获得标准化 ID -func (ts *Timer) GetTimerID() uint32 { - key := ts.GetTimerInfo() +func (t *Timer) GetTimerID() uint32 { + key := t.GetTimerInfo() m := md5.Sum(helper.StringToBytes(key)) return binary.LittleEndian.Uint32(m[:4]) } // GetFilledCronTimer 获得以cron填充好的ts func GetFilledCronTimer(croncmd string, alert string, img string, botqq, gid int64) *Timer { - var ts Timer - ts.Alert = alert - ts.Cron = croncmd - ts.URL = img - ts.SelfID = botqq - ts.GrpID = gid - return &ts + var t Timer + t.Alert = alert + t.Cron = croncmd + t.URL = img + t.SelfID = botqq + t.GrpID = gid + return &t } // GetFilledTimer 获得填充好的ts @@ -46,79 +46,79 @@ func GetFilledTimer(dateStrs []string, botqq, grp int64, matchDateOnly bool) *Ti hourStr := []rune(dateStrs[3]) minuteStr := []rune(dateStrs[4]) - var ts Timer + var t Timer mon := time.Month(chineseNum2Int(monthStr)) if (mon != -1 && mon <= 0) || mon > 12 { // 月份非法 - ts.Alert = "月份非法!" - return &ts + t.Alert = "月份非法!" + return &t } - ts.SetMonth(mon) + t.SetMonth(mon) lenOfDW := len(dayWeekStr) switch { case lenOfDW == 4: // 包括末尾的"日" dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} // 去除中间的十 d := chineseNum2Int(dayWeekStr) if (d != -1 && d <= 0) || d > 31 { // 日期非法 - ts.Alert = "日期非法1!" - return &ts + t.Alert = "日期非法1!" + return &t } - ts.SetDay(d) + t.SetDay(d) case dayWeekStr[lenOfDW-1] == rune('日'): // xx日 dayWeekStr = dayWeekStr[:lenOfDW-1] d := chineseNum2Int(dayWeekStr) if (d != -1 && d <= 0) || d > 31 { // 日期非法 - ts.Alert = "日期非法2!" - return &ts + t.Alert = "日期非法2!" + return &t } - ts.SetDay(d) + t.SetDay(d) case dayWeekStr[0] == rune('每'): // 每周 - ts.SetWeek(-1) + t.SetWeek(-1) default: // 周x w := chineseNum2Int(dayWeekStr[1:]) if w == 7 { // 周天是0 w = 0 } if w < 0 || w > 6 { // 星期非法 - ts.Alert = "星期非法!" - return &ts + t.Alert = "星期非法!" + return &t } - ts.SetWeek(time.Weekday(w)) + t.SetWeek(time.Weekday(w)) } if len(hourStr) == 3 { hourStr = []rune{hourStr[0], hourStr[2]} // 去除中间的十 } h := chineseNum2Int(hourStr) if h < -1 || h > 23 { // 小时非法 - ts.Alert = "小时非法!" - return &ts + t.Alert = "小时非法!" + return &t } - ts.SetHour(h) + t.SetHour(h) if len(minuteStr) == 3 { minuteStr = []rune{minuteStr[0], minuteStr[2]} // 去除中间的十 } min := chineseNum2Int(minuteStr) if min < -1 || min > 59 { // 分钟非法 - ts.Alert = "分钟非法!" - return &ts + t.Alert = "分钟非法!" + return &t } - ts.SetMinute(min) + t.SetMinute(min) if !matchDateOnly { urlStr := dateStrs[5] if urlStr != "" { // 是图片url - ts.URL = urlStr[3:] // utf-8下用为3字节 - logrus.Println("[群管]" + ts.URL) - if !strings.HasPrefix(ts.URL, "http") { - ts.URL = "illegal" + t.URL = urlStr[3:] // utf-8下用为3字节 + logrus.Println("[群管]" + t.URL) + if !strings.HasPrefix(t.URL, "http") { + t.URL = "illegal" logrus.Println("[群管]url非法!") - return &ts + return &t } } - ts.Alert = dateStrs[6] - ts.SetEn(true) + t.Alert = dateStrs[6] + t.SetEn(true) } - ts.SelfID = botqq - ts.GrpID = grp - return &ts + t.SelfID = botqq + t.GrpID = grp + return &t } // chineseNum2Int 汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每二"为-2,以此类推 diff --git a/plugin_manager/timer/sleep.go b/plugin_manager/timer/sleep.go index a75269d69b..9ab46fdc00 100644 --- a/plugin_manager/timer/sleep.go +++ b/plugin_manager/timer/sleep.go @@ -89,7 +89,7 @@ func (ts *Timer) nextWakeTime() (date time.Time) { } logrus.Debugln("[timer] stable:", stable) logrus.Debugln("[timer] m:", m, "d:", d, "h:", h, "mn:", mn, "w:", w) - date = time.Date(date.Year(), time.Month(m), int(d), int(h), int(mn), date.Second(), date.Nanosecond(), date.Location()) + date = time.Date(date.Year(), time.Month(m), d, h, mn, date.Second(), date.Nanosecond(), date.Location()) logrus.Debugln("[timer] date original:", date) if unit > 0 { date = date.Add(unit) @@ -111,7 +111,7 @@ func (ts *Timer) nextWakeTime() (date time.Time) { } } logrus.Debugln("[timer] date after fix:", date) - if stable&0x8 != 0 && date.Hour() != int(h) { + if stable&0x8 != 0 && date.Hour() != h { switch { case stable&0x4 == 0: date = date.AddDate(0, 0, 1).Add(-time.Hour) @@ -124,7 +124,7 @@ func (ts *Timer) nextWakeTime() (date time.Time) { } } logrus.Debugln("[timer] date after s8:", date) - if stable&0x4 != 0 && date.Day() != int(d) { + if stable&0x4 != 0 && date.Day() != d { switch { case stable*0x1 == 0: date = date.AddDate(0, 1, -1) diff --git a/plugin_manager/timer/wrap.go b/plugin_manager/timer/wrap.go index e79c976018..bb48f29d1b 100644 --- a/plugin_manager/timer/wrap.go +++ b/plugin_manager/timer/wrap.go @@ -3,13 +3,13 @@ package timer import "time" // En isEnabled 1bit -func (m *Timer) En() (en bool) { - return m.En1Month4Day5Week3Hour5Min6&0x800000 != 0 +func (t *Timer) En() (en bool) { + return t.En1Month4Day5Week3Hour5Min6&0x800000 != 0 } // Month 4bits -func (m *Timer) Month() (mon time.Month) { - mon = time.Month((m.En1Month4Day5Week3Hour5Min6 & 0x780000) >> 19) +func (t *Timer) Month() (mon time.Month) { + mon = time.Month((t.En1Month4Day5Week3Hour5Min6 & 0x780000) >> 19) if mon == 0b1111 { mon = -1 } @@ -17,8 +17,8 @@ func (m *Timer) Month() (mon time.Month) { } // Day 5bits -func (m *Timer) Day() (d int) { - d = int((m.En1Month4Day5Week3Hour5Min6 & 0x07c000) >> 14) +func (t *Timer) Day() (d int) { + d = int((t.En1Month4Day5Week3Hour5Min6 & 0x07c000) >> 14) if d == 0b11111 { d = -1 } @@ -26,8 +26,8 @@ func (m *Timer) Day() (d int) { } // Week 3bits -func (m *Timer) Week() (w time.Weekday) { - w = time.Weekday((m.En1Month4Day5Week3Hour5Min6 & 0x003800) >> 11) +func (t *Timer) Week() (w time.Weekday) { + w = time.Weekday((t.En1Month4Day5Week3Hour5Min6 & 0x003800) >> 11) if w == 0b111 { w = -1 } @@ -35,8 +35,8 @@ func (m *Timer) Week() (w time.Weekday) { } // Hour 5bits -func (m *Timer) Hour() (h int) { - h = int((m.En1Month4Day5Week3Hour5Min6 & 0x0007c0) >> 6) +func (t *Timer) Hour() (h int) { + h = int((t.En1Month4Day5Week3Hour5Min6 & 0x0007c0) >> 6) if h == 0b11111 { h = -1 } @@ -44,8 +44,8 @@ func (m *Timer) Hour() (h int) { } // Minute 6bits -func (m *Timer) Minute() (min int) { - min = int(m.En1Month4Day5Week3Hour5Min6 & 0x00003f) +func (t *Timer) Minute() (min int) { + min = int(t.En1Month4Day5Week3Hour5Min6 & 0x00003f) if min == 0b111111 { min = -1 } @@ -53,35 +53,35 @@ func (m *Timer) Minute() (min int) { } // SetEn ... -func (m *Timer) SetEn(en bool) { +func (t *Timer) SetEn(en bool) { if en { - m.En1Month4Day5Week3Hour5Min6 |= 0x800000 + t.En1Month4Day5Week3Hour5Min6 |= 0x800000 } else { - m.En1Month4Day5Week3Hour5Min6 &= 0x7fffff + t.En1Month4Day5Week3Hour5Min6 &= 0x7fffff } } // SetMonth ... -func (m *Timer) SetMonth(mon time.Month) { - m.En1Month4Day5Week3Hour5Min6 = ((int32(mon) << 19) & 0x780000) | (m.En1Month4Day5Week3Hour5Min6 & 0x87ffff) +func (t *Timer) SetMonth(mon time.Month) { + t.En1Month4Day5Week3Hour5Min6 = ((int32(mon) << 19) & 0x780000) | (t.En1Month4Day5Week3Hour5Min6 & 0x87ffff) } // SetDay ... -func (m *Timer) SetDay(d int) { - m.En1Month4Day5Week3Hour5Min6 = ((int32(d) << 14) & 0x07c000) | (m.En1Month4Day5Week3Hour5Min6 & 0xf83fff) +func (t *Timer) SetDay(d int) { + t.En1Month4Day5Week3Hour5Min6 = ((int32(d) << 14) & 0x07c000) | (t.En1Month4Day5Week3Hour5Min6 & 0xf83fff) } // SetWeek ... -func (m *Timer) SetWeek(w time.Weekday) { - m.En1Month4Day5Week3Hour5Min6 = ((int32(w) << 11) & 0x003800) | (m.En1Month4Day5Week3Hour5Min6 & 0xffc7ff) +func (t *Timer) SetWeek(w time.Weekday) { + t.En1Month4Day5Week3Hour5Min6 = ((int32(w) << 11) & 0x003800) | (t.En1Month4Day5Week3Hour5Min6 & 0xffc7ff) } // SetHour ... -func (m *Timer) SetHour(h int) { - m.En1Month4Day5Week3Hour5Min6 = ((int32(h) << 6) & 0x0007c0) | (m.En1Month4Day5Week3Hour5Min6 & 0xfff83f) +func (t *Timer) SetHour(h int) { + t.En1Month4Day5Week3Hour5Min6 = ((int32(h) << 6) & 0x0007c0) | (t.En1Month4Day5Week3Hour5Min6 & 0xfff83f) } // SetMinute ... -func (m *Timer) SetMinute(min int) { - m.En1Month4Day5Week3Hour5Min6 = (int32(min) & 0x00003f) | (m.En1Month4Day5Week3Hour5Min6 & 0xffffc0) +func (t *Timer) SetMinute(min int) { + t.En1Month4Day5Week3Hour5Min6 = (int32(min) & 0x00003f) | (t.En1Month4Day5Week3Hour5Min6 & 0xffffc0) } diff --git a/plugin_novel/qianbi.go b/plugin_novel/qianbi.go index c181f62920..e817184fa8 100644 --- a/plugin_novel/qianbi.go +++ b/plugin_novel/qianbi.go @@ -11,8 +11,6 @@ import ( "strings" "time" - "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" - "github.com/antchfx/htmlquery" log "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" @@ -22,6 +20,7 @@ import ( "github.com/FloatTech/ZeroBot-Plugin/control" ub "github.com/FloatTech/ZeroBot-Plugin/utils/binary" + "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" ) const ( diff --git a/plugin_omikuji/sensou.go b/plugin_omikuji/sensou.go index 05ea26e1e6..1a3152cf94 100644 --- a/plugin_omikuji/sensou.go +++ b/plugin_omikuji/sensou.go @@ -7,16 +7,13 @@ import ( "strconv" "time" - "github.com/wdvxdr1123/ZeroBot/utils/helper" - - "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" - log "github.com/sirupsen/logrus" - - "github.com/FloatTech/ZeroBot-Plugin/control" - zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" + + "github.com/FloatTech/ZeroBot-Plugin/control" + "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" ) const ( diff --git a/plugin_shindan/shindan.go b/plugin_shindan/shindan.go index 193baf02f0..4c875daff9 100644 --- a/plugin_shindan/shindan.go +++ b/plugin_shindan/shindan.go @@ -4,18 +4,16 @@ package shindan import ( "time" - log "github.com/sirupsen/logrus" - "github.com/wdvxdr1123/ZeroBot/utils/helper" - - "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" - "github.com/FloatTech/AnimeAPI/shindanmaker" + log "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/FloatTech/ZeroBot-Plugin/control" "github.com/FloatTech/ZeroBot-Plugin/utils/ctxext" + "github.com/FloatTech/ZeroBot-Plugin/utils/txt2img" ) var (