mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -04:00
add initial anime search work
This commit is contained in:
parent
cc4f57d133
commit
d37a0d46de
4 changed files with 113 additions and 1 deletions
94
commands/message/search/anime.js
Normal file
94
commands/message/search/anime.js
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
const { anime } = require('#api');
|
||||||
|
const { paginator } = require('#client');
|
||||||
|
const { PERMISSION_GROUPS } = require('#constants');
|
||||||
|
|
||||||
|
const { createEmbed, formatPaginationEmbeds, page, hexToEmbedColor } = require('#utils/embed');
|
||||||
|
const { acknowledge } = require('#utils/interactions');
|
||||||
|
const { smallPill, link } = require('#utils/markdown');
|
||||||
|
const { editOrReply } = require('#utils/message');
|
||||||
|
|
||||||
|
function renderAnimeResultsPage(context, res){
|
||||||
|
let result = createEmbed("default", context, {
|
||||||
|
author: {
|
||||||
|
name: res.title,
|
||||||
|
url: res.url
|
||||||
|
},
|
||||||
|
description: ``,
|
||||||
|
fields: []
|
||||||
|
})
|
||||||
|
|
||||||
|
// Render Description
|
||||||
|
if(res.subtitle) result.description += `-# ${res.subtitle}\n\n`;
|
||||||
|
if(res.genres) result.description += res.genres.map((r)=>smallPill(r)).join(" ") + "\n\n";
|
||||||
|
if(res.description) result.description += res.description;
|
||||||
|
|
||||||
|
// Render Images
|
||||||
|
if(res.cover) result.thumbnail = { url: res.cover };
|
||||||
|
if(res.image) result.image = { url: res.image };
|
||||||
|
|
||||||
|
// Render Color
|
||||||
|
if(res.color) result.color = hexToEmbedColor(res.color);
|
||||||
|
|
||||||
|
// Render Episode Metadata
|
||||||
|
if(res.episodes) {
|
||||||
|
result.fields.push({
|
||||||
|
name: "Episodes",
|
||||||
|
value: `${res.episodes} ${res.episode_length ? `@ ${res.episode_length}` : ""}`,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res.links){
|
||||||
|
result.fields.push({
|
||||||
|
name: "Links",
|
||||||
|
value: res.links.map((l)=>`${link(l.url, l.label)}`).join("\n"),
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return page(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'anime',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['ani'],
|
||||||
|
metadata: {
|
||||||
|
description: 'Returns search results for Anime.',
|
||||||
|
description_short: 'Search Anime',
|
||||||
|
examples: [
|
||||||
|
'ani dandadan',
|
||||||
|
'ani stranger by the shore'
|
||||||
|
],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'anime <query>',
|
||||||
|
//slashCommand: "anime"
|
||||||
|
},
|
||||||
|
permissionsClient: [...PERMISSION_GROUPS.baseline],
|
||||||
|
run: async (context, args) => {
|
||||||
|
await acknowledge(context);
|
||||||
|
|
||||||
|
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||||
|
try{
|
||||||
|
let search = await anime(context, args.query, context.channel.nsfw)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
if(search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(renderAnimeResultsPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||||
|
|
||||||
|
await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages: formatPaginationEmbeds(pages)
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, createEmbed("error", context, `Unable to perform anime search.`))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -32,6 +32,8 @@ const Api = Object.freeze({
|
||||||
PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave',
|
PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave',
|
||||||
PHOTOFUNIA_YACHT: '/photofunia/yacht',
|
PHOTOFUNIA_YACHT: '/photofunia/yacht',
|
||||||
|
|
||||||
|
SEARCH_ANIME: '/search/anime',
|
||||||
|
SEARCH_ANIME_SUPPLEMENTAL: '/search/anime-supplemental',
|
||||||
SEARCH_BING: '/search/bing',
|
SEARCH_BING: '/search/bing',
|
||||||
SEARCH_BING_IMAGES: '/search/bing-images',
|
SEARCH_BING_IMAGES: '/search/bing-images',
|
||||||
SEARCH_GOOGLE: '/search/google',
|
SEARCH_GOOGLE: '/search/google',
|
||||||
|
|
|
@ -170,6 +170,19 @@ module.exports.rule34 = async function(context, query, service){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.anime = async function(context, query, includeAdultContent){
|
||||||
|
return await request(Api.SEARCH_ANIME, "GET", {}, {
|
||||||
|
q: query,
|
||||||
|
include_adult: includeAdultContent
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.animeSupplemental = async function(context, supplementalKey){
|
||||||
|
return await request(Api.SEARCH_ANIME_SUPPLEMENTAL, "GET", {}, {
|
||||||
|
supplemental_key: supplementalKey
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.bing = async function(context, query, nsfw){
|
module.exports.bing = async function(context, query, nsfw){
|
||||||
return await request(Api.SEARCH_BING, "GET", {}, {
|
return await request(Api.SEARCH_BING, "GET", {}, {
|
||||||
q: query,
|
q: query,
|
||||||
|
|
|
@ -181,8 +181,11 @@ module.exports.formatPaginationEmbeds = function(embeds){
|
||||||
|
|
||||||
// Creates a page for our paginator. simple helper so we dont have to do {embeds:[]} every time
|
// Creates a page for our paginator. simple helper so we dont have to do {embeds:[]} every time
|
||||||
module.exports.page = function(embed){
|
module.exports.page = function(embed){
|
||||||
|
|
||||||
return {
|
return {
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.hexToEmbedColor = (color)=>{
|
||||||
|
return parseInt(color.split("#")[1], 16)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue