Skip to content

Commit 3faabc4

Browse files
authored
feat: add plugin 抽扑克牌 (FloatTech#906)
1 parent 7c47a55 commit 3faabc4

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,14 @@ print("run[CQ:image,file="+j["img"]+"]")
10691069

10701070
- [x] 解签
10711071

1072+
</details>
1073+
<details>
1074+
<summary>抽扑克</summary>
1075+
1076+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker"`
1077+
1078+
- [x] 抽扑克牌
1079+
10721080
</details>
10731081
<details>
10741082
<summary>一群一天一夫一妻制群老婆</summary>

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import (
115115
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
116116
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife" // 本地老婆
117117
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
118+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker" // 抽扑克
118119
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
119120
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qzone" // qq空间表白墙
120121
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/realcugan" // realcugan清晰术

plugin/poker/poker.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Package poker 抽扑克牌
2+
package poker
3+
4+
import (
5+
"encoding/json"
6+
"math/rand"
7+
8+
fcext "github.com/FloatTech/floatbox/ctxext"
9+
ctrl "github.com/FloatTech/zbpctrl"
10+
"github.com/FloatTech/zbputils/control"
11+
"github.com/FloatTech/zbputils/ctxext"
12+
zero "github.com/wdvxdr1123/ZeroBot"
13+
"github.com/wdvxdr1123/ZeroBot/message"
14+
)
15+
16+
// 图片来源 https://www.bilibili.com/opus/834601953403076633
17+
18+
var cardImgPathList []string
19+
20+
func init() {
21+
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
22+
DisableOnDefault: false,
23+
Brief: "抽扑克牌",
24+
Help: "- 抽扑克\n- poker",
25+
PublicDataFolder: "Poker",
26+
}).ApplySingle(ctxext.DefaultSingle)
27+
28+
getImg := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
29+
data, err := engine.GetLazyData("imgdata.json", true)
30+
if err != nil {
31+
ctx.SendChain(message.Text("ERROR:", err))
32+
return false
33+
}
34+
err = json.Unmarshal(data, &cardImgPathList)
35+
if err != nil {
36+
ctx.SendChain(message.Text("ERROR:", err))
37+
return false
38+
}
39+
return true
40+
})
41+
42+
engine.OnFullMatchGroup([]string{"抽扑克", "poker"}, getImg).SetBlock(true).
43+
Handle(func(ctx *zero.Ctx) {
44+
randomIndex := rand.Intn(len(cardImgPathList))
45+
randomImgPath := cardImgPathList[randomIndex]
46+
imgData, err := engine.GetLazyData(randomImgPath, true)
47+
if err != nil {
48+
ctx.Send("[poker]读取扑克图片失败")
49+
return
50+
}
51+
ctx.Send(message.ImageBytes(imgData))
52+
})
53+
}

0 commit comments

Comments
 (0)