Merge pull request #4 from hydrabolt/indev

Minor improvements that should benefit quite a bit
This commit is contained in:
hydrabolt
2015-08-14 12:50:48 +01:00
3 changed files with 41 additions and 5 deletions

View File

@@ -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 || {};
@@ -25,7 +29,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 +62,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, id, members || dat.members, dat.icon, dat.afk_timeout, dat.afk_channel_id );
request
.get( Endpoints.SERVERS + "/" + id + "/channels" )
@@ -105,6 +109,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;
@@ -450,7 +462,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;
@@ -460,7 +472,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 ) {

View File

@@ -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 );

View File

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