Skip to content

Commit

Permalink
make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Dec 26, 2021
1 parent 3f69308 commit 657532f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 59 deletions.
2 changes: 1 addition & 1 deletion data
Submodule data updated 1 files
+ CpStory/cp.db
25 changes: 6 additions & 19 deletions plugin_cpstory/cpstory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,28 @@ 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"
)

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)
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion plugin_cpstory/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions plugin_cpstory/model.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 2 additions & 14 deletions plugin_funny/laugh.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package funny

import (
"strconv"
"strings"
"time"

Expand All @@ -10,6 +9,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"

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

Expand All @@ -29,19 +29,7 @@ func init() {
return
}
// 获取名字
name := ctx.State["args"].(string)
if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" {
qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64)
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("card").String()
if name == "" {
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").String()
}
} else if name == "" {
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("card").String()
if name == "" {
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("nickname").String()
}
}
name := ctxext.NickName(ctx)
var j joke
err := db.Pick("jokes", &j)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions plugin_manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/FloatTech/ZeroBot-Plugin/plugin_manager/timer"
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
Expand Down Expand Up @@ -423,11 +424,7 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
if ctx.Event.NoticeType == "group_decrease" {
userid := ctx.Event.UserID
nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, userid, false).Get("card").String()
if nickname == "" {
nickname = ctx.GetGroupMemberInfo(ctx.Event.GroupID, userid, false).Get("nickname").String()
}
ctx.SendChain(message.Text(nickname, "(", userid, ")", "离开了我们..."))
ctx.SendChain(message.Text(ctxext.CardOrNickName(ctx, userid), "(", userid, ")", "离开了我们..."))
}
})
// 设置欢迎语
Expand Down
9 changes: 2 additions & 7 deletions plugin_nativewife/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"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/file"
)

Expand Down Expand Up @@ -49,13 +50,7 @@ func init() {
ctx.SendChain(message.Text("大家的wife都是", wn, "\n"), message.Image(baseuri+"/"+grpf+"/"+wn), message.Text("\n哦~"))
default:
// 获取名字
name := ctx.State["args"].(string)
if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" {
qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64)
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").Str
} else if name == "" {
name = ctx.Event.Sender.NickName
}
name := ctxext.NickName(ctx)
now := time.Now()
s := md5.Sum(helper.StringToBytes(fmt.Sprintf("%s%d%d%d", name, now.Year(), now.Month(), now.Day())))
r := rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(s[:]))))
Expand Down
10 changes: 2 additions & 8 deletions plugin_shindan/shindan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package shindan

import (
"strconv"
"time"

"github.com/FloatTech/AnimeAPI/shindanmaker"
Expand All @@ -11,6 +10,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
)

var (
Expand Down Expand Up @@ -40,13 +40,7 @@ func handle(ctx *zero.Ctx) {
return
}
// 获取名字
name := ctx.State["args"].(string)
if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" {
qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64)
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").Str
} else if name == "" {
name = ctx.Event.Sender.NickName
}
name := ctxext.NickName(ctx)
// 调用接口
text, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugin_wtf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {
}
ctx.SendChain(message.Text(s))
})
en.OnRegex(`^查询鬼东西(\d*)`).SetBlock(true).SetPriority(30).
en.OnRegex(`^查询鬼东西(\d*)`, zero.OnlyGroup).SetBlock(true).SetPriority(30).
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.SendChain(message.Text("请稍后重试0x0..."))
Expand Down
29 changes: 29 additions & 0 deletions utils/ctxext/name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Package ctxext zero ctx 扩展
package ctxext

import (
"strconv"

zero "github.com/wdvxdr1123/ZeroBot"
)

// NickName 从 args 获取名字
func NickName(ctx *zero.Ctx) (name string) {
name = ctx.State["args"].(string)
if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" {
qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64)
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").Str
} else if name == "" {
name = ctx.Event.Sender.NickName
}
return
}

// CardOrNickName 从 uid 获取名字
func CardOrNickName(ctx *zero.Ctx, uid int64) (name string) {
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, uid, false).Get("card").String()
if name == "" {
name = ctx.GetStrangerInfo(uid, false).Get("nickname").String()
}
return
}

0 comments on commit 657532f

Please sign in to comment.