Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

抽扑克牌 #906

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,14 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 解签

</details>
<details>
<summary>抽扑克</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker"`

- [x] 抽扑克牌

</details>
<details>
<summary>一群一天一夫一妻制群老婆</summary>
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife" // 本地老婆
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker" // 抽扑克
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qzone" // qq空间表白墙
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/realcugan" // realcugan清晰术
Expand Down
53 changes: 53 additions & 0 deletions plugin/poker/poker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Package poker 抽扑克牌
package poker

import (
"encoding/json"
"math/rand"

fcext "github.com/FloatTech/floatbox/ctxext"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

// 图片来源 https://www.bilibili.com/opus/834601953403076633

var cardImgPathList []string

func init() {
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "抽扑克牌",
Help: "- 抽扑克\n- poker",
PublicDataFolder: "Poker",
}).ApplySingle(ctxext.DefaultSingle)

getImg := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
data, err := engine.GetLazyData("imgdata.json", true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = json.Unmarshal(data, &cardImgPathList)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})

engine.OnFullMatchGroup([]string{"抽扑克", "poker"}, getImg).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
randomIndex := rand.Intn(len(cardImgPathList))
randomImgPath := cardImgPathList[randomIndex]
imgData, err := engine.GetLazyData(randomImgPath, true)
if err != nil {
ctx.Send("[poker]读取扑克图片失败")
return
}
ctx.Send(message.ImageBytes(imgData))
})
}
Loading