mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
Merge branch 'master' into hydrabot
This commit is contained in:
20
index.js
20
index.js
@@ -9,6 +9,10 @@ var Invite = require( "./lib/invite.js" ).Invite;
|
|||||||
var PMChannel = require( "./lib/PMChannel.js" ).PMChannel;
|
var PMChannel = require( "./lib/PMChannel.js" ).PMChannel;
|
||||||
var WebSocket = require( 'ws' );
|
var WebSocket = require( 'ws' );
|
||||||
|
|
||||||
|
exports.prototype.isUserID = function(id){
|
||||||
|
return ((id + "").length === 17 && !isNaN(id));
|
||||||
|
}
|
||||||
|
|
||||||
exports.Client = function( options ) {
|
exports.Client = function( options ) {
|
||||||
|
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
@@ -25,7 +29,7 @@ exports.Client = function( options ) {
|
|||||||
|
|
||||||
exports.Client.prototype.triggerEvent = function( event, args ) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +62,7 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
|||||||
.set( "authorization", this.token )
|
.set( "authorization", this.token )
|
||||||
.end( function( err, res ) {
|
.end( function( err, res ) {
|
||||||
var dat = res.body;
|
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
|
request
|
||||||
.get( Endpoints.SERVERS + "/" + id + "/channels" )
|
.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 ) {
|
exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||||
|
|
||||||
var client = this;
|
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 )
|
if ( !message )
|
||||||
return false;
|
return false;
|
||||||
@@ -460,7 +472,7 @@ exports.Client.prototype.deleteMessage = function( message ) {
|
|||||||
request
|
request
|
||||||
.del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id )
|
.del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id )
|
||||||
.set( "authorization", client.token )
|
.set( "authorization", client.token )
|
||||||
.end( function( err, res ) {} );
|
.end( cb );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.channelFromId = function( id ) {
|
exports.Client.prototype.channelFromId = function( id ) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var User = require( "./user.js" ).User;
|
var User = require( "./user.js" ).User;
|
||||||
var List = require( "./list.js" ).List;
|
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.region = region;
|
||||||
this.ownerID = ownerID;
|
this.ownerID = ownerID;
|
||||||
@@ -8,14 +8,32 @@ exports.Server = function( region, ownerID, name, id, members ) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.members = new List( "id" );
|
this.members = new List( "id" );
|
||||||
this.channels = new List( "id" );
|
this.channels = new List( "id" );
|
||||||
|
this.icon = icon;
|
||||||
|
this.afkTimeout = afkTimeout;
|
||||||
|
this.afkChannelId = afkChannelId;
|
||||||
|
|
||||||
for ( x in members ) {
|
for ( x in members ) {
|
||||||
var member = members[ x ].user;
|
var member = members[ x ].user;
|
||||||
this.members.add( new User( member ) );
|
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() {
|
exports.Server.prototype.getDefaultChannel = function() {
|
||||||
|
|
||||||
return this.channels.filter( "name", "general", true );
|
return this.channels.filter( "name", "general", true );
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ exports.User = function(username, id, discriminator, avatar){
|
|||||||
this.avatar = 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(){
|
exports.User.prototype.mention = function(){
|
||||||
return "<@"+this.id+">";
|
return "<@"+this.id+">";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user