2022-09-27 16:45:50 -04:00
const { Constants } = require ( 'discord.js' ) ;
2022-05-13 22:03:05 +03:00
const scraper = require ( 'mal-scraper' ) ;
2022-09-27 16:45:50 -04:00
2022-05-13 22:03:05 +03:00
module . exports = {
2022-05-18 21:34:58 +03:00
name : 'asearch' ,
2022-05-18 21:53:23 +03:00
description : 'Selmer bot gives you info on an anime' ,
2022-09-27 16:45:50 -04:00
async execute ( interaction , Discord , Client , bot ) {
const args = interaction . options . data ;
const name = args . filter ( ( arg ) => { return ( arg . name == 'anime' ) ; } ) [ 0 ] . value ;
var style ;
2022-05-18 21:34:58 +03:00
if ( args . length > 1 ) {
2022-09-27 16:45:50 -04:00
style = args . filter ( ( arg ) => { return ( arg . name == 'style' ) ; } ) [ 0 ] . value ;
}
else { style = "stats" ; }
2022-07-16 19:26:06 +03:00
2022-09-27 16:45:50 -04:00
//Maybe change it to "this anime movie" if there is only 1 episode?
2022-05-18 21:34:58 +03:00
2022-07-19 15:41:49 +03:00
//When set to true, getInfoFromName.getBestMatch did not, in fact, return the best results
scraper . getInfoFromName ( name , false ) . then ( ( data ) => {
2022-09-27 16:45:50 -04:00
try { console . log ( data ) ;
if ( style == 'stats' ) {
2022-07-16 19:26:06 +03:00
const newEmbed = new Discord . MessageEmbed ( )
. setColor ( '#002eff' )
. setTitle ( data . title )
//.setURL('https://discordjs.guide/popular-topics/embeds.html#embed-preview')
//.setDescription('My professional resume')
. setImage ( data . picture )
. addFields (
{ name : 'Genres:' , value : data . genres . join ( ", " ) } ,
{ name : 'Score:' , value : data . score } ,
2022-09-27 16:45:50 -04:00
{ name : 'Episode:' , value : data . episodes } ,
{ name : "Date Aired/Premiered" , value : data . premiered || data . aired }
2022-07-16 19:26:06 +03:00
) . setURL ( data . trailer ) ;
2022-09-27 16:45:50 -04:00
interaction . reply ( { embeds : [ newEmbed ] } ) ;
} else if ( style == 'fancy' ) {
let temp = ` The ${ data . genres . join ( ", " ) } anime _ ${ data . title } _ first aired on ${ data . premiered || data . aired } ` ;
2022-07-16 19:26:06 +03:00
if ( data . aired ) { temp += ` . This anime ran for ${ data . aired } for a total of ${ data . episodes } episodes. ` }
else { temp += ` and is still airing with ${ data . episodes } so far! ` }
2022-05-13 22:03:05 +03:00
2022-07-16 19:26:06 +03:00
temp += ` This anime has a score of ${ data . score } and is ${ data . popularity } on MyAnimeList! \n ` ;
2022-09-27 16:45:50 -04:00
temp += ` You can see a trailer for ${ data . title } ***[here]( ${ data . trailer } )*** ` ;
// temp += `\n\n(to see a summary of the anime, use '${bot.prefix}asearch <anime name> summary')`;
2022-07-16 19:26:06 +03:00
2022-09-27 16:45:50 -04:00
interaction . reply ( { embeds : [ new Discord . MessageEmbed ( ) . setImage ( data . picture ) . setDescription ( temp ) ] } ) ;
// message.channel.send(temp);
} else if ( style == 'summary' ) {
2022-07-16 19:26:06 +03:00
let temp = data . synopsis ;
2022-09-27 16:45:50 -04:00
interaction . reply ( temp ) ;
2022-07-16 19:26:06 +03:00
} else {
2022-09-27 16:45:50 -04:00
interaction . reply ( ` Unknown command, try using the format '/asearch <anime name> [stats or fancy or summary] ` ) ;
2022-07-16 19:26:06 +03:00
}
} catch ( err ) {
if ( err . message . indexOf ( 'MessageEmbed field values must be non-empty strings' ) != - 1 ) {
2022-09-27 16:45:50 -04:00
interaction . reply ( ` Insufficient information on website! \n The page can be found here: ${ data . url } ` ) ;
2022-07-19 15:41:49 +03:00
} else {
2022-09-27 16:45:50 -04:00
const m = interaction . reply ( "Uh oh, an unknown error occured, click the ✅ to report this!" ) ;
2022-07-19 15:41:49 +03:00
const { addComplaintButton } = require ( '../dev only/submitcomplaint' ) ;
2022-09-27 16:45:50 -04:00
m . then ( ( msg ) => {
addComplaintButton ( bot , msg ) ;
} ) ;
2022-07-16 19:26:06 +03:00
}
2022-07-19 15:41:49 +03:00
console . log ( err ) ;
2022-05-13 22:03:05 +03:00
}
2022-05-18 21:34:58 +03:00
2022-05-13 22:03:05 +03:00
} ) ;
2022-09-27 16:45:50 -04:00
} ,
options : [
{ name : 'anime' , description : 'The name of the anime' , type : Constants . ApplicationCommandOptionTypes . STRING , required : true } ,
{ name : 'style' , description : 'stats or fancy or summary (defaults to stats)' , type : Constants . ApplicationCommandOptionTypes . STRING , required : false , choices : [ { name : 'stats' , value : 'stats' } , { name : 'fancy' , value : 'fancy' } , { name : 'summary' , value : 'summary' } ] }
]
2022-05-13 22:03:05 +03:00
}