⚡️ 优化SauceNAO搜图
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { common, PicSearch } from '../model/index.js'
|
||||
import { PicSearch, common } from '../model/index.js'
|
||||
|
||||
export class newPicSearch extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
@@ -16,8 +17,11 @@ export class newPicSearch extends plugin {
|
||||
|
||||
async search (e) {
|
||||
if (!e.img) return e.reply('请将图片与消息一起发送')
|
||||
let msg = await PicSearch.SauceNAO(e.img[0])
|
||||
if (msg.error) return e.reply(msg.error)
|
||||
common.getforwardMsg(e, msg)
|
||||
let res = await PicSearch.SauceNAO(e.img[0])
|
||||
if (res.error) e.reply(res.error)
|
||||
if (!res.error && res.isTooLow) {
|
||||
return res.length > 1 ? common.recallsendMsg(e, res, true) : common.getRecallsendMsg(e, res)
|
||||
}
|
||||
e.reply(`相似度 ${res.maxSimilarity}% 过低,自动使用 Ascii2D 进行搜索`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
#SauceNAO搜图apikey 请在 https://saucenao.com/user.php?page=search-api 进行获取
|
||||
SauceNAOApiKey:
|
||||
#SauceNAO搜图相似度低于这个百分比将被认定为相似度过低
|
||||
SauceNAO_Min_sim: 60
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
#SauceNAO搜图apikey 请在 https://saucenao.com/user.php?page=search-api 进行获取
|
||||
SauceNAOApiKey:
|
||||
#SauceNAO搜图相似度低于这个百分比将被认定为相似度过低
|
||||
SauceNAO_Min_sim: 60
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable no-void */
|
||||
import fetch from 'node-fetch'
|
||||
import { Config } from '../components/index.js'
|
||||
import { common } from './index.js'
|
||||
import sites from '../tools/sites.js'
|
||||
|
||||
import sagiri from '../tools/sagiri.js'
|
||||
import lodash from 'lodash'
|
||||
export default new class {
|
||||
async SauceNAO (url) {
|
||||
let apiKey = Config.picSearch.SauceNAOApiKey
|
||||
@@ -17,20 +16,32 @@ export default new class {
|
||||
numres: 3
|
||||
}
|
||||
let res = await this.request('https://saucenao.com/search.php', params)
|
||||
if (!res) return { error: 'SauceNAO搜图请求失败' }
|
||||
if (res.header.status != 0) return { error: res.header.message }
|
||||
let msg = await Promise.all(sites(res).map(async item => [
|
||||
`SauceNAO (${item.similarity})\n`,
|
||||
if (!res) return { error: 'SauceNAO搜图网络请求失败' }
|
||||
if (res.header.status != 0) return { error: 'SauceNAO搜图,错误信息:' + res.header.message.replace(/<.*?>/g, '') }
|
||||
let format = sagiri(res)
|
||||
if (lodash.isEmpty(format)) return { error: 'SauceNAO搜图无数据,使用 Ascii2D 进行搜图' }
|
||||
|
||||
let msgMap = async item => [
|
||||
`SauceNAO (${item.similarity}%)\n`,
|
||||
await common.proxyRequestImg(item.thumbnail),
|
||||
`\nsite:${item.site}\n`,
|
||||
`作者:${item.authorName}\n`,
|
||||
`作者主页:${item.authorUrl}\n`,
|
||||
`作品链接:${item.url[0]}`
|
||||
]))
|
||||
if (res.header.long_remaining < 10) {
|
||||
msg.push(`SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`)
|
||||
`\nSite:${item.site}\n`,
|
||||
`作者:${item.authorName}(${item.authorUrl})\n`,
|
||||
`来源:${item.url[0]}`
|
||||
]
|
||||
let maxSimilarity = format[0].similarity
|
||||
let message = maxSimilarity > 80 ? [await msgMap(format[0])] : await Promise.all(format.map(msgMap))
|
||||
|
||||
if (res.header.long_remaining < 30) {
|
||||
message.push(`${maxSimilarity > 80 ? '\n' : ''}SauceNAO 24h 内仅剩 ${res.header.long_remaining} 次使用次数`)
|
||||
}
|
||||
if (res.header.short_remaining < 3) {
|
||||
message.push(`${maxSimilarity > 80 ? '\n' : ''}SauceNAO 30s 内仅剩 ${res.header.short_remaining} 次。`)
|
||||
}
|
||||
return {
|
||||
maxSimilarity,
|
||||
isTooLow: maxSimilarity > Config.picSearch.SauceNAO_Min_sim,
|
||||
message
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
async request (url, params, headers) {
|
||||
|
||||
@@ -109,14 +109,15 @@ export default new class newCommon {
|
||||
/**
|
||||
* @description: 发送普通消息并根据指定时间撤回群消息
|
||||
* @param {*} e oicq
|
||||
* @param {*} msg 消息
|
||||
* @param {Array|String} msg 消息
|
||||
* @param {Boolean} quote 是否引用回复
|
||||
* @param {Number} time 撤回时间
|
||||
* @param {Boolean} fkmsg 风控消息
|
||||
* @return {*}
|
||||
*/
|
||||
async recallsendMsg (e, msg, time = setu.getRecallTime(e.group_id), fkmsg = '') {
|
||||
async recallsendMsg (e, msg, quote, time = setu.getRecallTime(e.group_id), fkmsg = '') {
|
||||
// 发送消息
|
||||
let res = await e.reply(msg, false, { recallMsg: time })
|
||||
let res = await e.reply(msg, quote, { recallMsg: time })
|
||||
if (!res) await e.reply(fkmsg || '消息发送失败,可能被风控')
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
/* eslint-disable no-void */
|
||||
'use strict'
|
||||
// Object.defineProperty(exports, '__esModule', { value: true })
|
||||
// const errors_1 = require('./errors')
|
||||
// #region Site data objects
|
||||
const DoujinMangaLexicon = {
|
||||
name: 'The Doujinshi & Manga Lexicon',
|
||||
index: 3,
|
||||
@@ -357,7 +353,7 @@ const resolveResult = item => {
|
||||
}, ((_a = authorData === null || authorData === void 0 ? void 0 : authorData(item.data)) !== null && _a !== void 0 ? _a : { authorName: null, authorUrl: null }))
|
||||
}
|
||||
|
||||
export default (response) => {
|
||||
const sagiri = (response) => {
|
||||
const unknownIds = new Set(response.results.filter((result) => !sites[result.header.index_id]).map((result) => result.header.index_id))
|
||||
const results = response.results
|
||||
.filter((result) => !unknownIds.has(result.header.index_id))
|
||||
@@ -378,4 +374,5 @@ export default (response) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
export default sagiri
|
||||
// # sourceMappingURL=sites.js.map
|
||||
Reference in New Issue
Block a user