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

This commit is contained in:
莫思潋 2022-08-22 15:33:25 +08:00 committed by GitHub
parent 169af4ccce
commit 941d6d2884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 110 deletions

View File

@ -493,8 +493,6 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 教你一篇小作文[作文] - [x] 教你一篇小作文[作文]
- [x] [回复]查重
</details> </details>
<details> <details>
<summary>漂流瓶</summary> <summary>漂流瓶</summary>

View File

@ -17,8 +17,7 @@ var engine = control.Register("diana", &ctrl.Options[*zero.Ctx]{
Help: "嘉然\n" + Help: "嘉然\n" +
"- 小作文\n" + "- 小作文\n" +
"- 发大病\n" + "- 发大病\n" +
"- 教你一篇小作文[作文]\n" + "- 教你一篇小作文[作文]",
"- [回复]查重",
PublicDataFolder: "Diana", PublicDataFolder: "Diana",
}) })

View File

@ -1,89 +0,0 @@
// Package diana 嘉然相关
package diana
import (
"bytes"
"math"
"strings"
"time"
"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/web"
"github.com/FloatTech/zbputils/ctxext"
"github.com/tidwall/gjson"
"github.com/wdvxdr1123/ZeroBot/message"
zero "github.com/wdvxdr1123/ZeroBot"
)
// 小作文查重: 回复要查的消息 查重
func init() {
engine.OnMessage(func(ctx *zero.Ctx) bool {
msg := ctx.Event.Message
if msg[0].Type != "reply" {
return false
}
for _, elem := range msg {
if elem.Type == "text" {
text := elem.Data["text"]
text = strings.ReplaceAll(text, " ", "")
text = strings.ReplaceAll(text, "\r", "")
text = strings.ReplaceAll(text, "\n", "")
if text == "查重" {
return true
}
}
}
return false
}).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
msg := ctx.GetMessage(message.NewMessageIDFromString(ctx.Event.Message[0].Data["id"])).Elements[0].Data["text"]
result, err := zhiwangapi(msg)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if result.Get("code").Int() != 0 {
ctx.SendChain(message.Text("api返回错误:", result.Get("code").Int()))
return
}
if result.Get("data.related.#").Int() == 0 {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("枝网没搜到查重率为0%,鉴定为原创")))
return
}
related := result.Get("data.related.0.reply").Map()
rate := result.Get("data.related.0.rate").Float()
relatedcontent := related["content"].String()
if len(relatedcontent) > 102 {
relatedcontent = relatedcontent[:102] + "....."
}
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(
"枝网文本复制检测报告(简洁)", "\n",
"查重时间: ", time.Now().Format("2006-01-02 15:04:05"), "\n",
"总文字复制比: ", math.Floor(rate*100), "%", "\n",
"相似小作文:", "\n", relatedcontent, "\n",
"获赞数:", related["like_num"].String(), "\n",
result.Get("data.related.0.reply_url").String(), "\n",
"作者: ", related["m_name"].String(), "\n",
"发表时间: ", time.Unix(int64(related["ctime"].Float()), 0).Format("2006-01-02 15:04:05"), "\n",
"查重结果仅作参考,请注意辨别是否为原创", "\n",
"数据来源: https://asoulcnki.asia/",
)))
})
}
func zhiwangapi(text string) (*gjson.Result, error) {
b, cl := binary.OpenWriterF(func(w *binary.Writer) {
w.WriteString("{\n\"text\":\"")
w.WriteString(text)
w.WriteString("\"\n}")
})
data, err := web.PostData("https://asoulcnki.asia/v1/api/check", "application/json", bytes.NewReader(b))
cl()
if err != nil {
return nil, err
}
result := gjson.ParseBytes(data)
return &result, nil
}

View File

@ -1,13 +1,16 @@
package gif package gif
import ( import (
"errors"
"image" "image"
"image/color" "image/color"
"sync" "sync"
"github.com/Coloured-glaze/gg" "github.com/Coloured-glaze/gg"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/img/writer" "github.com/FloatTech/floatbox/img/writer"
"github.com/FloatTech/zbputils/img" "github.com/FloatTech/zbputils/img"
"github.com/FloatTech/zbputils/img/text"
) )
// mo 摸 // mo 摸
@ -1394,3 +1397,52 @@ func whirl(cc *context, value ...string) (string, error) {
} }
return "file:///" + name, writer.SaveGIF2Path(name, img.MergeGif(7, whirl)) 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))
}

View File

@ -118,6 +118,7 @@ var (
"我老婆": nowife, "我老婆": nowife,
"远离": yuanli, "远离": yuanli,
"抬棺": taiguan, "抬棺": taiguan,
"一直": alwaysDoGif,
} }
) )
@ -140,7 +141,7 @@ func init() { // 插件主体
"- 抬棺|- 远离|- 我老婆|- 小天使XXX|- 你的XXX|- 不要看\n" + "- 抬棺|- 远离|- 我老婆|- 小天使XXX|- 你的XXX|- 不要看\n" +
"- 玩一下XXX|- 给我变|- 揍|- 吞|- 膜拜|- 诶嘿|- 2蹭|- 你犯法了\n" + "- 玩一下XXX|- 给我变|- 揍|- 吞|- 膜拜|- 诶嘿|- 2蹭|- 你犯法了\n" +
"- 砰|- 注意力涣散|- 蒙蔽|- 踩|- 好玩|- 2转|- 踢球|- 2舔|\n" + "- 砰|- 注意力涣散|- 蒙蔽|- 踩|- 好玩|- 2转|- 踢球|- 2舔|\n" +
"- 可莉吃|- 胡桃啃|- 怀", "- 可莉吃|- 胡桃啃|- 怀|- 一直(支持动图)",
PrivateDataFolder: "gif", PrivateDataFolder: "gif",
}).ApplySingle(ctxext.DefaultSingle) }).ApplySingle(ctxext.DefaultSingle)
datapath = file.BOTPATH + "/" + en.DataFolder() datapath = file.BOTPATH + "/" + en.DataFolder()

View File

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