mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
[cmd](search) reverse-image
This commit is contained in:
parent
6526b79c86
commit
e2f69b14c1
4 changed files with 81 additions and 2 deletions
67
commands/message/search/reverse-image.js
Normal file
67
commands/message/search/reverse-image.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { tineye } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createTineyeResultPage(context, result){
|
||||||
|
let res = {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `**${link(result.url, result.name)}**\nLast indexed: ${result.date}`,
|
||||||
|
image: {
|
||||||
|
url: result.image
|
||||||
|
},
|
||||||
|
thumbnail: {
|
||||||
|
url: result.cached
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.tineye,
|
||||||
|
text: `TinEye • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'reverse-image',
|
||||||
|
aliases: ['reverse', 'tineye','reverseimage'],
|
||||||
|
metadata: {
|
||||||
|
description: 'reverse image search',
|
||||||
|
examples: ['reverseimage'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'reverse <image>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
try{
|
||||||
|
let image = await getRecentImage(context, 50)
|
||||||
|
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||||
|
|
||||||
|
let search = await tineye(context, image)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createTineyeResultPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const paging = await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform reverse image search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -32,6 +32,7 @@ const Api = Object.freeze({
|
||||||
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||||
SEARCH_LYRICS: '/search/lyrics',
|
SEARCH_LYRICS: '/search/lyrics',
|
||||||
SEARCH_RULE34: '/search/booru',
|
SEARCH_RULE34: '/search/booru',
|
||||||
|
SEARCH_TINEYE: '/search/tineye',
|
||||||
SEARCH_URBANDICTIONARY: '/search/urbandictionary',
|
SEARCH_URBANDICTIONARY: '/search/urbandictionary',
|
||||||
SEARCH_WIKIHOW: '/search/wikihow',
|
SEARCH_WIKIHOW: '/search/wikihow',
|
||||||
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
|
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
|
||||||
|
|
|
@ -135,6 +135,12 @@ module.exports.bingImages = async function(context, query){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.tineye = async function(context, url){
|
||||||
|
return await request(Api.SEARCH_TINEYE, "GET", {}, {
|
||||||
|
url: url
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.urbandictionary = async function(context, query){
|
module.exports.urbandictionary = async function(context, query){
|
||||||
return await request(Api.SEARCH_URBANDICTIONARY, "GET", {}, {
|
return await request(Api.SEARCH_URBANDICTIONARY, "GET", {}, {
|
||||||
q: query
|
q: query
|
||||||
|
|
|
@ -39,6 +39,10 @@ const Statics = Object.freeze({
|
||||||
wikihow: {
|
wikihow: {
|
||||||
file: "brands/wikihow.png",
|
file: "brands/wikihow.png",
|
||||||
revision: 1
|
revision: 1
|
||||||
|
},
|
||||||
|
tineye: {
|
||||||
|
file: "brands/tineye.png",
|
||||||
|
revision: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -56,5 +60,6 @@ module.exports.STATICS = Object.freeze({
|
||||||
inferkit: staticAsset(Statics.brands.inferkit),
|
inferkit: staticAsset(Statics.brands.inferkit),
|
||||||
youtube: staticAsset(Statics.brands.youtube),
|
youtube: staticAsset(Statics.brands.youtube),
|
||||||
urbandictionary: staticAsset(Statics.brands.urbandictionary),
|
urbandictionary: staticAsset(Statics.brands.urbandictionary),
|
||||||
wikihow: staticAsset(Statics.brands.wikihow)
|
wikihow: staticAsset(Statics.brands.wikihow),
|
||||||
|
tineye: staticAsset(Statics.brands.tineye)
|
||||||
})
|
})
|
Loading…
Add table
Add a link
Reference in a new issue