From e4723c7dfe23acbe2480d465a8c989f8c9c1d727 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 14 Aug 2015 11:48:44 +0100 Subject: [PATCH 1/3] Added more properties to the server --- index.js | 12 ++++++++++-- lib/server.js | 20 +++++++++++++++++++- lib/user.js | 6 ++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index cf4c2abbc..f3ea47f2a 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ exports.Client = function( options ) { exports.Client.prototype.triggerEvent = function( event, args ) { - if ( !this.ready ) { //if we're not even loaded yet, don't try doing anything because it always ends badly! + if ( !this.ready && event !== "raw" ) { //if we're not even loaded yet, don't try doing anything because it always ends badly! return; } @@ -58,7 +58,7 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) { .set( "authorization", this.token ) .end( function( err, res ) { var dat = res.body; - var server = new Server( dat.region, dat.owner_id, dat.name, dat.roles[ 0 ].id, members || dat.members ); + var server = new Server( dat.region, dat.owner_id, dat.name, dat.roles[ 0 ].id, members || dat.members, dat.icon, dat.afk_timeout, dat.afk_channel_id ); request .get( Endpoints.SERVERS + "/" + id + "/channels" ) @@ -105,6 +105,14 @@ exports.Client.prototype.login = function( email, password ) { } +exports.Client.prototype.reply = function(){ + + arguments[1] = arguments[0].author.mention() + ", " + arguments[1]; + + this.sendMessage.apply(this, arguments); + +} + exports.Client.prototype.connectWebsocket = function( cb ) { var client = this; diff --git a/lib/server.js b/lib/server.js index 44b57f6d9..5f0c231f5 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,6 +1,6 @@ var User = require( "./user.js" ).User; var List = require( "./list.js" ).List; -exports.Server = function( region, ownerID, name, id, members ) { +exports.Server = function( region, ownerID, name, id, members, icon, afkTimeout, afkChannelId ) { this.region = region; this.ownerID = ownerID; @@ -8,14 +8,32 @@ exports.Server = function( region, ownerID, name, id, members ) { this.id = id; this.members = new List( "id" ); this.channels = new List( "id" ); + this.icon = icon; + this.afkTimeout = afkTimeout; + this.afkChannelId = afkChannelId; for ( x in members ) { var member = members[ x ].user; this.members.add( new User( member ) ); } +} + +exports.Server.prototype.getIconURL = function(){ + if(!this.icon) + return false; + return "https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg"; +} + +exports.Server.prototype.getAFKChannel = function(){ + + if(!this.afkChannelId) + return false; + + return this.channels.filter("id", this.afkChannelId, true); } + exports.Server.prototype.getDefaultChannel = function() { return this.channels.filter( "name", "general", true ); diff --git a/lib/user.js b/lib/user.js index 3a9564529..3de727332 100644 --- a/lib/user.js +++ b/lib/user.js @@ -14,6 +14,12 @@ exports.User = function(username, id, discriminator, avatar){ this.avatar = avatar; } +exports.User.prototype.getAvatarURL = function(){ + if(!this.avatar) + return false; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; +} + exports.User.prototype.mention = function(){ return "<@"+this.id+">"; } From a0d4fa930c4f7e2157b540b2b401f3faf735c2b6 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 14 Aug 2015 12:33:46 +0100 Subject: [PATCH 2/3] Caching Server now gets actual ID --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f3ea47f2a..c9edda165 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) { .set( "authorization", this.token ) .end( function( err, res ) { var dat = res.body; - var server = new Server( dat.region, dat.owner_id, dat.name, dat.roles[ 0 ].id, members || dat.members, dat.icon, dat.afk_timeout, dat.afk_channel_id ); + var server = new Server( dat.region, dat.owner_id, dat.name, id, members || dat.members, dat.icon, dat.afk_timeout, dat.afk_channel_id ); request .get( Endpoints.SERVERS + "/" + id + "/channels" ) @@ -458,7 +458,7 @@ exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions } -exports.Client.prototype.deleteMessage = function( message ) { +exports.Client.prototype.deleteMessage = function( message, cb ) { if ( !message ) return false; @@ -468,7 +468,7 @@ exports.Client.prototype.deleteMessage = function( message ) { request .del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id ) .set( "authorization", client.token ) - .end( function( err, res ) {} ); + .end( cb ); } exports.Client.prototype.channelFromId = function( id ) { From a6bcb7befb503764ce1a77cbb5fa820cb962f1dc Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 14 Aug 2015 12:38:49 +0100 Subject: [PATCH 3/3] Added method to test whether string is ID --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index c9edda165..a4cfc21a8 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,10 @@ var Invite = require( "./lib/invite.js" ).Invite; var PMChannel = require( "./lib/PMChannel.js" ).PMChannel; var WebSocket = require( 'ws' ); +exports.prototype.isUserID = function(id){ + return ((id + "").length === 17 && !isNaN(id)); +} + exports.Client = function( options ) { this.options = options || {};