Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 抽塔罗牌附加解析 #383

Merged
merged 21 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,6 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 教你一篇小作文[作文]

- [x] [回复]查重

</details>
<details>
<summary>漂流瓶</summary>
Expand Down
3 changes: 1 addition & 2 deletions plugin/diana/bing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ var engine = control.Register("diana", &ctrl.Options[*zero.Ctx]{
Help: "嘉然\n" +
"- 小作文\n" +
"- 发大病\n" +
"- 教你一篇小作文[作文]\n" +
"- [回复]查重",
"- 教你一篇小作文[作文]",
PublicDataFolder: "Diana",
})

Expand Down
89 changes: 0 additions & 89 deletions plugin/diana/zhiwang.go

This file was deleted.

52 changes: 52 additions & 0 deletions plugin/gif/gif.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package gif

import (
"errors"
"image"
"image/color"
"sync"

"github.com/Coloured-glaze/gg"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/img/writer"
"github.com/FloatTech/zbputils/img"
"github.com/FloatTech/zbputils/img/text"
)

// mo 摸
Expand Down Expand Up @@ -1394,3 +1397,52 @@ func whirl(cc *context, value ...string) (string, error) {
}
return "file:///" + name, writer.SaveGIF2Path(name, img.MergeGif(7, whirl))
}

// always 一直
func alwaysDoGif(cc *context, value ...string) (string, error) {
_ = value
var err error
var face []*image.NRGBA
name := cc.usrdir + "AlwaysDo.gif"
face, err = img.LoadAllFrames(cc.headimgsdir[0], 500, 500)
if err != nil {
// 载入失败尝试载入第一帧
face = make([]*image.NRGBA, 0)
first, err := img.LoadFirstFrame(cc.headimgsdir[0], 500, 500)
if err != nil {
return "", err
}
face = append(face, first.Im)
}
canvas := gg.NewContext(500, 600)
canvas.SetColor(color.Black)
_, err = file.GetLazyData(text.BoldFontFile, true)
if err != nil {
return "", err
}
err = canvas.LoadFontFace(text.BoldFontFile, 40)
if err != nil {
return "", err
}
length := len(face)
if length > 50 {
length = 50
}
arg := "要我一直"
l, _ := canvas.MeasureString(arg)
if l > 500 {
return "", errors.New("文字消息太长了")
}
turn := make([]*image.NRGBA, length)
for i, f := range face {
canvas := gg.NewContext(500, 600)
canvas.DrawImage(f, 0, 0)
canvas.SetColor(color.Black)
_ = canvas.LoadFontFace(text.BoldFontFile, 40)
canvas.DrawString(arg, 280-l, 560)
canvas.DrawImage(img.Size(f, 90, 90).Im, 280, 505)
canvas.DrawString("吗", 370, 560)
turn[i] = img.Size(canvas.Image(), 0, 0).Im
}
return "file:///" + name, writer.SaveGIF2Path(name, img.MergeGif(8, turn))
}
3 changes: 2 additions & 1 deletion plugin/gif/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var (
"我老婆": nowife,
"远离": yuanli,
"抬棺": taiguan,
"一直": alwaysDoGif,
}
)

Expand All @@ -140,7 +141,7 @@ func init() { // 插件主体
"- 抬棺|- 远离|- 我老婆|- 小天使XXX|- 你的XXX|- 不要看\n" +
"- 玩一下XXX|- 给我变|- 揍|- 吞|- 膜拜|- 诶嘿|- 2蹭|- 你犯法了\n" +
"- 砰|- 注意力涣散|- 蒙蔽|- 踩|- 好玩|- 2转|- 踢球|- 2舔|\n" +
"- 可莉吃|- 胡桃啃|- 怀",
"- 可莉吃|- 胡桃啃|- 怀|- 一直(支持动图)",
PrivateDataFolder: "gif",
}).ApplySingle(ctxext.DefaultSingle)
datapath = file.BOTPATH + "/" + en.DataFolder()
Expand Down
40 changes: 24 additions & 16 deletions plugin/tarot/tarot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tarot

import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"strings"
Expand Down Expand Up @@ -71,7 +70,6 @@ func init() {
infoMap[card.Name] = card.cardInfo
}
for i := 0; i < 22; i++ {
// 噢天哪,我应该把json里面序号设成int
majorArcanaName = append(majorArcanaName, cardMap[strconv.Itoa(i)].Name)
}
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
Expand All @@ -95,9 +93,9 @@ func init() {
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"}
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
position := [...]string{"『正位』", "『逆位』"}
reverse := [...]string{"", "Reverse/"}
start := 0
length := 22
if match != "" {
Expand Down Expand Up @@ -129,9 +127,14 @@ func init() {
p := rand.Intn(2)
card := cardMap[strconv.Itoa(i)]
name := card.Name
description := card.Description
if p == 1 {
description = card.ReverseDescription
}
if id := ctx.SendChain(
message.Text(reasons[rand.Intn(len(reasons))], position[p], "』的『", name, "』\n"),
message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))); id.ID() == 0 {
message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n"),
message.Image(bed+reverse[p]+card.ImgURL),
message.Text("\n其释义为: ", description)); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
return
Expand All @@ -149,9 +152,14 @@ func init() {
p := rand.Intn(2)
card := cardMap[strconv.Itoa(j+start)]
name := card.Name
description := card.Description
if p == 1 {
description = card.ReverseDescription
}
tarotMsg := []message.MessageSegment{
message.Text(reasons[rand.Intn(len(reasons))], position[p], "』的『", name, "』\n"),
message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))}
message.Text(position[p], "的『", name, "』\n"),
message.Image(bed + reverse[p] + card.ImgURL),
message.Text("\n其释义为: ", description)}
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
}
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
Expand All @@ -164,8 +172,8 @@ func init() {
ctx.SendChain(
message.Image(bed+info.ImgURL),
message.Text("\n", match, "的含义是~"),
message.Text("\n正位:", info.Description),
message.Text("\n逆位:", info.ReverseDescription))
message.Text("\n『正位』:", info.Description),
message.Text("\n『逆位』:", info.ReverseDescription))
} else {
var build strings.Builder
build.WriteString("塔罗牌列表\n大阿尔卡纳:\n")
Expand All @@ -188,8 +196,8 @@ func init() {
cardType := ctx.State["regex_matched"].([]string)[1]
match := ctx.State["regex_matched"].([]string)[5]
info, ok := formationMap[match]
position := [...]string{"正位", "逆位"}
reverse := [...]string{"", "Reverse"}
position := [...]string{"『正位』", "『逆位』"}
reverse := [...]string{"", "Reverse/"}
start, length := 0, 22
if strings.Contains(cardType, "小") {
start = 22
Expand Down Expand Up @@ -222,11 +230,11 @@ func init() {
if p == 1 {
description = card.ReverseDescription
}
tarotMsg := []message.MessageSegment{message.Image(fmt.Sprintf("%s/%s/%s", bed, reverse[p], card.ImgURL))}
tarotMsg := []message.MessageSegment{message.Image(bed + reverse[p] + card.ImgURL)}
build.WriteString(info.Represent[0][i])
build.WriteString(":")
build.WriteString(":")
build.WriteString(position[p])
build.WriteString("的『")
build.WriteString("的『")
build.WriteString(name)
build.WriteString("』\n其释义为: \n")
build.WriteString(description)
Expand Down