@ -15,85 +15,93 @@ class manga extends Command{
}
async run ( message , args )
{
if ( ! args [ 0 ] ) return new ErrorMessage ( this . client ) . send ( ErrorType . Arguments , message )
const data = await new Anilist ( ) . searchManga ( args . join ( ' ' ) ) ;
if ( data == 'Error' ) return new ErrorMessage ( this . client ) . send ( ErrorType . Arguments , message , [ ` Couldn't find any character with the search argument you provided. ` ] )
// console.log('SearchManga: Data:', data)
const embed = new EmbedBuilder ( ) ;
const randomID = Random ( ) ;
const row = new ActionRowBuilder ( ) ;
var fieldPayload = [ ] ;
var embeds = [ ] ;
for ( var i = 0 ; i < data . length ; i ++ )
{
fieldPayload . push ( { name : data [ i ] . title . romaji + ( data [ i ] . title . english ? "(" + data [ i ] . title . english + ")" : '' ) , value : i . toString ( ) } ) ;
embeds . push ( new EmbedBuilder ( ) . setImage ( data [ i ] . image ) . setURL ( 'https://www.rem.wordfights.com' ) ) ;
row . addComponents (
new ButtonBuilder ( )
. setCustomId ( randomID + i )
. setLabel ( i . toString ( ) )
. setStyle ( ButtonStyle . Success )
) ;
}
if ( ! args [ 0 ] ) return new ErrorMessage ( this . client ) . send ( ErrorType . NoArguments , message )
const data = await new Anilist ( ) . searchManga ( args . join ( ' ' ) ) ;
if ( data == 'Error' ) return new ErrorMessage ( this . client ) . send ( ErrorType . Arguments , message , [ ` Couldn't find any character with the search argument you provided. ` ] )
// console.log('SearchManga: Data:', data)
const embed = new EmbedBuilder ( ) ;
const randomID = Random ( ) ;
const row = new ActionRowBuilder ( ) ;
var fieldPayload = [ ] ;
var embeds = [ ] ;
for ( var i = 0 ; i < data . length ; i ++ )
{
fieldPayload . push ( { name : data [ i ] . title . romaji + ( data [ i ] . title . english ? "(" + data [ i ] . title . english + ")" : '' ) , value : i . toString ( ) } ) ;
embeds . push ( new EmbedBuilder ( ) . setImage ( data [ i ] . image ) . setURL ( 'https://www.rem.wordfights.com' ) ) ;
row . addComponents (
new ButtonBuilder ( )
. setCustomId ( randomID + 4 )
. setLabel ( 'Cancel' )
. setStyle ( ButtonStyle . Danger )
)
embed . setTitle ( ` First ${ data . length >= 4 ? '4' : ( data . length + ' and only' ) } result ${ data . length > 1 ? 's' : '' } of search: ` )
. setAuthor ( { name : "Rem-chan" , iconURL : "https://i.imgur.com/g6FSNhL.png" , url : 'https://rem.wordfights.com/addtodiscord' } )
. setColor ( 0x003284 )
. setURL ( 'https://www.rem.wordfights.com' )
. setFooter ( { text : 'Rem-Chan on' , iconURL : 'https://i.imgur.com/g6FSNhL.png' } )
. setTimestamp ( )
. addFields ( fieldPayload ) ;
. setCustomId ( randomID + i )
. setLabel ( i . toString ( ) )
. setStyle ( ButtonStyle . Success )
) ;
}
row . addComponents (
new ButtonBuilder ( )
. setCustomId ( randomID + 4 )
. setLabel ( 'Cancel' )
. setStyle ( ButtonStyle . Danger )
)
embed . setTitle ( ` First ${ data . length >= 4 ? '4' : ( data . length + ' and only' ) } result ${ data . length > 1 ? 's' : '' } of search: ` )
. setAuthor ( { name : "Rem-chan" , iconURL : "https://i.imgur.com/g6FSNhL.png" , url : 'https://rem.wordfights.com/addtodiscord' } )
. setColor ( 0x003284 )
. setURL ( 'https://www.rem.wordfights.com' )
. setFooter ( { text : 'Rem-Chan on' , iconURL : 'https://i.imgur.com/g6FSNhL.png' } )
. setTimestamp ( )
. addFields ( fieldPayload ) ;
embeds . unshift ( embed ) ;
embeds . unshift ( embed ) ;
const filter = i => i . customId . slice ( 0 , - 1 ) === randomID ;
await message . channel . send ( { ephemeral : true , embeds , components : [ row ] } ) ;
const filter = i => i . customId . slice ( 0 , - 1 ) === randomID ;
const Message = await message . channel . send ( { ephemeral : true , embeds , components : [ row ] } ) ;
const collector = message . channel . createMessageComponentCollector ( { filter , time : 60000 } ) ;
collector . on ( 'collect' , async m =>
{
message . delete ( ) ;
m . message . delete ( ) ;
if ( m . customId [ m . customId . length - 1 ] != 4 ) sendMessage ( data [ m . customId [ m . customId . length - 1 ] ] . id , this . client ) ;
} ) ;
collector . on ( 'end' , async ( ) =>
{
this . client . guilds . cache . get ( Message . guildId ) . channels . cache . get ( Message . channelId ) . messages . cache . get ( Message . id ) . edit ( { components : [ ] } ) ;
} )
/ * *
* @ param { Number } id
* /
async function sendMessage ( id , client )
{
const data = await new Anilist ( ) . getMangaInfo ( id ) ;
data . description = data . description . replaceAll ( '~!' , '' ) . replaceAll ( '!~' , '' ) . replaceAll ( /<[^>]*>/g , '' ) ;
data . description = data . description . length > 1500 ? ( data . description . substring ( 0 , 1500 ) + "..." ) : data . description ;
console . log ( data . description )
const embed = new EmbedBuilder ( )
. setTitle ( ` ${ data . title . romaji } ( ${ data . title . native + ( data . title . english ? '/' + data . title . english : '' ) } ) ` )
. setAuthor ( { name : "Rem-chan" , iconURL : "https://i.imgur.com/g6FSNhL.png" , url : 'https://rem.wordfights.com/addtodiscord' } )
. setColor ( 0x003284 )
. setDescription ( data . description )
. setFooter ( { text : 'Rem-Chan on' , iconURL : 'https://i.imgur.com/g6FSNhL.png' } )
. addFields ( { name : 'Page' , value : data . url , inline : true } )
. setImage ( data . coverImage )
. setThumbnail ( data . coverImage )
. setTimestamp ( )
const randomID = Random ( ) ;
const row = new ActionRowBuilder ( )
. addComponents (
new ButtonBuilder ( )
. setCustomId ( randomID )
. setLabel ( 'Remove this.' )
. setStyle ( ButtonStyle . Primary ) ,
) ;
const filter = i => i . customId === randomID ;
const sentMessage = await message . channel . send ( { ephemeral : true , embeds : [ embed ] , components : [ row ] } ) ;
const collector = message . channel . createMessageComponentCollector ( { filter , time : 60000 } ) ;
collector . on ( 'collect' , async m =>
{
message . delete ( ) ;
m . message . delete ( ) ;
if ( m . customId [ m . customId . length - 1 ] != 4 ) sendMessage ( data [ m . customId [ m . customId . length - 1 ] ] . id ) ;
} ) ;
/ * *
* @ param { Number } id
* /
async function sendMessage ( id )
} ) ;
collector . on ( 'end' , async ( ) =>
{
const data = await new Anilist ( ) . getMangaInfo ( id ) ;
data . description = data . description . replaceAll ( '~!' , '' ) . replaceAll ( '!~' , '' ) . replaceAll ( /<[^>]*>/g , '' ) ;
data . description = data . description . length > 1500 ? ( data . description . substring ( 0 , 1500 ) + "..." ) : data . description ;
console . log ( data . description )
const embed = new EmbedBuilder ( )
. setTitle ( ` ${ data . title . romaji } ( ${ data . title . native + ( data . title . english ? '/' + data . title . english : '' ) } ) ` )
. setAuthor ( { name : "Rem-chan" , iconURL : "https://i.imgur.com/g6FSNhL.png" , url : 'https://rem.wordfights.com/addtodiscord' } )
. setColor ( 0x003284 )
. setDescription ( data . description )
. setFooter ( { text : 'Rem-Chan on' , iconURL : 'https://i.imgur.com/g6FSNhL.png' } )
. addFields ( { name : 'Page' , value : data . url , inline : true } )
. setImage ( data . coverImage )
. setThumbnail ( data . coverImage )
. setTimestamp ( )
const randomID = Random ( ) ;
const row = new ActionRowBuilder ( )
. addComponents (
new ButtonBuilder ( )
. setCustomId ( randomID )
. setLabel ( 'Remove this.' )
. setStyle ( ButtonStyle . Primary ) ,
) ;
const filter = i => i . customId === randomID ;
await message . channel . send ( { ephemeral : true , embeds : [ embed ] , components : [ row ] } ) ;
const collector = message . channel . createMessageComponentCollector ( { filter , time : 60000 } ) ;
collector . on ( 'collect' , async m =>
{
m . message . delete ( ) ;
} ) ;
}
client . guilds . cache . get ( sentMessage . guildId ) . channels . cache . get ( sentMessage . channelId ) . messages . cache . get ( sentMessage . id ) . edit ( { components : [ ] } ) ;
} )
}
}
} module . exports = manga ;