Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ require (
github.com/jozsefsallai/gophersauce v1.0.1
github.com/lithammer/fuzzysearch v1.1.5
github.com/mroth/weightedrand v1.0.0
github.com/notnil/chess v1.9.0
github.com/pkg/errors v0.9.1
github.com/quic-go/quic-go v0.38.1
github.com/shirou/gopsutil/v3 v3.23.1
github.com/sirupsen/logrus v1.9.0
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
github.com/tidwall/gjson v1.14.4
github.com/wcharczuk/go-chart/v2 v2.1.0
github.com/wdvxdr1123/ZeroBot v1.7.4
Expand All @@ -46,6 +49,7 @@ require (
)

require (
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca // indirect
github.com/antchfx/xpath v1.2.1 // indirect
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
github.com/faiface/beep v1.1.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOU
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 h1:bBmmB7he0iVN4m5mcehfheeRUEer/Avo4ujnxI3uCqs=
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5/go.mod h1:0UcFaCkhp6vZw6l5Dpq0Dp673CoF9GdvA8lTfst0GiU=
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca h1:kWzLcty5V2rzOqJM7Tp/MfSX0RMSI1x4IOLApEefYxA=
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/antchfx/htmlquery v1.2.5 h1:1lXnx46/1wtv1E/kzmH8vrfMuUKYgkdDBA9pIdMJnk4=
github.com/antchfx/htmlquery v1.2.5/go.mod h1:2MCVBzYVafPBmKbrmwB9F5xdd+IEgRY61ci2oOsOQVw=
Expand Down Expand Up @@ -152,6 +154,8 @@ github.com/mroth/weightedrand v1.0.0 h1:V8JeHChvl2MP1sAoXq4brElOcza+jxLkRuwvtQu8
github.com/mroth/weightedrand v1.0.0/go.mod h1:3p2SIcC8al1YMzGhAIoXD+r9olo/g/cdJgAD905gyNE=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/notnil/chess v1.9.0 h1:YMxR5kUVjtwcuFptGU0/3q7eG3MSHQNbg0VUekvRKV0=
github.com/notnil/chess v1.9.0/go.mod h1:cRuJUIBFq9Xki05TWHJxHYkC+fFpq45IWwk94DdlCrA=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
Expand Down Expand Up @@ -179,6 +183,10 @@ github.com/shirou/gopsutil/v3 v3.23.1 h1:a9KKO+kGLKEvcPIs4W62v0nu3sciVDOOOPUD0Hz
github.com/shirou/gopsutil/v3 v3.23.1/go.mod h1:NN6mnm5/0k8jw4cBfCnJtr5L7ErOTg18tMNpgFkn0hA=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE=
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ=
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // b站相关
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chess" // 国际象棋
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/choose" // 选择困难症帮手
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chouxianghua" // 说抽象话
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chrev" // 英文字符翻转
Expand Down
Binary file added plugin/chess/assets/cheese.jpeg
Comment thread
aimerneige marked this conversation as resolved.
Outdated
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions plugin/chess/assets/help.txt
Comment thread
aimerneige marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- 参与/创建一盘游戏:「下棋」(chess)
- 参与/创建一盘盲棋:「盲棋」(blind)
- 投降认输:「认输」 (resign)
- 请求、接受和棋:「和棋」 (draw)
- 走棋:!Nxf3 中英文感叹号均可,格式请参考“代数记谱法”(Algebraic notation)
- 中断对局:「中断」 (abort)(仅群主/管理员有效)
- 查看等级分排行榜:「排行榜」(ranking)
- 查看自己的等级分:「等级分」(rate)
- 清空等级分:「清空等级分 QQ号」(.clean.rate) (仅超管有效)
144 changes: 144 additions & 0 deletions plugin/chess/chess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Package chess 国际象棋
package chess

import (
_ "embed"
"encoding/base64"
"fmt"
"os"
"path"
"strconv"
"strings"

"github.com/FloatTech/floatbox/file"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/ZeroBot-Plugin/plugin/chess/service"
)

//go:embed assets/cheese.jpeg
var cheeseData []byte

//go:embed assets/help.txt
var helpString string

var (
tempFileDir string
engine = control.Register("chess", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "国际象棋",
Help: helpString,
})
Comment thread
aimerneige marked this conversation as resolved.
Outdated
)

func init() {
// 初始化临时文件夹
tempFileDir = path.Join(engine.DataFolder(), "temp")
if !file.IsExist(tempFileDir) {
err := os.MkdirAll(tempFileDir, 0750)
Comment thread
aimerneige marked this conversation as resolved.
Outdated
if err != nil {
panic(err)
}
}
// 初始化数据库
dbFilePath := engine.DataFolder() + "chess.db"
service.InitDatabase(dbFilePath)
// 注册指令
engine.OnFullMatchGroup([]string{"下棋", "chess"}, zero.OnlyGroup).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
userName := ctx.Event.Sender.NickName
Comment thread
aimerneige marked this conversation as resolved.
groupCode := ctx.Event.GroupID
if replyMessage := Game(groupCode, userUin, userName); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"认输", "resign"}, zero.OnlyGroup).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
groupCode := ctx.Event.GroupID
if replyMessage := Resign(groupCode, userUin); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"和棋", "draw"}, zero.OnlyGroup).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
groupCode := ctx.Event.GroupID
if replyMessage := Draw(groupCode, userUin); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"中断", "abort"}, zero.OnlyGroup, zero.AdminPermission).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
groupCode := ctx.Event.GroupID
if replyMessage := Abort(groupCode); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"盲棋", "blind"}, zero.OnlyGroup).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
userName := ctx.Event.Sender.NickName
groupCode := ctx.Event.GroupID
if replyMessage := Blindfold(groupCode, userUin, userName); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnRegex("[!|!]([0-9]|[A-Z]|[a-z]|=|-)+", zero.OnlyGroup).
Comment thread
aimerneige marked this conversation as resolved.
Outdated
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
groupCode := ctx.Event.GroupID
userMsgStr := ctx.Event.Message.ExtractPlainText()
Comment thread
aimerneige marked this conversation as resolved.
Outdated
userMsgStr = strings.Replace(userMsgStr, "!", "!", 1)
Comment thread
aimerneige marked this conversation as resolved.
Outdated
moveStr := userMsgStr[1:]
if replyMessage := Play(userUin, groupCode, moveStr); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"排行榜", "ranking"}).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
if replyMessage := Ranking(); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnFullMatchGroup([]string{"等级分", "rate"}).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
userUin := ctx.Event.UserID
userName := ctx.Event.Sender.NickName
if replyMessage := Rate(userUin, userName); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
})
engine.OnPrefixGroup([]string{"清空等级分", ".clean.rate"}, zero.SuperUserPermission).
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
args := ctx.State["args"].(string)
if playerUin, err := strconv.ParseInt(strings.TrimSpace(args), 10, 64); err == nil && playerUin > 0 {
Comment thread
aimerneige marked this conversation as resolved.
Outdated
if replyMessage := CleanUserRate(playerUin); len(replyMessage) >= 1 {
ctx.Send(replyMessage)
}
} else {
ctx.Send(fmt.Sprintf("解析失败「%s」不是正确的 QQ 号。", args))
}
})
engine.OnFullMatch("cheese").
SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(
message.Text("Chess Cheese Cheese Chess"),
message.Image("base64://"+base64.StdEncoding.EncodeToString(cheeseData)),
)
})
}
Loading