Skip to content

Commit cda583e

Browse files
authored
feat: add plugin 抽扑克! (#903)
1 parent e62c86a commit cda583e

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,15 @@ print("run[CQ:image,file="+j["img"]+"]")
14831483

14841484
</details>
14851485

1486+
<details>
1487+
<summary>抽扑克</summary>
1488+
1489+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/yujn"`
1490+
1491+
- [x] 抽扑克牌
1492+
1493+
</details>
1494+
14861495
### *低优先级*
14871496

14881497
<details>

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

0 commit comments

Comments
 (0)