✏️ make lint happy

This commit is contained in:
fumiama 2021-12-24 12:32:51 +08:00
parent a3b5a226ac
commit 7c5d08b723
12 changed files with 43 additions and 34 deletions

View File

@ -70,7 +70,7 @@ func init() {
keyword := ctx.State["regex_matched"].([]string)[1]
soutujson := soutuapi(keyword)
pom1 := "https://i.pixiv.re"
rannum := randintn(len(soutujson.Illusts))
rannum := rintn(len(soutujson.Illusts))
pom2 := soutujson.Illusts[rannum].ImageUrls.Medium[19:]
ctx.SendChain(message.Image(pom1 + pom2))
})
@ -102,8 +102,8 @@ func soutuapi(keyword string) *resultjson {
return result
}
// randintn 从json里的30条数据中随机获取一条返回
func randintn(len int) int {
// rintn 从json里的30条数据中随机获取一条返回
func rintn(len int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(len)
}

View File

@ -33,7 +33,7 @@ func checkNewUser(qq, gid int64, ghun, hash string) (bool, string) {
// 600s 内验证成功
ok := math.Abs(int(time.Now().Unix()-st)) < 600
if ok {
_ = db.Insert("member", &Member{QQ: qq, Ghun: ghun})
_ = db.Insert("member", &member{QQ: qq, Ghun: ghun})
return true, ""
}
return false, "时间戳超时"

View File

@ -1,11 +1,11 @@
package manager
type Welcome struct {
type welcome struct {
GrpID int64 `db:"gid"`
Msg string `db:"msg"`
}
type Member struct {
type member struct {
QQ int64 `db:"qq"`
// github username
Ghun string `db:"ghun"`

View File

@ -66,8 +66,14 @@ func init() { // 插件主体
go func() {
process.SleepAbout1sTo2s()
clock = timer.NewClock(db)
db.Create("welcome", &Welcome{})
db.Create("member", &Member{})
err := db.Create("welcome", &welcome{})
if err != nil {
panic(err)
}
err = db.Create("member", &member{})
if err != nil {
panic(err)
}
}()
// 升为管理
engine.OnRegex(`^升为管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
@ -362,7 +368,7 @@ func init() { // 插件主体
engine.OnNotice().SetBlock(false).FirstPriority().
Handle(func(ctx *zero.Ctx) {
if ctx.Event.NoticeType == "group_increase" && ctx.Event.SelfID != ctx.Event.UserID {
var w Welcome
var w welcome
err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
if err == nil {
ctx.SendChain(message.Text(w.Msg))
@ -422,7 +428,7 @@ func init() { // 插件主体
// 设置欢迎语
engine.OnRegex(`^设置欢迎语([\s\S]*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
w := &Welcome{
w := &welcome{
GrpID: ctx.Event.GroupID,
Msg: ctx.State["regex_matched"].([]string)[1],
}

View File

@ -6,35 +6,35 @@ import (
"time"
)
type holiday struct {
// Holiday 节日
type Holiday struct {
name string
date time.Time
dur time.Duration
}
// NewHoliday 节日名 天数 年 月 日
func NewHoliday(name string, dur, year int, month time.Month, day int) *holiday {
return &holiday{name: name, date: time.Date(year, month, day, 0, 0, 0, 0, time.Local), dur: time.Duration(dur) * time.Hour * 24}
func NewHoliday(name string, dur, year int, month time.Month, day int) *Holiday {
return &Holiday{name: name, date: time.Date(year, month, day, 0, 0, 0, 0, time.Local), dur: time.Duration(dur) * time.Hour * 24}
}
// 获取两个时间相差
func (h *holiday) String() string {
func (h *Holiday) String() string {
d := time.Until(h.date)
if d >= 0 {
switch {
case d >= 0:
return "距离" + h.name + "还有: " + strconv.FormatFloat(d.Hours()/24.0, 'f', 2, 64) + "天!"
} else if d+h.dur >= 0 {
case d+h.dur >= 0:
return "好好享受 " + h.name + " 假期吧!"
} else {
default:
return "今年 " + h.name + " 假期已过"
}
}
func weekend() string {
t := time.Now().Weekday()
switch t {
case time.Sunday, time.Saturday:
if t == time.Sunday || t == time.Saturday {
return "好好享受周末吧!"
default:
return fmt.Sprintf("距离周末还有:%d天", 5-t)
}
return fmt.Sprintf("距离周末还有:%d天", 5-t)
}

View File

@ -1,3 +1,4 @@
// Package moyu 摸鱼
package moyu
import (

View File

@ -1,3 +1,4 @@
// Package nativesetu 本地setu
package nativesetu
import (

View File

@ -116,8 +116,8 @@ func init() {
if reg.MatchString(recordUrl) {
// log.Println(reg.FindStringSubmatch(recordUrl)[1])
// log.Println(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
recordUrl = strings.Replace(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]), -1)
recordUrl = strings.Replace(recordUrl, "+", "%20", -1)
recordUrl = strings.ReplaceAll(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
recordUrl = strings.ReplaceAll(recordUrl, "+", "%20")
// log.Println(recordUrl)
}
ctx.SendChain(message.Reply(e.MessageID), message.Text("请欣赏《"+tc.ThirdCategoryName+"》"))
@ -149,8 +149,8 @@ func init() {
if reg.MatchString(recordUrl) {
// log.Println(reg.FindStringSubmatch(recordUrl)[1])
// log.Println(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
recordUrl = strings.Replace(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]), -1)
recordUrl = strings.Replace(recordUrl, "+", "%20", -1)
recordUrl = strings.ReplaceAll(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
recordUrl = strings.ReplaceAll(recordUrl, "+", "%20")
// log.Println(recordUrl)
}
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请欣赏"+fc.FirstCategoryName+"的《"+tc.ThirdCategoryName+"》"))

View File

@ -1,3 +1,4 @@
// Package wtf 鬼东西
package wtf
import (
@ -27,7 +28,6 @@ func init() {
s := ""
for i, w := range table {
s += fmt.Sprintf("%02d. %s\n", i, w.name)
i++
}
ctx.SendChain(message.Text(s))
})
@ -43,7 +43,7 @@ func init() {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
w := NewWtf(i)
w := newWtf(i)
if w == nil {
ctx.SendChain(message.Text("没有这项内容!"))
return
@ -58,9 +58,9 @@ func init() {
name = ctx.Event.Sender.NickName
var text string
if secondname != "" {
text, err = w.Predict(name, secondname)
text, err = w.predict(name, secondname)
} else {
text, err = w.Predict(name)
text, err = w.predict(name)
}
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))

View File

@ -18,12 +18,12 @@ for(i=0; i<a.length; i++) {
const apiprefix = "https://wtf.hiigara.net/api/run/"
type Wtf struct {
type wtf struct {
name string
path string
}
var table = [...]*Wtf{
var table = [...]*wtf{
{"你的意义是什么?", "mRIFuS"},
{"【ABO】性別和信息素", "KXyy9"},
{"测测cp", "ZoGXQd"},
@ -114,7 +114,7 @@ var table = [...]*Wtf{
{"你的蘿莉控程度全國排名", "IIWh9k"},
}
func NewWtf(index int) *Wtf {
func newWtf(index int) *wtf {
if index >= 0 && index < len(table) {
return table[index]
}
@ -128,7 +128,7 @@ type result struct {
Msg string `json:"msg"`
}
func (w *Wtf) Predict(names ...string) (string, error) {
func (w *wtf) predict(names ...string) (string, error) {
name := ""
for _, n := range names {
name += "/" + url.QueryEscape(n)

View File

@ -29,9 +29,9 @@ func DownloadTo(url, file string, chkcrt bool) error {
f, err = os.Create(file)
if err == nil {
_, err = io.Copy(f, resp.Body)
resp.Body.Close()
f.Close()
}
resp.Body.Close()
}
return err
}

View File

@ -23,6 +23,7 @@ var (
lzmu sync.Mutex
)
// GetLazyData 获取懒加载数据
func GetLazyData(path string, isReturnDataBytes, isDataMustEqual bool) ([]byte, error) {
var data []byte
var resp *http.Response