2022-09-27 16:45:50 -04:00
const { Constants } = require ( 'discord.js' ) ;
2022-05-18 21:53:23 +03:00
const scraper = require ( 'mal-scraper' ) ;
const search = scraper . search ;
const type = "manga" ;
2022-09-27 16:45:50 -04:00
2022-05-18 21:53:23 +03:00
module . exports = {
name : 'msearch' ,
description : 'Selmer bot gives you info on a manga' ,
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 == 'manga' ) ; } ) [ 0 ] . value ;
var style ;
2022-05-18 21:53:23 +03:00
if ( args . length > 1 ) {
2022-09-27 16:45:50 -04:00
style = args . filter ( ( arg ) => { return ( arg . name == 'style' ) ; } ) [ 0 ] . value ;
2022-05-18 21:53:23 +03:00
}
2022-09-27 16:45:50 -04:00
else { style = "stats" ; }
2022-05-20 10:39:34 +03:00
2022-07-19 15:41:49 +03:00
try {
search . search ( type , {
maxResults : 1 ,
term : name
} ) . then ( ( data1 ) => {
let data = data1 [ 0 ] ;
2022-09-27 16:45:50 -04:00
if ( style == "stats" ) {
2022-07-19 15:41:49 +03:00
const newEmbed = new Discord . MessageEmbed ( )
. setColor ( '#ff9900' )
. setTitle ( data . title )
. setURL ( data . url )
. setImage ( data . thumbnail )
//.setDescription('My professional resume')
. addFields (
{ name : 'Type:' , value : data . type } ,
{ name : 'Score:' , value : data . score } ,
{ name : 'Volumes:' , value : data . vols }
) ;
2022-09-27 16:45:50 -04:00
interaction . reply ( { embeds : [ newEmbed ] } ) ;
} else if ( style == "fancy" ) {
2022-07-19 15:41:49 +03:00
let temp = ` The ${ data . type } _ ${ data . title } _ currently has ${ data . vols } volumes with ${ data . nbChapters } chapters, ` ;
temp += ` running from _ ${ data . startDate . replace ( /-/g , "/" ) } _ to _ ${ data . endDate . replace ( /-/g , "/" ) } _, and has a score of ${ data . score } on MyAnimeList! \n ` ;
temp += ` You can read more about _ ${ data . title } _ at ${ data . url } ` ;
2022-09-27 16:45:50 -04:00
interaction . reply ( temp ) ;
} else if ( style == "summary" ) {
2022-07-19 15:41:49 +03:00
//Remove the "read more." at the end
let temp = data . shortDescription . slice ( 0 , - 10 ) ;
temp += ` _read more at_ ${ data . url } ` ;
2022-09-27 16:45:50 -04:00
return interaction . reply ( temp ) ;
2022-07-19 15:41:49 +03:00
} else {
2022-09-27 16:45:50 -04:00
interaction . reply ( ` Unknown command, try using the format ' ${ bot . prefix } msearch <manga name> [stats or fancy or summary] ` ) ;
2022-07-19 15:41:49 +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-05-20 10:39:34 +03:00
}
2022-07-19 15:41:49 +03:00
console . log ( err ) ;
}
2022-09-27 16:45:50 -04:00
} ,
options : [ { name : 'manga' , description : 'The name of the manga' , 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-18 21:53:23 +03:00
}