mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-26 03:21:21 +08:00
make lint happy
This commit is contained in:
parent
3f69308603
commit
657532f7e5
2
data
2
data
@ -1 +1 @@
|
||||
Subproject commit 61349e6e05d2256182950469321653fb535ccbbc
|
||||
Subproject commit 913db5e597a217c205584488a66de52277a4a327
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package funny
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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"
|
||||
@ -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, ")", "离开了我们..."))
|
||||
}
|
||||
})
|
||||
// 设置欢迎语
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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[:]))))
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
package shindan
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/shindanmaker"
|
||||
@ -11,6 +10,7 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -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 {
|
||||
|
||||
@ -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..."))
|
||||
|
||||
29
utils/ctxext/name.go
Normal file
29
utils/ctxext/name.go
Normal file
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user