Compare commits

..

3 Commits

Author SHA1 Message Date
源文雨
5b409ff3de 🐛 pixiv dns 2022-04-02 13:31:54 +08:00
源文雨
a9e13d3a92 🎨 优化代码结构 2022-03-31 19:50:34 +08:00
莫思潋
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
5 changed files with 72 additions and 91 deletions

View File

@@ -148,7 +148,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 退出群聊[群号]@Bot
- [x] *入群欢迎
- [x] *退群通知
- [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}]
- [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}] [{id}]
- [x] 在[MM]月[dd]日的[hh]点[mm]分时(用[url])提醒大家[xxx]
- [x] 在[MM]月[每周 | 周几]的[hh]点[mm]分时(用[url])提醒大家[xxx]
- [x] 取消在[MM]月[dd]日的[hh]点[mm]分的提醒

4
go.mod
View File

@@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.18
require (
github.com/FloatTech/AnimeAPI v1.3.2-0.20220330051608-0599bc2286fc
github.com/FloatTech/AnimeAPI v1.3.2
github.com/FloatTech/sqlite v0.2.1
github.com/FloatTech/zbputils v1.3.2-0.20220330051507-f26fec6ab9d8
github.com/FloatTech/zbputils v1.3.2
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0

8
go.sum
View File

@@ -1,9 +1,9 @@
github.com/FloatTech/AnimeAPI v1.3.2-0.20220330051608-0599bc2286fc h1:kTdQ6MvYGhVFpXlnAYdWeXAy8pdcpCUEcInT6zVOq+g=
github.com/FloatTech/AnimeAPI v1.3.2-0.20220330051608-0599bc2286fc/go.mod h1:lZmZecNyucV88/1GllxoAh4F41Gy1nLannviQ4ahVWg=
github.com/FloatTech/AnimeAPI v1.3.2 h1:5RmNOIi8QSwFjTgB9KxIjdbDdXUCe1+MLe+7R633ero=
github.com/FloatTech/AnimeAPI v1.3.2/go.mod h1:IKFBpKHgFAzo6cU4wOaRdb1ywa5mQ4NFc0mJk/wzgyY=
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
github.com/FloatTech/zbputils v1.3.2-0.20220330051507-f26fec6ab9d8 h1:qFMThl7qav2WwRGxNNcD1qviIZhfANW8Y0aXRpnhwMM=
github.com/FloatTech/zbputils v1.3.2-0.20220330051507-f26fec6ab9d8/go.mod h1:V2Y8jkxjwACWuJsDCyNVKc+qABfMAUh/mgBYdWBxOPo=
github.com/FloatTech/zbputils v1.3.2 h1:TxQ6SjT/f+iHLoz+IlQ3Hk2dUb2P9SIs4DvjGWLjZYs=
github.com/FloatTech/zbputils v1.3.2/go.mod h1:V2Y8jkxjwACWuJsDCyNVKc+qABfMAUh/mgBYdWBxOPo=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=

View File

@@ -3,106 +3,87 @@ package diana
import (
"bytes"
"encoding/json"
"math"
"strings"
"time"
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/web"
"github.com/tidwall/gjson"
"github.com/wdvxdr1123/ZeroBot/message"
"net/http"
"strings"
zero "github.com/wdvxdr1123/ZeroBot"
)
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() {
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.Code != 0 {
ctx.SendChain(message.Text("api返回错误"))
return
}
if len(zhiwangjson.Data.Related) == 0 {
ctx.SendChain(message.Text("枝网没搜到查重率为0%,我的评价是:一眼真"))
return
}
related := zhiwangjson.Data.Related[0][1].(map[string]interface{})
ctx.SendChain(message.Text(
"枝网文本复制检测报告(简洁)", "\n",
"查重时间: ", time.Now().Format("2006-01-02 15:04:05"), "\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",
"发表时间: ", time.Unix(int64(related["ctime"].(float64)), 0).Format("2006-01-02 15:04:05"), "\n",
"查重结果仅作参考,请注意辨别是否为原创", "\n",
"数据来源: https://asoulcnki.asia/",
))
}
})
}
// 发起api请求并把返回body交由json库解析
func zhiwangapi(text string) *zhiwang {
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
}
defer resp.Body.Close()
result := &zhiwang{}
if err1 := json.NewDecoder(resp.Body).Decode(result); err1 != nil {
return nil
}
return result
}
func fullmatch(src ...string) zero.Rule {
return func(ctx *zero.Ctx) bool {
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", "")
for _, s := range src {
if text == s {
return true
}
if text == "查重" {
return true
}
}
}
return false
}
}).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
msg := ctx.GetMessage(message.NewMessageID(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

@@ -76,7 +76,7 @@ func init() { // 插件主体
}
}()
engine.OnRegex(`^来份(.*)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnRegex(`^来份(.+)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
var imgtype = ctx.State["regex_matched"].([]string)[1]
// 补充池子
@@ -96,7 +96,7 @@ func init() { // 插件主体
}
})
engine.OnRegex(`^添加(.*?)(\d+)$`, zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`^添加(.+)\s?(\d+)$`, zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
@@ -110,7 +110,7 @@ func init() { // 插件主体
ctx.SendChain(message.Text("成功向分类", imgtype, "添加图片", id))
})
engine.OnRegex(`^删除(.*?)(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`^删除(.+)\s?(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]