diff --git a/README.md b/README.md index 099abc9335..380e405b93 100644 --- a/README.md +++ b/README.md @@ -917,10 +917,10 @@ print("run[CQ:image,file="+j["img"]+"]") `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot"` - - [x] 抽塔罗牌 - - [x] 抽n张塔罗牌 + - [x] 抽[塔罗牌|大阿卡纳|小阿卡纳] + - [x] 抽n张[塔罗牌|大阿卡纳|小阿卡纳] - [x] 解塔罗牌[牌名] - - [x] 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]" + - [x] [塔罗|大阿卡纳|小阿卡纳|混合]牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]
diff --git a/plugin/bilibili/card2msg.go b/plugin/bilibili/card2msg.go index 607ad24e2f..9ff892f334 100644 --- a/plugin/bilibili/card2msg.go +++ b/plugin/bilibili/card2msg.go @@ -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.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.ParentAreaName)) 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++ { 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", cvURL, defaultID)) return @@ -184,7 +184,7 @@ func articleCard2msg(card Card, defaultID string) (msg []message.MessageSegment) func liveCard2msg(card roomCard) (msg []message.MessageSegment) { msg = make([]message.MessageSegment, 0, 16) 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.RoomInfo.RoomID, "\n")) 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.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", vURL, card.BvID)) return diff --git a/plugin/char_reverser/init.go b/plugin/char_reverser/init.go index 1a208c1587..3ec334283b 100644 --- a/plugin/char_reverser/init.go +++ b/plugin/char_reverser/init.go @@ -98,7 +98,7 @@ func init() { var reversedStrBuilder strings.Builder for _, char := range tempBuilder.String() { if char != ' ' { - reversedStrBuilder.WriteRune(charMap[char]) + reversedStrBuilder.WriteRune(charMap[char]) } else { reversedStrBuilder.WriteRune(' ') } diff --git a/plugin/tarot/README.md b/plugin/tarot/README.md new file mode 100644 index 0000000000..0cd23604b9 --- /dev/null +++ b/plugin/tarot/README.md @@ -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)的收集与整理! diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index fbb9e2f561..d782bd790c 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -37,21 +37,21 @@ type formation struct { } type cardSet = map[string]card -var cardMap = make(cardSet, 30) -var infoMap = make(map[string]cardInfo, 30) +var cardMap = make(cardSet, 80) +var infoMap = make(map[string]cardInfo, 80) var formationMap = make(map[string]formation, 10) // var cardName = make([]string, 30) -// var formationName = make([]string, 10) +var formationName = make([]string, 10) func init() { engine := control.Register("tarot", &ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, Help: "塔罗牌\n" + - "- 抽塔罗牌\n" + - "- 抽n张塔罗牌\n" + + "- 抽[塔罗牌|大阿卡纳|小阿卡纳]\n" + + "- 抽n张[塔罗牌|大阿卡纳|小阿卡纳]\n" + "- 解塔罗牌[牌名]\n" + - "- 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]", + "- [塔罗|大阿卡纳|小阿卡纳|混合]牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]", PublicDataFolder: "Tarot", }).ApplySingle(ctxext.DefaultSingle) @@ -67,12 +67,11 @@ func init() { return false } for _, card := range cardMap { - infoMapKey := strings.Split(card.Name, "(")[0] - infoMap[infoMapKey] = card.cardInfo - // 可以拿来显示大阿尔卡纳列表 - // cardName = append(cardName, infoMapKey) + infoMap[card.Name] = card.cardInfo + // 可以拿来显示塔罗牌列表 + // cardName = append(cardName, card.Name) } - logrus.Infof("[tarot]读取%d张大阿尔卡纳塔罗牌", len(cardMap)) + logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap)) formation, err := engine.GetLazyData("formation.json", true) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -83,15 +82,21 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return false } + for k := range formationMap { + formationName = append(formationName, k) + } logrus.Infof("[tarot]读取%d组塔罗牌阵", len(formationMap)) 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] + cardType := ctx.State["regex_matched"].([]string)[2] n := 1 reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"} position := [...]string{"正位", "逆位"} reverse := [...]string{"", "Reverse"} + start := 0 + length := 22 if match != "" { var err error n, err = strconv.Atoi(match[:len(match)-3]) @@ -112,14 +117,18 @@ func init() { return } } + if strings.Contains(cardType, "小") { + start = 22 + length = 55 + } if n == 1 { - i := rand.Intn(22) + i := rand.Intn(length) + start p := rand.Intn(2) card := cardMap[(strconv.Itoa(i))] name := card.Name if id := ctx.SendChain( 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:可能被风控了")) } return @@ -127,19 +136,19 @@ func init() { msg := make([]message.MessageSegment, n) randomIntMap := make(map[int]int, 30) for i := range msg { - j := rand.Intn(22) + j := rand.Intn(length) _, ok := randomIntMap[j] for ok { - j = rand.Intn(22) + j = rand.Intn(length) _, ok = randomIntMap[j] } randomIntMap[j] = 0 p := rand.Intn(2) - card := cardMap[(strconv.Itoa(j))] + card := cardMap[(strconv.Itoa(j + start))] name := card.Name tarotMsg := []message.MessageSegment{ 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...) } ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg) @@ -158,11 +167,20 @@ func init() { ctx.SendChain(message.Text("没有找到", match, "噢~")) } }) - engine.OnRegex(`^塔罗牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { - match := ctx.State["regex_matched"].([]string)[1] + engine.OnRegex(`^((塔罗|大阿(尔)?卡纳)|小阿(尔)?卡纳|混合)牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { + cardType := ctx.State["regex_matched"].([]string)[1] + match := ctx.State["regex_matched"].([]string)[5] info, ok := formationMap[match] position := [...]string{"正位", "逆位"} reverse := [...]string{"", "Reverse"} + start, length := 0, 22 + if strings.Contains(cardType, "小") { + start = 22 + length = 55 + } else if cardType == "混合" { + start = 0 + length = 77 + } if ok { var build strings.Builder build.WriteString(ctx.CardOrNickName(ctx.Event.UserID)) @@ -170,17 +188,17 @@ func init() { msg := make([]message.MessageSegment, info.CardsNum) randomIntMap := make(map[int]int, 30) for i := range msg { - j := rand.Intn(22) + j := rand.Intn(length) _, ok := randomIntMap[j] for ok { - j = rand.Intn(22) + j = rand.Intn(length) _, ok = randomIntMap[j] } randomIntMap[j] = 0 p := rand.Intn(2) - card := cardMap[(strconv.Itoa(j))] + card := cardMap[(strconv.Itoa(j + start))] 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(": ") build.WriteString(position[p]) @@ -199,7 +217,7 @@ func init() { ctx.SendChain(message.Image("base64://" + binary.BytesToString(formation))) ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg) } else { - ctx.SendChain(message.Text("没有找到", match, "噢~")) + ctx.SendChain(message.Text("没有找到", match, "噢~\n现有牌阵列表: ", strings.Join(formationName, " "))) } }) }