mirror of
https://github.com/danbulant/discord.js
synced 2026-07-10 05:31:13 +00:00
Added file sending
This commit is contained in:
parent
68db1f6ac0
commit
9572236b69
3 changed files with 102 additions and 54 deletions
|
|
@ -264,6 +264,20 @@ Commands["setusername"] = {
|
|||
}
|
||||
}
|
||||
|
||||
Commands[ "cat" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
|
||||
var http = require( "http" );
|
||||
var request = require( 'request' );
|
||||
|
||||
bot.sendFile( message, request("http://thewallpaperhost.com/wp-content/uploads/2014/12/cool-hd-wallpaper.jpg"), "cat.jpg", function( err ) {
|
||||
bot.reply( message, err );
|
||||
} );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Commands[ "icon" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
|
|
|
|||
20
index.js
20
index.js
|
|
@ -745,7 +745,14 @@ exports.Client.prototype.startPM = function( user, callback ) {
|
|||
* delete itself after being sent.
|
||||
* @method sendMessage
|
||||
*/
|
||||
exports.Client.prototype.sendMessage = function( destination, toSend, callback, options ) {
|
||||
|
||||
exports.Client.prototype.sendFile = function( destination, toSend, fileName, callback, options ) {
|
||||
|
||||
this.sendMessage( destination, toSend, callback, options, fileName );
|
||||
|
||||
}
|
||||
|
||||
exports.Client.prototype.sendMessage = function( destination, toSend, callback, options, fileName ) {
|
||||
|
||||
options = options || {};
|
||||
callback = callback || function() {};
|
||||
|
|
@ -753,8 +760,10 @@ exports.Client.prototype.sendMessage = function( destination, toSend, callback,
|
|||
var channel_id, message, mentions, self = this;
|
||||
|
||||
channel_id = resolveChannel( destination, self );
|
||||
if ( !fileName ) {
|
||||
message = resolveMessage( toSend );
|
||||
mentions = resolveMentions( message, options.mention );
|
||||
}
|
||||
|
||||
if ( channel_id ) {
|
||||
send();
|
||||
|
|
@ -764,6 +773,15 @@ exports.Client.prototype.sendMessage = function( destination, toSend, callback,
|
|||
|
||||
function send() {
|
||||
|
||||
if(fileName){
|
||||
Internal.XHR.sendFile( self.token, channel_id, toSend, fileName, function(err){
|
||||
|
||||
callback(err);
|
||||
|
||||
} );
|
||||
return;
|
||||
}
|
||||
|
||||
Internal.XHR.sendMessage( self.token, channel_id, {
|
||||
content: message,
|
||||
mentions: mentions
|
||||
|
|
|
|||
|
|
@ -124,6 +124,22 @@ Internal.XHR.sendMessage = function( token, channelID, messageParameters, callba
|
|||
|
||||
}
|
||||
|
||||
Internal.XHR.sendFile = function( token, channelID, file, fileName, callback ) {
|
||||
request
|
||||
.post( Endpoints.CHANNELS + "/" + channelID + "/messages" )
|
||||
.set( "authorization", token )
|
||||
.attach("file", file, fileName)
|
||||
.end( function( err, res ) {
|
||||
|
||||
if ( err ) {
|
||||
callback( err );
|
||||
} else {
|
||||
callback( null, res.body );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
Internal.XHR.deleteMessage = function( token, channelID, messageID, callback ) {
|
||||
request
|
||||
.del( Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID )
|
||||
|
|
|
|||
Loading…
Reference in a new issue