import type { Emoji , Message , TextChannel , User } from "eris" ; import { Command } from "../../classes/Command" ; import { timeoutHandler , waitFor } from "../../utils/waitFor" ; export class EmbedCommand extends Command { description = "Creates a custom embed." ; aliases = [ "embedmessage" , "embedmsg" , "rembed" , "richembed" ] ; cooldown = 3000 ; staff = true ; async run ( msg , pargs , args ) { const emojis = [ ] ; const emojiactions = { "🇦" : "title" , "🇧" : "description" , "🖼" : "image.url" , "📷" : "thumbnail.url" , "👤" : "author.name" , "📸" : "author.icon_url" , "💬" : "footer.text" , "🎥" : "footer.icon_url" , "🖍" : "color" , "📅" : "timestamp" , "✅" : "hibiki:done" , "❌" : "hibiki:cancel" , } ; const emojilabels = { "title" : msg . string ( "global.TITLE" ) , "description" : msg . string ( "global.DESCRIPTION" ) , "image.url" : msg . string ( "global.IMAGE" ) , "thumbnail.url" : msg . string ( "global.THUMBNAIL" ) , "author.name" : msg . string ( "moderation.EMBED_AUTHORTEXT" ) , "author.icon_url" : msg . string ( "moderation.EMBED_AUTHORICON" ) , "footer.text" : msg . string ( "moderation.EMBED_FOOTERTEXT" ) , "footer.icon_url" : msg . string ( "moderation.EMBED_FOOTERICON" ) , "color" : msg . string ( "global.COLOR" ) , "timestamp" : msg . string ( "global.TIMESTAMP" ) , "hibiki:done" : msg . string ( "global.DONE" ) , "hibiki:cancel" : msg . string ( "global.CANCEL" ) , } ; const emojidescriptions = { "title" : msg . string ( "moderation.EMBED_TITLE" ) , "description" : msg . string ( "moderation.EMBED_DESCRIPTION" ) , "image.url" : msg . string ( "moderation.EMBED_IMAGEURL_DESCRIPTION" ) , "thumbnail.url" : msg . string ( "moderation.EMBED_THUMBNAIL_DESCRIPTION" ) , "author.name" : msg . string ( "moderation.EMBED_AUTHORNAME_DESCRIPTION" ) , "author.icon_url" : msg . string ( "moderation.EMBED_AUTHORICON_DESCRIPTION" ) , "footer.text" : msg . string ( "moderation.EMBED_FOOTERTEXT_DESCRIPTION" ) , "footer.icon_url" : msg . string ( "moderation.EMBED_FOOTERICON_DESCRIPTION" ) , "color" : msg . string ( "moderation.EMBED_COLOR_DESCRIPTION" ) , "timestamp" : msg . string ( "moderation.EMBED_TIMESTAMP" ) , "hibiki:done" : msg . string ( "moderation.EMBED_SEND" ) , "hibiki:cancel" : msg . string ( "moderation.EMBED_CANCEL" ) , } ; let embed = { } ; Object . entries ( emojiactions ) . forEach ( ( e ) => emojis . push ( e [ 0 ] ) ) ; const embedmsg = await msg . channel . createMessage ( { embed : { title : `🖊 ${ msg . string ( "global.EMBED" ) }` , color : msg . convertHex ( "general" ) , fields : Object . entries ( emojiactions ) . map ( ( e ) => { return { name : `${ e [ 0 ] } ${ emojilabels [ e [ 1 ] ] ? emojilabels [ e [ 1 ] ] : e [ 1 ] }` , value : emojidescriptions [ e [ 1 ] ] ? emojidescriptions [ e [ 1 ] ] : msg . string ( "global.NO_CONTENT" ) , inline : true , } ; } ) , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; emojis . forEach ( ( e ) => embedmsg . addReaction ( e ) . catch ( ( ) => { } ) ) ; await waitFor ( "messageReactionAdd" , 300000 , async ( m , emoji , user ) => { if ( m . id !== embedmsg . id ) return false ; if ( user . id !== msg . author . id ) return false ; if ( ! emojiactions [ emoji . name ] ) return false ; let e = emojiactions [ emoji . name ] ; if ( e === "hibiki:done" ) return true ; if ( e === "hibiki:cancel" ) { embedmsg . delete ( ) ; embed = { error : msg . string ( "global.CANCELLED" ) } ; return true ; } m . removeReaction ( emoji . name , user . id ) . catch ( ( ) => { } ) ; if ( e === "timestamp" ) { embed . timestamp = new Date ( ) ; return ; } if ( e . includes ( "." ) ) e = e . split ( "." ) ; embedmsg . editEmbed ( `🖊 ${ msg . string ( "global.EMBED" ) } ` , msg . string ( "global.ASKFOR" , { item : emojilabels [ typeof e == "string" ? e : e . join ( "." ) ] ? `${ emojilabels [ typeof e == "string" ? e : e . join ( "." ) ] [ 0 ] . toLowerCase ( ) }${ emojilabels [ typeof e == "string" ? e : e . join ( "." ) ] . substring ( 1 ) }` : e [ 1 ] `` , } ) ) ; const [ resp ] = await waitFor ( "messageCreate" , 60000 , async ( message ) => { if ( message . author . id !== msg . author . id ) return false ; if ( message . channel . id !== msg . channel . id ) return false ; message . delete ( ) . catch ( ( ) => { } ) ; return true ; } , this . bot ) . catch ( ( err ) => { timeoutHandler ( err , embedmsg , msg . string ) ; } ) ; embedmsg . edit ( { embed : { title : `🖊 ${ msg . string ( "global.EMBED" ) }` , color : msg . convertHex ( "general" ) , fields : Object . entries ( emojiactions ) . map ( ( em ) => { return { name : `${ em [ 0 ] } ${ emojilabels [ em [ 1 ] ] ? emojilabels [ em [ 1 ] ] : em [ 1 ] }` , value : emojidescriptions [ em [ 1 ] ] ? emojidescriptions [ em [ 1 ] ] : msg . string ( "global.NO_CONTENT" ) , inline : true , } ; } ) , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) . catch ( ( ) => { } ) ; if ( typeof e == "string" && e !== "color" && e !== "timestamp" ) embed [ e ] = resp . content ; else if ( e === "color" ) { let finalhex ; const hexcheck = /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/ . exec ( resp . content ) ; if ( hexcheck ) args = `${ args . slice ( 0 , hexcheck . index ) }${ args . slice ( hexcheck . index + hexcheck [ 0 ] . length , args . length ) }` ; if ( ! hexcheck && isNaN ( parseInt ( `0x${ args }` ) ) ) { finalhex = msg . convertHex ( "general" ) ; } else { if ( ! hexcheck ) finalhex = parseInt ( `0x${ args }` ) ; else finalhex = parseInt ( hexcheck [ 0 ] . replace ( "#" , "0x" ) ) ; if ( finalhex >= 16777215 ) finalhex = 16777215 ; } embed [ e ] = finalhex ; } else { if ( ( e [ 0 ] === "image" || e [ 0 ] === "thumbnail" || e [ 0 ] === "author" || e [ 0 ] === "footer" ) && ( e [ 1 ] === "url" || e [ 1 ] === "icon_url" ) && resp . attachments ?. [ 0 ] ) resp . content = resp . attachments [ 0 ] . proxy_url ; let obj = { } ; if ( embed [ e [ 0 ] ] ) obj = embed [ e [ 0 ] ] ; obj [ e [ 1 ] ] = resp . content ; embed [ e [ 0 ] ] = obj ; } } , this . bot ) . catch ( ( ) => { } ) ; if ( ! Object . keys ( embed ) . length || Object . keys ( embed ) . includes ( "error" ) ) { return embedmsg . editEmbed ( msg . string ( "global.ERROR" ) , embed . error ? embed . error : msg . string ( "moderation.EMBED_INVALID" ) , "error" ) ; } if ( ! embed . color ) embed . color = msg . convertHex ( "general" ) ; await msg . channel . createMessage ( { embed : embed } ) . catch ( ( ) => { } ) ; await embedmsg . delete ( ) . catch ( ( ) => { } ) ; } }