make lint happy

This commit is contained in:
fumiama
2021-12-26 22:21:00 +08:00
parent 3f69308603
commit 657532f7e5
10 changed files with 49 additions and 59 deletions

View File

@@ -2,13 +2,12 @@ package cpstory
import (
"strings"
"time"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
)
@@ -16,19 +15,15 @@ const (
prio = 20
)
var (
engine = control.Register("cpstory", &control.Options{
func init() {
engine := control.Register("cpstory", &control.Options{
DisableOnDefault: false,
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 组cp大老师 雪乃",
})
limit = rate.NewManager(time.Minute, 20)
)
func init() {
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
cs := getRandomCpStory()
gong := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
shou := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
gong := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
shou := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
text := strings.ReplaceAll(cs.Story, "<攻>", gong)
text = strings.ReplaceAll(text, "<受>", shou)
text = strings.ReplaceAll(text, cs.Gong, gong)
@@ -51,11 +46,3 @@ func init() {
}
})
}
func getCardOrNickName(ctx *zero.Ctx, userId int64) (name string) {
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, userId, false).Get("card").String()
if name == "" {
name = ctx.GetStrangerInfo(userId, false).Get("nickname").String()
}
return
}

View File

@@ -24,7 +24,7 @@ func init() {
// os.RemoveAll(dbpath)
_ = os.MkdirAll(dbpath, 0755)
_, _ = file.GetLazyData(dbfile, false, true)
err := db.Create("cp_story", &CpStory{})
err := db.Create("cp_story", &cpstory{})
if err != nil {
panic(err)
}

View File

@@ -1,13 +1,13 @@
package cpstory
type CpStory struct {
Id int64 `db:"id"`
type cpstory struct {
ID int64 `db:"id"`
Gong string `db:"gong"`
Shou string `db:"shou"`
Story string `db:"story"`
}
func getRandomCpStory() (cs CpStory) {
func getRandomCpStory() (cs cpstory) {
_ = db.Pick("cp_story", &cs)
return
}