️ 优化saucenao搜图

This commit is contained in:
yeyang
2023-02-04 14:13:58 +08:00
parent c65277a619
commit 21e15a33a3
3 changed files with 26 additions and 5 deletions

View File

@@ -235,7 +235,7 @@ A请参考[此教程](https://docs.qq.com/doc/p/108e5d788607d988ac62e1512552c
#### 联系方式 #### 联系方式
QQ[746659424](https://qm.qq.com/cgi-bin/qm/qr?k=m6tyVb1v5y7a5_YK8CU7AoKyuR51aEaI&noverify=0&personal_qrcode_source=4) QQ746659424
群号:[254974507](https://jq.qq.com/?_wv=1027&k=o8FTig5Z) 群号:[254974507](https://jq.qq.com/?_wv=1027&k=o8FTig5Z)

View File

@@ -22,6 +22,7 @@ export class newPicSearch extends plugin {
if (!res.error && res.isTooLow) { if (!res.error && res.isTooLow) {
return res.length > 1 ? common.recallsendMsg(e, res, true) : common.getRecallsendMsg(e, res) return res.length > 1 ? common.recallsendMsg(e, res, true) : common.getRecallsendMsg(e, res)
} }
e.reply(`相似度 ${res.maxSimilarity}% 过低,自动使用 Ascii2D 进行搜索`) // e.reply(`相似度 ${res.maxSimilarity}% 过低,自动使用 Ascii2D 进行搜索`)
e.reply(`相似度 ${res.maxSimilarity}% 过低`)
} }
} }

View File

@@ -4,6 +4,10 @@ import { common } from './index.js'
import sagiri from '../tools/sagiri.js' import sagiri from '../tools/sagiri.js'
import lodash from 'lodash' import lodash from 'lodash'
export default new class { export default new class {
constructor () {
this.ascii2dDomain = 'https://ascii2d.net'
}
async SauceNAO (url) { async SauceNAO (url) {
let apiKey = Config.picSearch.SauceNAOApiKey let apiKey = Config.picSearch.SauceNAOApiKey
if (!apiKey) return { error: '未配置SauceNAOApiKey无法使用SauceNAO搜图请在 https://saucenao.com/user.php?page=search-api 进行获取' } if (!apiKey) return { error: '未配置SauceNAOApiKey无法使用SauceNAO搜图请在 https://saucenao.com/user.php?page=search-api 进行获取' }
@@ -16,10 +20,11 @@ export default new class {
numres: 3 numres: 3
} }
let res = await this.request('https://saucenao.com/search.php', params) let res = await this.request('https://saucenao.com/search.php', params)
if (!res) return { error: 'SauceNAO搜图网络请求失败' } if (!res) return { error: 'SauceNAO搜图网络请求失败移动网络无法访问saucenao可尝试配置代理' }
if (res.header.status != 0) return { error: 'SauceNAO搜图错误信息' + res.header.message.replace(/<.*?>/g, '') } if (res.header.status != 0) return { error: 'SauceNAO搜图错误信息' + res.header.message.replace(/<.*?>/g, '') }
let format = sagiri(res) let format = sagiri(res)
if (lodash.isEmpty(format)) return { error: 'SauceNAO搜图无数据使用 Ascii2D 进行搜图' } // if (lodash.isEmpty(format)) return { error: 'SauceNAO搜图无数据使用 Ascii2D 进行搜图' }
if (lodash.isEmpty(format)) return { error: 'SauceNAO搜图无数据' }
let msgMap = async item => [ let msgMap = async item => [
`SauceNAO (${item.similarity}%)\n`, `SauceNAO (${item.similarity}%)\n`,
@@ -29,7 +34,18 @@ export default new class {
`来源:${item.url[0]}` `来源:${item.url[0]}`
] ]
let maxSimilarity = format[0].similarity let maxSimilarity = format[0].similarity
let message = maxSimilarity > 80 ? [await msgMap(format[0])] : await Promise.all(format.map(msgMap)) let filterSimilarity = format.filter(item => item.similarity > 80)
let message = []
if (lodash.isEmpty(filterSimilarity)) {
let filterPixiv = filterSimilarity.filter(item => item.site == 'Pixiv')
if (lodash.isEmpty(filterPixiv)) {
message.push(await msgMap(filterPixiv[0]))
} else {
message.push(await msgMap(filterSimilarity[0]))
}
} else {
message = await Promise.all(format.map(msgMap))
}
if (res.header.long_remaining < 30) { if (res.header.long_remaining < 30) {
message.push(`${maxSimilarity > 80 ? '\n' : ''}SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`) message.push(`${maxSimilarity > 80 ? '\n' : ''}SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`)
@@ -44,6 +60,10 @@ export default new class {
} }
} }
async Ascii2D () {
// ing~
}
async request (url, params, headers) { async request (url, params, headers) {
const qs = (obj) => { const qs = (obj) => {
let res = '' let res = ''