ZeroBot-Plugin/plugin/diana/zhiwang.go
莫思潋 0698d8e3b1
fix:修复了枝网查重无法使用的问题 (#175)
* 优化在两个命令中使用空格分隔的体验
- fortune的设置底图功能
- b14的加密功能

* 优化四个插件中使用空格分隔的体验
- 加密
- 哔哩哔哩推送
- 藏头诗
- 运势

* 优化并修正了上一个commit
- 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?`
- 调整藏头诗和加密的正则触发,使其不必多此一举
- 删去了未被发现的测试代码

* - 删去了遗漏的Trim

* 优化了更多插件中使用空格的体验
- 优化了music bilibili image_finder 中使用空格的体验
- 补上了plugin_bilibili中未实现的vup开头触发
- 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版

* 小调整

- 考虑到屌字既难打又有碍观瞻,改为正则匹配`[屌|弔|吊]图`
- 增加了退群提醒的定制

* - 修复退群提醒本身忘记修改了的问题

* fix:修复了枝网查重无法使用的问题

* readme适配上次的欢迎语修改

* 删去调试语句

* Update setu_geter.go

* Update zhiwang.go

Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
2022-03-31 19:36:29 +08:00

97 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package diana 嘉然相关
package diana
import (
"bytes"
"io"
"math"
"time"
"github.com/tidwall/gjson"
"github.com/wdvxdr1123/ZeroBot/message"
"net/http"
"strings"
zero "github.com/wdvxdr1123/ZeroBot"
)
// 小作文查重: 回复要查的消息 查重
func init() {
engine.OnMessage(fullmatch("查重")).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
msg := ctx.Event.Message
if msg[0].Type == "reply" {
msg := ctx.GetMessage(message.NewMessageID(msg[0].Data["id"])).Elements[0].Data["text"]
zhiwangjson := zhiwangapi(msg)
if zhiwangjson == nil || zhiwangjson.Get("code").Int() != 0 {
ctx.SendChain(message.Text("api返回错误"))
return
}
if zhiwangjson.Get("data.related.#").Int() == 0 {
ctx.SendChain(message.Text("枝网没搜到查重率为0%,鉴定为原创"))
return
}
related := zhiwangjson.Get("data.related.0.reply").Map()
rate := zhiwangjson.Get("data.related.0.rate").Float()
ctx.SendChain(message.Text(
"枝网文本复制检测报告(简洁)", "\n",
"查重时间: ", time.Now().Format("2006-01-02 15:04:05"), "\n",
"总文字复制比: ", math.Floor(rate*100), "%", "\n",
"相似小作文:", "\n",
related["content"].String()[:102]+".....", "\n",
"获赞数:", related["like_num"].String(), "\n",
zhiwangjson.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 {
url := "https://asoulcnki.asia/v1/api/check"
post := "{\n\"text\":\"" + text + "\"\n}"
var jsonStr = []byte(post)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil
}
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil
}
resp.Body.Close()
result := gjson.ParseBytes(bodyBytes)
return &result
}
func fullmatch(src ...string) zero.Rule {
return func(ctx *zero.Ctx) bool {
msg := ctx.Event.Message
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", "")
for _, s := range src {
if text == s {
return true
}
}
}
}
return false
}
}