mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 22:40:23 +08:00
新增小作文查重功能
This commit is contained in:
parent
5a6c1e36e5
commit
bea8607a9f
110
plugin_diana/zhiwang.go
Normal file
110
plugin_diana/zhiwang.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package plugin_diana
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// json解析的结构体声明
|
||||||
|
type zhiwang struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
EndTime int `json:"end_time"`
|
||||||
|
Rate float64 `json:"rate"`
|
||||||
|
Related [][]interface{} `json:"related"`
|
||||||
|
StartTime int `json:"start_time"`
|
||||||
|
} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小作文查重: 回复要查的消息 查重
|
||||||
|
func init() {
|
||||||
|
zero.OnMessage(FullMatchText("查重")).
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
msg := ctx.Event.Message
|
||||||
|
if msg[0].Type == "reply" {
|
||||||
|
id, _ := strconv.Atoi(msg[0].Data["id"])
|
||||||
|
msg := ctx.GetMessage(int64(id)).Elements[0].Data["text"]
|
||||||
|
zhiwangjson := zhiwangapi(msg)
|
||||||
|
// 判断api是否能调通
|
||||||
|
if zhiwangjson.Code != 0 {
|
||||||
|
ctx.Send("api返回错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 判断json数据里Related标签是否有数据
|
||||||
|
if len(zhiwangjson.Data.Related) == 0 {
|
||||||
|
ctx.Send("枝网没搜到,查重率为0%,我的评价是:一眼真")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 把interface转为map方便提取其中数据
|
||||||
|
related := zhiwangjson.Data.Related[0][1].(map[string]interface{})
|
||||||
|
ctx.SendChain(message.Text(
|
||||||
|
"枝网文本复制检测报告(简洁)", "\n",
|
||||||
|
"查重时间: ", timecurrent(), "\n",
|
||||||
|
"总文字复制比: ", math.Floor(zhiwangjson.Data.Rate * 100), "%", "\n",
|
||||||
|
"相似小作文:", "\n",
|
||||||
|
related["content"].(string)[:102] + ".....", "\n",
|
||||||
|
"获赞数", related["like_num"], "\n",
|
||||||
|
zhiwangjson.Data.Related[0][2].(string), "\n",
|
||||||
|
"作者: ", related["m_name"], "\n",
|
||||||
|
"发表时间: ", timestamp(related["ctime"].(float64)), "\n",
|
||||||
|
"查重结果仅作参考,请注意辨别是否为原创", "\n",
|
||||||
|
"数据来源: https://asoulcnki.asia/",
|
||||||
|
))
|
||||||
|
}else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发起api请求并把返回body交由json库解析
|
||||||
|
func zhiwangapi(Text string) *zhiwang {
|
||||||
|
|
||||||
|
url := "https://asoulcnki.asia/v1/api/checksdsadas"
|
||||||
|
post := "{\"text\":\"" + Text + "\"}"
|
||||||
|
var jsonStr = []byte(post)
|
||||||
|
|
||||||
|
req, err := 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{
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
result := &zhiwang{}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 照帮理酱的关键字匹配函数
|
||||||
|
func FullMatchText(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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user