️ 优化SauceNAO搜图

This commit is contained in:
yeyang
2023-02-16 00:18:58 +08:00
parent d380d979e0
commit 950c3e18b8
3 changed files with 23 additions and 13 deletions

View File

@@ -202,6 +202,7 @@ Tip具体可使用 **#椰奶群管帮助** 查看
<img src="resources/img/状态.png" alt="状态" width = "300" />
</details>
<br>
常见问题请移步[wiki](https://github.com/yeyang52/yenai-plugin/wiki)
@@ -244,6 +245,11 @@ Tip具体可使用 **#椰奶群管帮助** 查看
本段遵循 [all-contributors](https://github.com/all-contributors/all-contributors) 规范,欢迎任何形式的贡献!
## 友情链接
- [Yunzai-Bot插件索引](https://gitee.com/Hikari666/Yunzai-Bot-plugins-index)
- [码云镜像库](https://gitee.com/yeyang52/yenai-plugin)
## 免责声明
1. 功能仅限内部交流与小范围使用请勿将Yunzai-Bot及Yenai-Plugin用于任何以盈利为目的的场景.

View File

@@ -37,14 +37,9 @@ export class NewPicSearch extends plugin {
if (!await this.handelImg(e, 'SauceNAO')) return
await PicSearch.SauceNAO(e.img[0])
.then(async res => {
if (res.message.length == 1)res.message = res.message[0]
await (res.maxSimilarity > 80 || res.message.length == 1
? common.recallsendMsg(e, res.message, true)
: common.getRecallsendMsg(e, res.message))
if (res.maxSimilarity < Config.picSearch.SauceNAOMinSim) {
e.reply(`SauceNAO 相似度 ${res.maxSimilarity}% 过低使用Ascii2D进行搜索`)
await this.Ascii2D(e)
}
res.length == 1
? common.recallsendMsg(e, res[0], true)
: common.getRecallsendMsg(e, res, { isxmlMsg: false })
})
.catch(async err => {
await e.reply(err.message)

View File

@@ -2,6 +2,7 @@ import _ from 'lodash'
import { Config } from '../../components/index.js'
import sagiri from '../../tools/sagiri.js'
import request from '../../lib/request/request.js'
import Ascii2D from './ascii2d.js'
export default async function doSearch (url) {
let res = await getSearchResult(url)
logger.debug('SauceNAO result:', res)
@@ -22,21 +23,29 @@ export default async function doSearch (url) {
if (!_.isEmpty(filterSimilarity)) {
let filterPixiv = filterSimilarity.filter(item => item.site == 'Pixiv')
if (!_.isEmpty(filterPixiv)) {
message = await msgMap(filterPixiv[0])
message.push(await msgMap(filterPixiv[0]))
} else {
message = await msgMap(filterSimilarity[0])
message.push(await msgMap(filterSimilarity[0]))
}
} else {
message = await Promise.all(format.map(msgMap))
}
let n = maxSimilarity > 80 ? '\n' : ''
if (res.header.long_remaining < 30) {
message.push(`${n}SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`)
const msg = `${n}SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`
n ? message[0].push(msg) : message.push(msg)
}
if (res.header.short_remaining < 3) {
message.push(`${n}SauceNAO 30s 内仅剩 ${res.header.short_remaining} 次。`)
const msg = `${n}SauceNAO 30s 内仅剩 ${res.header.short_remaining} 次。`
n ? message[0].push(msg) : message.push(msg)
}
return { message, maxSimilarity }
if (maxSimilarity < Config.picSearch.SauceNAOMinSim) {
message.push(`SauceNAO 相似度 ${maxSimilarity}% 过低使用Ascii2D进行搜索`)
await Ascii2D(url)
.then(res => message.push(...res.color, ...res.bovw))
.catch(err => message.push(err.message))
}
return message
}
async function getSearchResult (imgURL, db = 999) {