2019-09-13 20:02:41 +00:00
const gm = require ( "gm" ) . subClass ( {
imageMagick : true
} ) ;
const gmToBuffer = require ( "../utils/gmbuffer.js" ) ;
const wrap = require ( "../utils/wrap.js" ) ;
exports . run = async ( message , args ) => {
2019-12-02 20:47:22 +00:00
if ( args . length === 0 ) return ` ${ message . author . mention } , you need to provide some text to make a Sonic meme! ` ;
2019-09-13 20:02:41 +00:00
message . channel . sendTyping ( ) ;
const template = "./assets/images/sonic.jpg" ;
2019-10-28 16:02:00 +00:00
const file = ` /tmp/ ${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) } .png ` ;
2019-12-10 14:24:13 +00:00
const cleanedMessage = args . join ( " " ) . replace ( /&/g , "\\&" ) . replace ( />/g , "\\>" ) . replace ( /</g , "\\<" ) . replace ( /"/g , "\\"" ) . replace ( /'/g , "\\'" ) ;
gm ( 474 , 332 ) . out ( "+size" ) . background ( "none" ) . gravity ( "Center" ) . out ( "-pointsize" , 72 ) . out ( "-font" , "Bitstream Vera Sans" ) . out ( ` pango:<span foreground="white"> ${ wrap ( cleanedMessage , { width : 15 , indent : "" } )}</span> ` ) . write ( file , async ( error ) => {
2019-12-10 15:53:43 +00:00
if ( error ) throw error ;
2019-09-13 20:02:41 +00:00
const command = gm ( template ) . composite ( file ) . gravity ( "Center" ) . geometry ( "474x332+160+10" ) ;
return message . channel . createMessage ( "" , {
2020-02-13 20:31:40 +00:00
file : await gmToBuffer ( command , "png" ) ,
2019-09-13 20:02:41 +00:00
name : "sonic.png"
} ) ;
} ) ;
2019-12-02 20:47:22 +00:00
} ;
exports . category = 4 ;
2019-12-05 16:58:46 +00:00
exports . help = "Creates a Sonic speech bubble image" ;
exports . params = "[text]" ;