mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-01-05 11:29:00 +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 (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,19 +15,15 @@ const (
|
|||||||
prio = 20
|
prio = 20
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func init() {
|
||||||
engine = control.Register("cpstory", &control.Options{
|
engine := control.Register("cpstory", &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 组cp大老师 雪乃",
|
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 组cp大老师 雪乃",
|
||||||
})
|
})
|
||||||
limit = rate.NewManager(time.Minute, 20)
|
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
|
|
||||||
cs := getRandomCpStory()
|
cs := getRandomCpStory()
|
||||||
gong := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
|
gong := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
|
||||||
shou := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
|
shou := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
|
||||||
text := strings.ReplaceAll(cs.Story, "<攻>", gong)
|
text := strings.ReplaceAll(cs.Story, "<攻>", gong)
|
||||||
text = strings.ReplaceAll(text, "<受>", shou)
|
text = strings.ReplaceAll(text, "<受>", shou)
|
||||||
text = strings.ReplaceAll(text, cs.Gong, gong)
|
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.RemoveAll(dbpath)
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
_ = os.MkdirAll(dbpath, 0755)
|
||||||
_, _ = file.GetLazyData(dbfile, false, true)
|
_, _ = file.GetLazyData(dbfile, false, true)
|
||||||
err := db.Create("cp_story", &CpStory{})
|
err := db.Create("cp_story", &cpstory{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
package cpstory
|
package cpstory
|
||||||
|
|
||||||
type CpStory struct {
|
type cpstory struct {
|
||||||
Id int64 `db:"id"`
|
ID int64 `db:"id"`
|
||||||
Gong string `db:"gong"`
|
Gong string `db:"gong"`
|
||||||
Shou string `db:"shou"`
|
Shou string `db:"shou"`
|
||||||
Story string `db:"story"`
|
Story string `db:"story"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRandomCpStory() (cs CpStory) {
|
func getRandomCpStory() (cs cpstory) {
|
||||||
_ = db.Pick("cp_story", &cs)
|
_ = db.Pick("cp_story", &cs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package funny
|
package funny
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,19 +29,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 获取名字
|
// 获取名字
|
||||||
name := ctx.State["args"].(string)
|
name := ctxext.NickName(ctx)
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var j joke
|
var j joke
|
||||||
err := db.Pick("jokes", &j)
|
err := db.Pick("jokes", &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_manager/timer"
|
"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/math"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||||
@ -423,11 +424,7 @@ func init() { // 插件主体
|
|||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
if ctx.Event.NoticeType == "group_decrease" {
|
if ctx.Event.NoticeType == "group_decrease" {
|
||||||
userid := ctx.Event.UserID
|
userid := ctx.Event.UserID
|
||||||
nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, userid, false).Get("card").String()
|
ctx.SendChain(message.Text(ctxext.CardOrNickName(ctx, userid), "(", userid, ")", "离开了我们..."))
|
||||||
if nickname == "" {
|
|
||||||
nickname = ctx.GetGroupMemberInfo(ctx.Event.GroupID, userid, false).Get("nickname").String()
|
|
||||||
}
|
|
||||||
ctx.SendChain(message.Text(nickname, "(", userid, ")", "离开了我们..."))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 设置欢迎语
|
// 设置欢迎语
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
"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哦~"))
|
ctx.SendChain(message.Text("大家的wife都是", wn, "\n"), message.Image(baseuri+"/"+grpf+"/"+wn), message.Text("\n哦~"))
|
||||||
default:
|
default:
|
||||||
// 获取名字
|
// 获取名字
|
||||||
name := ctx.State["args"].(string)
|
name := ctxext.NickName(ctx)
|
||||||
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
|
|
||||||
}
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
s := md5.Sum(helper.StringToBytes(fmt.Sprintf("%s%d%d%d", name, now.Year(), now.Month(), now.Day())))
|
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[:]))))
|
r := rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(s[:]))))
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
package shindan
|
package shindan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/shindanmaker"
|
"github.com/FloatTech/AnimeAPI/shindanmaker"
|
||||||
@ -11,6 +10,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -40,13 +40,7 @@ func handle(ctx *zero.Ctx) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 获取名字
|
// 获取名字
|
||||||
name := ctx.State["args"].(string)
|
name := ctxext.NickName(ctx)
|
||||||
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
|
|
||||||
}
|
|
||||||
// 调用接口
|
// 调用接口
|
||||||
text, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name)
|
text, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text(s))
|
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) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||||
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
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