Skip to content

Commit 1909131

Browse files
feat:抽塔罗牌 (#213)
* 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim * 优化了更多插件中使用空格的体验 - 优化了music bilibili image_finder 中使用空格的体验 - 补上了plugin_bilibili中未实现的vup开头触发 - 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版 * - 调整funny - 补回readme中bilibili_push的注释说明 * - 简化funny说明 * feat:抽塔罗牌 * 🎨 改进代码样式 * 加上一个换行符 * 🎨 改进代码样式 * - At用户 * 🎨 改进代码样式 * -改进抽塔罗牌 * typo: 小写struct名 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d29e12a commit 1909131

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

README.md

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

796796
- [x] 黄油角色[@xxx]
797797

798+
</details>
799+
<details>
800+
<summary>抽塔罗牌</summary>
801+
802+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot"`
803+
804+
- [x] 抽塔罗牌
805+
798806
</details>
799807
<details>
800808
<summary>搜番</summary>

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import (
104104
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
105105
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
106106
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
107+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot" // 抽塔罗牌
107108
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou" // 舔狗日记
108109
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
109110
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译

plugin/tarot/tarot.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package tarot
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
"math/rand"
8+
"strconv"
9+
10+
"github.com/FloatTech/zbputils/control"
11+
"github.com/FloatTech/zbputils/ctxext"
12+
"github.com/FloatTech/zbputils/file"
13+
zero "github.com/wdvxdr1123/ZeroBot"
14+
"github.com/wdvxdr1123/ZeroBot/message"
15+
)
16+
17+
const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/"
18+
19+
type card struct {
20+
Name string `json:"name"`
21+
Info struct {
22+
Description string `json:"description"`
23+
ReverseDescription string `json:"reverseDescription"`
24+
ImgURL string `json:"imgUrl"`
25+
} `json:"info"`
26+
}
27+
type cardset = map[string]card
28+
29+
var cardMap = make(cardset, 256)
30+
var reasons = []string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
31+
var position = []string{"正位", "逆位"}
32+
33+
func init() {
34+
engine := control.Register("tarot", &control.Options{
35+
DisableOnDefault: false,
36+
Help: "塔罗牌\n" +
37+
"- 抽塔罗牌\n",
38+
// TODO 抽X张塔罗牌 解塔罗牌[牌名]
39+
PublicDataFolder: "Tarot",
40+
}).ApplySingle(ctxext.DefaultSingle)
41+
42+
engine.OnFullMatch("抽塔罗牌", ctxext.DoOnceOnSuccess(
43+
func(ctx *zero.Ctx) bool {
44+
tarotPath := engine.DataFolder() + "tarots.json"
45+
data, err := file.GetLazyData(tarotPath, true, true)
46+
if err != nil {
47+
ctx.SendChain(message.Text("ERROR:", err))
48+
return false
49+
}
50+
err = json.Unmarshal(data, &cardMap)
51+
if err != nil {
52+
panic(err)
53+
}
54+
log.Printf("[tarot]读取%d张塔罗牌", len(cardMap))
55+
return true
56+
},
57+
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
58+
i := rand.Intn(22)
59+
p := rand.Intn(2)
60+
card := cardMap[(strconv.Itoa(i))]
61+
name := card.Name
62+
var info string
63+
if p == 0 {
64+
info = card.Info.Description
65+
} else {
66+
info = card.Info.ReverseDescription
67+
}
68+
if id := ctx.SendChain(
69+
message.At(ctx.Event.UserID),
70+
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
71+
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
72+
message.Text("\n其意义为:", info),
73+
); id.ID() == 0 {
74+
ctx.SendChain(message.Text("ERROR:可能被风控了"))
75+
}
76+
})
77+
}

0 commit comments

Comments
 (0)