mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
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>
This commit is contained in:
parent
d29e12a92c
commit
19091319cc
@ -795,6 +795,14 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] 黄油角色[@xxx]
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>抽塔罗牌</summary>
|
||||
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot"`
|
||||
|
||||
- [x] 抽塔罗牌
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>搜番</summary>
|
||||
|
||||
1
main.go
1
main.go
@ -104,6 +104,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot" // 抽塔罗牌
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou" // 舔狗日记
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
||||
|
||||
77
plugin/tarot/tarot.go
Normal file
77
plugin/tarot/tarot.go
Normal file
@ -0,0 +1,77 @@
|
||||
package tarot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/"
|
||||
|
||||
type card struct {
|
||||
Name string `json:"name"`
|
||||
Info struct {
|
||||
Description string `json:"description"`
|
||||
ReverseDescription string `json:"reverseDescription"`
|
||||
ImgURL string `json:"imgUrl"`
|
||||
} `json:"info"`
|
||||
}
|
||||
type cardset = map[string]card
|
||||
|
||||
var cardMap = make(cardset, 256)
|
||||
var reasons = []string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
|
||||
var position = []string{"正位", "逆位"}
|
||||
|
||||
func init() {
|
||||
engine := control.Register("tarot", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "塔罗牌\n" +
|
||||
"- 抽塔罗牌\n",
|
||||
// TODO 抽X张塔罗牌 解塔罗牌[牌名]
|
||||
PublicDataFolder: "Tarot",
|
||||
}).ApplySingle(ctxext.DefaultSingle)
|
||||
|
||||
engine.OnFullMatch("抽塔罗牌", ctxext.DoOnceOnSuccess(
|
||||
func(ctx *zero.Ctx) bool {
|
||||
tarotPath := engine.DataFolder() + "tarots.json"
|
||||
data, err := file.GetLazyData(tarotPath, true, true)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return false
|
||||
}
|
||||
err = json.Unmarshal(data, &cardMap)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Printf("[tarot]读取%d张塔罗牌", len(cardMap))
|
||||
return true
|
||||
},
|
||||
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
i := rand.Intn(22)
|
||||
p := rand.Intn(2)
|
||||
card := cardMap[(strconv.Itoa(i))]
|
||||
name := card.Name
|
||||
var info string
|
||||
if p == 0 {
|
||||
info = card.Info.Description
|
||||
} else {
|
||||
info = card.Info.ReverseDescription
|
||||
}
|
||||
if id := ctx.SendChain(
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
||||
message.Text("\n其意义为:", info),
|
||||
); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user