2019-12-25 16:20:32 -05:00
module . exports = async ( app , req , res , api ) => {
if ( ! req . body . targetID ) return res . status ( 400 ) . send ( "No target ID provided!" )
if ( ! req . body . message ) return res . status ( 400 ) . send ( "No message provided!" )
if ( ! req . body . accountID ) return res . status ( 400 ) . send ( "No account ID provided!" )
if ( ! req . body . password ) return res . status ( 400 ) . send ( "No password provided!" )
2020-09-22 18:37:21 -04:00
let subject = Buffer . from ( req . body . subject ? ( req . body . color ? "☆" : "" ) + ( req . body . subject . slice ( 0 , 50 ) ) : ( req . body . color ? "☆" : "" ) + "No subject" ) . toString ( 'base64' ) . replace ( /\//g , '_' ) . replace ( /\+/g , "-" )
2021-01-18 21:54:18 -05:00
let body = app . xor . encrypt ( req . body . message . slice ( 0 , 300 ) , 14251 )
2019-12-25 16:20:32 -05:00
2020-11-01 15:29:32 -05:00
let params = req . gdParams ( {
2019-12-25 16:20:32 -05:00
accountID : req . body . accountID ,
2021-01-18 21:54:18 -05:00
gjp : app . xor . encrypt ( req . body . password , 37526 ) ,
2019-12-25 16:20:32 -05:00
toAccountID : req . body . targetID ,
subject , body ,
2020-09-29 21:42:18 -04:00
} )
2019-12-25 16:20:32 -05:00
2021-01-18 21:54:18 -05:00
req . gdRequest ( 'uploadGJMessage20' , params , function ( err , resp , body ) {
if ( body != 1 ) return res . status ( 400 ) . send ( ` The Geometry Dash servers refused to send the message! Try again later, or make sure your username and password are entered correctly. Last worked: ${ app . timeSince ( req . id ) } ago. ` )
2019-12-25 16:20:32 -05:00
else res . status ( 200 ) . send ( 'Message sent!' )
2021-01-18 21:54:18 -05:00
app . trackSuccess ( req . id )
2019-12-25 16:20:32 -05:00
} )
}