mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -04:00
add omnisearch for movies&tv
This commit is contained in:
parent
d6b3239e4c
commit
6ddf9829ab
5 changed files with 98 additions and 4 deletions
81
commands/message/search/movie.js
Normal file
81
commands/message/search/movie.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
const { movie } = require('#api');
|
||||||
|
const { paginator } = require('#client');
|
||||||
|
const { PERMISSION_GROUPS, OMNI_ANIME_FORMAT_TYPES, OMNI_MOVIE_TYPES } = require('#constants');
|
||||||
|
|
||||||
|
const { createEmbed, formatPaginationEmbeds, page, hexToEmbedColor } = require('#utils/embed');
|
||||||
|
const { acknowledge } = require('#utils/interactions');
|
||||||
|
const { smallPill, pill } = require('#utils/markdown');
|
||||||
|
const { editOrReply } = require('#utils/message');
|
||||||
|
|
||||||
|
function renderMovieResultsPage(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.type) result.description += `${pill(OMNI_MOVIE_TYPES[res.type])} `
|
||||||
|
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);
|
||||||
|
|
||||||
|
return page(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'movie',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['tv','show','shows','tvshows','movies','mov'],
|
||||||
|
metadata: {
|
||||||
|
description: 'Returns search results for Movies & TV Shows.',
|
||||||
|
description_short: 'Search Movies & TV Shows',
|
||||||
|
examples: [
|
||||||
|
'tv wilsberg',
|
||||||
|
'mov stranger by the shore'
|
||||||
|
],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'movie <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 movie(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(renderMovieResultsPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||||
|
|
||||||
|
await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages: formatPaginationEmbeds(pages)
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
if(e.response?.body?.status == 1) return editOrReply(context, createEmbed("warning", context, e.response?.body?.message))
|
||||||
|
if(e.response?.body?.status == 2) return editOrReply(context, createEmbed("warning", context, e.response?.body?.message))
|
||||||
|
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, createEmbed("error", context, `Unable to perform anime search.`))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -31,6 +31,7 @@ const Api = Object.freeze({
|
||||||
|
|
||||||
OMNI_ANIME: '/omni/anime',
|
OMNI_ANIME: '/omni/anime',
|
||||||
OMNI_ANIME_SUPPLEMENTAL: '/omni/anime-supplemental',
|
OMNI_ANIME_SUPPLEMENTAL: '/omni/anime-supplemental',
|
||||||
|
OMNI_MOVIE: '/omni/movie',
|
||||||
|
|
||||||
PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave',
|
PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave',
|
||||||
PHOTOFUNIA_YACHT: '/photofunia/yacht',
|
PHOTOFUNIA_YACHT: '/photofunia/yacht',
|
||||||
|
|
|
@ -409,4 +409,11 @@ module.exports.animeSupplemental = async function(context, supplementalKey){
|
||||||
return await request(Api.OMNI_ANIME_SUPPLEMENTAL, "GET", {}, {
|
return await request(Api.OMNI_ANIME_SUPPLEMENTAL, "GET", {}, {
|
||||||
supplemental_key: supplementalKey
|
supplemental_key: supplementalKey
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.movie = async function(context, query, includeAdultContent){
|
||||||
|
return await request(Api.OMNI_MOVIE, "GET", {}, {
|
||||||
|
q: query,
|
||||||
|
include_adult: includeAdultContent
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1674,4 +1674,9 @@ module.exports.OMNI_ANIME_FORMAT_TYPES = Object.freeze({
|
||||||
MANGA: "Manga",
|
MANGA: "Manga",
|
||||||
NOVEL: "Novel",
|
NOVEL: "Novel",
|
||||||
ONE_SHOT: "One Shot"
|
ONE_SHOT: "One Shot"
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports.OMNI_MOVIE_TYPES = Object.freeze({
|
||||||
|
"movie": "Movie",
|
||||||
|
"tv": "TV Show"
|
||||||
})
|
})
|
|
@ -180,10 +180,10 @@ 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, message = {}){
|
||||||
return {
|
return Object.assign(message, {
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.hexToEmbedColor = (color)=>{
|
module.exports.hexToEmbedColor = (color)=>{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue