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+">"; }