mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
feat:小阿卡纳塔罗牌 (#346)
This commit is contained in:
parent
305db3395c
commit
27c637ba66
@ -917,10 +917,10 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot"`
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot"`
|
||||||
|
|
||||||
- [x] 抽塔罗牌
|
- [x] 抽[塔罗牌|大阿卡纳|小阿卡纳]
|
||||||
- [x] 抽n张塔罗牌
|
- [x] 抽n张[塔罗牌|大阿卡纳|小阿卡纳]
|
||||||
- [x] 解塔罗牌[牌名]
|
- [x] 解塔罗牌[牌名]
|
||||||
- [x] 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]"
|
- [x] [塔罗|大阿卡纳|小阿卡纳|混合]牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -137,7 +137,7 @@ func dynamicCard2msg(str string, cType int) (msg []message.MessageSegment, err e
|
|||||||
msg = append(msg, message.Text(dynamicCard.Desc.UserProfile.Info.Uname, typeMsg[cType], "\n"))
|
msg = append(msg, message.Text(dynamicCard.Desc.UserProfile.Info.Uname, typeMsg[cType], "\n"))
|
||||||
}
|
}
|
||||||
msg = append(msg, message.Image(card.LivePlayInfo.Cover))
|
msg = append(msg, message.Image(card.LivePlayInfo.Cover))
|
||||||
msg = append(msg, message.Text(card.LivePlayInfo.Title, "\n",
|
msg = append(msg, message.Text("\n", card.LivePlayInfo.Title, "\n",
|
||||||
"房间号: ", card.LivePlayInfo.RoomID, "\n",
|
"房间号: ", card.LivePlayInfo.RoomID, "\n",
|
||||||
"分区: ", card.LivePlayInfo.ParentAreaName))
|
"分区: ", card.LivePlayInfo.ParentAreaName))
|
||||||
if card.LivePlayInfo.ParentAreaName != card.LivePlayInfo.AreaName {
|
if card.LivePlayInfo.ParentAreaName != card.LivePlayInfo.AreaName {
|
||||||
@ -174,7 +174,7 @@ func articleCard2msg(card Card, defaultID string) (msg []message.MessageSegment)
|
|||||||
for i := 0; i < len(card.OriginImageUrls); i++ {
|
for i := 0; i < len(card.OriginImageUrls); i++ {
|
||||||
msg = append(msg, message.Image(card.OriginImageUrls[i]))
|
msg = append(msg, message.Image(card.OriginImageUrls[i]))
|
||||||
}
|
}
|
||||||
msg = append(msg, message.Text(card.Title, "\n", "UP主: ", card.AuthorName, "\n",
|
msg = append(msg, message.Text("\n", card.Title, "\n", "UP主: ", card.AuthorName, "\n",
|
||||||
"阅读: ", humanNum(card.Stats.View), " 评论: ", humanNum(card.Stats.Reply), "\n",
|
"阅读: ", humanNum(card.Stats.View), " 评论: ", humanNum(card.Stats.Reply), "\n",
|
||||||
cvURL, defaultID))
|
cvURL, defaultID))
|
||||||
return
|
return
|
||||||
@ -184,7 +184,7 @@ func articleCard2msg(card Card, defaultID string) (msg []message.MessageSegment)
|
|||||||
func liveCard2msg(card roomCard) (msg []message.MessageSegment) {
|
func liveCard2msg(card roomCard) (msg []message.MessageSegment) {
|
||||||
msg = make([]message.MessageSegment, 0, 16)
|
msg = make([]message.MessageSegment, 0, 16)
|
||||||
msg = append(msg, message.Image(card.RoomInfo.Keyframe))
|
msg = append(msg, message.Image(card.RoomInfo.Keyframe))
|
||||||
msg = append(msg, message.Text(card.RoomInfo.Title, "\n",
|
msg = append(msg, message.Text("\n", card.RoomInfo.Title, "\n",
|
||||||
"主播: ", card.AnchorInfo.BaseInfo.Uname, "\n",
|
"主播: ", card.AnchorInfo.BaseInfo.Uname, "\n",
|
||||||
"房间号: ", card.RoomInfo.RoomID, "\n"))
|
"房间号: ", card.RoomInfo.RoomID, "\n"))
|
||||||
if card.RoomInfo.ShortID != 0 {
|
if card.RoomInfo.ShortID != 0 {
|
||||||
@ -226,7 +226,7 @@ func videoCard2msg(card Card) (msg []message.MessageSegment, err error) {
|
|||||||
}
|
}
|
||||||
msg = append(msg, message.Text("播放: ", humanNum(card.Stat.View), " 弹幕: ", humanNum(card.Stat.Danmaku)))
|
msg = append(msg, message.Text("播放: ", humanNum(card.Stat.View), " 弹幕: ", humanNum(card.Stat.Danmaku)))
|
||||||
msg = append(msg, message.Image(card.Pic))
|
msg = append(msg, message.Image(card.Pic))
|
||||||
msg = append(msg, message.Text("点赞: ", humanNum(card.Stat.Like), " 投币: ", humanNum(card.Stat.Coin), "\n",
|
msg = append(msg, message.Text("\n点赞: ", humanNum(card.Stat.Like), " 投币: ", humanNum(card.Stat.Coin), "\n",
|
||||||
"收藏: ", humanNum(card.Stat.Favorite), " 分享: ", humanNum(card.Stat.Share), "\n",
|
"收藏: ", humanNum(card.Stat.Favorite), " 分享: ", humanNum(card.Stat.Share), "\n",
|
||||||
vURL, card.BvID))
|
vURL, card.BvID))
|
||||||
return
|
return
|
||||||
|
|||||||
14
plugin/tarot/README.md
Normal file
14
plugin/tarot/README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# ZeroBot-Plugin-Tarot
|
||||||
|
|
||||||
|
[ZeroBot QQ机器人](https://github.com/wdvxdr1123/ZeroBot)插件,玄学占卜抽塔罗牌!
|
||||||
|
|
||||||
|
## 触发方式
|
||||||
|
|
||||||
|
- [x] 抽[塔罗牌|大阿卡纳|小阿卡纳]
|
||||||
|
- [x] 抽n张[塔罗牌|大阿卡纳|小阿卡纳]
|
||||||
|
- [x] 解塔罗牌[牌名]
|
||||||
|
- [x] [塔罗|大阿卡纳|小阿卡纳|混合]牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]
|
||||||
|
|
||||||
|
## 致谢
|
||||||
|
|
||||||
|
解牌来自[MinatoAquaCrews/nonebot_plugin_tarot](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot),感谢[KafCoppelia](https://github.com/KafCoppelia)的收集与整理!
|
||||||
@ -37,21 +37,21 @@ type formation struct {
|
|||||||
}
|
}
|
||||||
type cardSet = map[string]card
|
type cardSet = map[string]card
|
||||||
|
|
||||||
var cardMap = make(cardSet, 30)
|
var cardMap = make(cardSet, 80)
|
||||||
var infoMap = make(map[string]cardInfo, 30)
|
var infoMap = make(map[string]cardInfo, 80)
|
||||||
var formationMap = make(map[string]formation, 10)
|
var formationMap = make(map[string]formation, 10)
|
||||||
|
|
||||||
// var cardName = make([]string, 30)
|
// var cardName = make([]string, 30)
|
||||||
// var formationName = make([]string, 10)
|
var formationName = make([]string, 10)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("tarot", &ctrl.Options[*zero.Ctx]{
|
engine := control.Register("tarot", &ctrl.Options[*zero.Ctx]{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "塔罗牌\n" +
|
Help: "塔罗牌\n" +
|
||||||
"- 抽塔罗牌\n" +
|
"- 抽[塔罗牌|大阿卡纳|小阿卡纳]\n" +
|
||||||
"- 抽n张塔罗牌\n" +
|
"- 抽n张[塔罗牌|大阿卡纳|小阿卡纳]\n" +
|
||||||
"- 解塔罗牌[牌名]\n" +
|
"- 解塔罗牌[牌名]\n" +
|
||||||
"- 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]",
|
"- [塔罗|大阿卡纳|小阿卡纳|混合]牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]",
|
||||||
PublicDataFolder: "Tarot",
|
PublicDataFolder: "Tarot",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
|
||||||
@ -67,12 +67,11 @@ func init() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, card := range cardMap {
|
for _, card := range cardMap {
|
||||||
infoMapKey := strings.Split(card.Name, "(")[0]
|
infoMap[card.Name] = card.cardInfo
|
||||||
infoMap[infoMapKey] = card.cardInfo
|
// 可以拿来显示塔罗牌列表
|
||||||
// 可以拿来显示大阿尔卡纳列表
|
// cardName = append(cardName, card.Name)
|
||||||
// cardName = append(cardName, infoMapKey)
|
|
||||||
}
|
}
|
||||||
logrus.Infof("[tarot]读取%d张大阿尔卡纳塔罗牌", len(cardMap))
|
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
|
||||||
formation, err := engine.GetLazyData("formation.json", true)
|
formation, err := engine.GetLazyData("formation.json", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
@ -83,15 +82,21 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
for k := range formationMap {
|
||||||
|
formationName = append(formationName, k)
|
||||||
|
}
|
||||||
logrus.Infof("[tarot]读取%d组塔罗牌阵", len(formationMap))
|
logrus.Infof("[tarot]读取%d组塔罗牌阵", len(formationMap))
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
engine.OnRegex(`^抽(\d{1,2}张)?塔罗牌$`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex(`^抽(\d{1,2}张)?((塔罗牌|大阿(尔)?卡纳)|小阿(尔)?卡纳)$`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||||
match := ctx.State["regex_matched"].([]string)[1]
|
match := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
cardType := ctx.State["regex_matched"].([]string)[2]
|
||||||
n := 1
|
n := 1
|
||||||
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
|
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
|
||||||
position := [...]string{"正位", "逆位"}
|
position := [...]string{"正位", "逆位"}
|
||||||
reverse := [...]string{"", "Reverse"}
|
reverse := [...]string{"", "Reverse"}
|
||||||
|
start := 0
|
||||||
|
length := 22
|
||||||
if match != "" {
|
if match != "" {
|
||||||
var err error
|
var err error
|
||||||
n, err = strconv.Atoi(match[:len(match)-3])
|
n, err = strconv.Atoi(match[:len(match)-3])
|
||||||
@ -112,14 +117,18 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if strings.Contains(cardType, "小") {
|
||||||
|
start = 22
|
||||||
|
length = 55
|
||||||
|
}
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
i := rand.Intn(22)
|
i := rand.Intn(length) + start
|
||||||
p := rand.Intn(2)
|
p := rand.Intn(2)
|
||||||
card := cardMap[(strconv.Itoa(i))]
|
card := cardMap[(strconv.Itoa(i))]
|
||||||
name := card.Name
|
name := card.Name
|
||||||
if id := ctx.SendChain(
|
if id := ctx.SendChain(
|
||||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], i))); id.ID() == 0 {
|
message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -127,19 +136,19 @@ func init() {
|
|||||||
msg := make([]message.MessageSegment, n)
|
msg := make([]message.MessageSegment, n)
|
||||||
randomIntMap := make(map[int]int, 30)
|
randomIntMap := make(map[int]int, 30)
|
||||||
for i := range msg {
|
for i := range msg {
|
||||||
j := rand.Intn(22)
|
j := rand.Intn(length)
|
||||||
_, ok := randomIntMap[j]
|
_, ok := randomIntMap[j]
|
||||||
for ok {
|
for ok {
|
||||||
j = rand.Intn(22)
|
j = rand.Intn(length)
|
||||||
_, ok = randomIntMap[j]
|
_, ok = randomIntMap[j]
|
||||||
}
|
}
|
||||||
randomIntMap[j] = 0
|
randomIntMap[j] = 0
|
||||||
p := rand.Intn(2)
|
p := rand.Intn(2)
|
||||||
card := cardMap[(strconv.Itoa(j))]
|
card := cardMap[(strconv.Itoa(j + start))]
|
||||||
name := card.Name
|
name := card.Name
|
||||||
tarotMsg := []message.MessageSegment{
|
tarotMsg := []message.MessageSegment{
|
||||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], j))}
|
message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))}
|
||||||
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
|
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
|
||||||
}
|
}
|
||||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||||
@ -158,11 +167,20 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("没有找到", match, "噢~"))
|
ctx.SendChain(message.Text("没有找到", match, "噢~"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
engine.OnRegex(`^塔罗牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex(`^((塔罗|大阿(尔)?卡纳)|小阿(尔)?卡纳|混合)牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||||
match := ctx.State["regex_matched"].([]string)[1]
|
cardType := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
match := ctx.State["regex_matched"].([]string)[5]
|
||||||
info, ok := formationMap[match]
|
info, ok := formationMap[match]
|
||||||
position := [...]string{"正位", "逆位"}
|
position := [...]string{"正位", "逆位"}
|
||||||
reverse := [...]string{"", "Reverse"}
|
reverse := [...]string{"", "Reverse"}
|
||||||
|
start, length := 0, 22
|
||||||
|
if strings.Contains(cardType, "小") {
|
||||||
|
start = 22
|
||||||
|
length = 55
|
||||||
|
} else if cardType == "混合" {
|
||||||
|
start = 0
|
||||||
|
length = 77
|
||||||
|
}
|
||||||
if ok {
|
if ok {
|
||||||
var build strings.Builder
|
var build strings.Builder
|
||||||
build.WriteString(ctx.CardOrNickName(ctx.Event.UserID))
|
build.WriteString(ctx.CardOrNickName(ctx.Event.UserID))
|
||||||
@ -170,17 +188,17 @@ func init() {
|
|||||||
msg := make([]message.MessageSegment, info.CardsNum)
|
msg := make([]message.MessageSegment, info.CardsNum)
|
||||||
randomIntMap := make(map[int]int, 30)
|
randomIntMap := make(map[int]int, 30)
|
||||||
for i := range msg {
|
for i := range msg {
|
||||||
j := rand.Intn(22)
|
j := rand.Intn(length)
|
||||||
_, ok := randomIntMap[j]
|
_, ok := randomIntMap[j]
|
||||||
for ok {
|
for ok {
|
||||||
j = rand.Intn(22)
|
j = rand.Intn(length)
|
||||||
_, ok = randomIntMap[j]
|
_, ok = randomIntMap[j]
|
||||||
}
|
}
|
||||||
randomIntMap[j] = 0
|
randomIntMap[j] = 0
|
||||||
p := rand.Intn(2)
|
p := rand.Intn(2)
|
||||||
card := cardMap[(strconv.Itoa(j))]
|
card := cardMap[(strconv.Itoa(j + start))]
|
||||||
name := card.Name
|
name := card.Name
|
||||||
tarotMsg := []message.MessageSegment{message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], j))}
|
tarotMsg := []message.MessageSegment{message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))}
|
||||||
build.WriteString(info.Represent[0][i])
|
build.WriteString(info.Represent[0][i])
|
||||||
build.WriteString(": ")
|
build.WriteString(": ")
|
||||||
build.WriteString(position[p])
|
build.WriteString(position[p])
|
||||||
@ -199,7 +217,7 @@ func init() {
|
|||||||
ctx.SendChain(message.Image("base64://" + binary.BytesToString(formation)))
|
ctx.SendChain(message.Image("base64://" + binary.BytesToString(formation)))
|
||||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||||
} else {
|
} else {
|
||||||
ctx.SendChain(message.Text("没有找到", match, "噢~"))
|
ctx.SendChain(message.Text("没有找到", match, "噢~\n现有牌阵列表: ", strings.Join(formationName, " ")))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user