Skip to content

Commit

Permalink
💩👌 make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jan 2, 2022
1 parent 59a731d commit 18def7c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 93 deletions.
3 changes: 1 addition & 2 deletions control/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ 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"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"

"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
"github.com/FloatTech/ZeroBot-Plugin/utils/txt2img"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions plugin_book_review/book_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions plugin_manager/timer/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
86 changes: 43 additions & 43 deletions plugin_manager/timer/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,以此类推
Expand Down
6 changes: 3 additions & 3 deletions plugin_manager/timer/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
50 changes: 25 additions & 25 deletions plugin_manager/timer/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,85 @@ 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
}
return
}

// 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
}
return
}

// 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
}
return
}

// 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
}
return
}

// 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
}
return
}

// 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)
}
3 changes: 1 addition & 2 deletions plugin_novel/qianbi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down
11 changes: 4 additions & 7 deletions plugin_omikuji/sensou.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 3 additions & 5 deletions plugin_shindan/shindan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 18def7c

Please sign in to comment.