mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Patches
This commit is contained in:
@@ -167,7 +167,8 @@ var Client = (function () {
|
||||
callback(err);
|
||||
reject(err);
|
||||
} else {
|
||||
callback(null);
|
||||
self.state = 4;
|
||||
callback();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
@@ -242,10 +243,9 @@ var Client = (function () {
|
||||
callback(err);
|
||||
reject(err);
|
||||
} else {
|
||||
var srv = self.getServer("id", self.resolveServerID(server));
|
||||
callback(null, srv);
|
||||
resolve(srv);
|
||||
self.serverCache.splice(self.serverCache.indexOf(srv), 1);
|
||||
self.serverCache.splice(self.serverCache.indexOf(server), 1);
|
||||
callback(null);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -781,7 +781,7 @@ var Client = (function () {
|
||||
self.trigger("ready");
|
||||
self.readyTime = Date.now();
|
||||
self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");
|
||||
|
||||
self.state = 3;
|
||||
setInterval(function () {
|
||||
self.keepAlive.apply(self);
|
||||
}, data.heartbeat_interval);
|
||||
@@ -1318,6 +1318,11 @@ var Client = (function () {
|
||||
get: function get() {
|
||||
return this.userCache;
|
||||
}
|
||||
}, {
|
||||
key: "PMChannels",
|
||||
get: function get() {
|
||||
return this.pmChannelCache;
|
||||
}
|
||||
}, {
|
||||
key: "messages",
|
||||
get: function get() {
|
||||
|
||||
@@ -72,6 +72,10 @@ class Client {
|
||||
get users() {
|
||||
return this.userCache;
|
||||
}
|
||||
|
||||
get PMChannels() {
|
||||
return this.pmChannelCache;
|
||||
}
|
||||
|
||||
get messages() {
|
||||
|
||||
@@ -181,7 +185,8 @@ class Client {
|
||||
callback(err);
|
||||
reject(err);
|
||||
} else {
|
||||
callback(null);
|
||||
self.state = 4;
|
||||
callback();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
@@ -266,10 +271,9 @@ class Client {
|
||||
callback(err);
|
||||
reject(err);
|
||||
} else {
|
||||
var srv = self.getServer("id", self.resolveServerID(server));
|
||||
callback(null, srv);
|
||||
resolve(srv);
|
||||
self.serverCache.splice(self.serverCache.indexOf(srv), 1);
|
||||
self.serverCache.splice(self.serverCache.indexOf(server), 1);
|
||||
callback(null);
|
||||
resolve();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -690,7 +694,7 @@ class Client {
|
||||
self.trigger("ready");
|
||||
self.readyTime = Date.now();
|
||||
self.debug(`cached ${self.serverCache.length} servers, ${self.channelCache.length} channels, ${self.pmChannelCache.length} PMs and ${self.userCache.length} users.`);
|
||||
|
||||
self.state = 3;
|
||||
setInterval(function () {
|
||||
self.keepAlive.apply(self);
|
||||
}, data.heartbeat_interval);
|
||||
|
||||
248
src/list.js
248
src/list.js
@@ -1,248 +0,0 @@
|
||||
/**
|
||||
* Similar to a Java set. Contains no duplicate elements and includes filter
|
||||
* functions. Discriminates between elements based on a discriminator passed
|
||||
* when created. Generally "ID"
|
||||
* @class List
|
||||
*/
|
||||
exports.List = function( discriminator, cap ) {
|
||||
/**
|
||||
* What to use to distringuish duplicates
|
||||
* @attribute discriminator
|
||||
* @type {String}
|
||||
*/
|
||||
this.discriminator = discriminator;
|
||||
/**
|
||||
* The maximum amount of elements allowed in the list.
|
||||
* @default Infinity
|
||||
* @attribute cap
|
||||
* @type {Number}
|
||||
*/
|
||||
this.cap = cap || Number.MAX_SAFE_INTEGER;
|
||||
/**
|
||||
* The Array version of the List.
|
||||
* @type {Array}
|
||||
* @attribute contents
|
||||
*/
|
||||
this.contents = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an element to the list if it isn't already there.
|
||||
* @method add
|
||||
* @param {Object/Array} element The element(s) to add
|
||||
* @example
|
||||
* List.add( obj );
|
||||
* List.add( [ obj, obj, obj ] );
|
||||
*/
|
||||
exports.List.prototype.add = function( child ) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if ( child.constructor === Array ) {
|
||||
|
||||
children = child;
|
||||
for ( child of children ) {
|
||||
addChild( child );
|
||||
}
|
||||
|
||||
} else {
|
||||
addChild( child );
|
||||
}
|
||||
|
||||
function addChild( child ) {
|
||||
|
||||
if ( self.length() > self.cap ) {
|
||||
self.splice( 0, 1 );
|
||||
}
|
||||
|
||||
if ( self.filter( self.discriminator, child[ self.discriminator ] ).length() === 0 )
|
||||
self.contents.push( child );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the List
|
||||
* @method length
|
||||
* @return {Number}
|
||||
*/
|
||||
exports.List.prototype.length = function() {
|
||||
return this.contents.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of an element in the List or defaults to false
|
||||
* @param {Object} object The element we want to get the index of
|
||||
* @return {Number/Boolean} The index if the object is in the list, or false.
|
||||
* @method getIndex
|
||||
*/
|
||||
exports.List.prototype.getIndex = function( object ) {
|
||||
|
||||
var index = false;
|
||||
|
||||
for ( elementIndex in this.contents ) {
|
||||
var element = this.contents[ elementIndex ];
|
||||
if ( element[ this.discriminator ] == object[ this.discriminator ] ) {
|
||||
return elementIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element at the specified index
|
||||
* @param {Number} index
|
||||
* @method removeIndex
|
||||
*/
|
||||
exports.List.prototype.removeIndex = function( index ) {
|
||||
this.contents.splice( index, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element from the list
|
||||
* @param {Object} element
|
||||
* @method removeElement
|
||||
* @return {Boolean} whether the operation was successful or not.
|
||||
*/
|
||||
exports.List.prototype.removeElement = function( child ) {
|
||||
|
||||
for ( _element in this.contents ) {
|
||||
var element = this.contents[ _element ];
|
||||
if ( child[ this.discriminator ] == element[ this.discriminator ] ) {
|
||||
this.removeIndex( _element, 1 );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces an element in the list with a specified element
|
||||
* @method updateElement
|
||||
* @param {Object} element Element to update.
|
||||
* @param {Object} newElement New Element
|
||||
* @return {Boolean} whether the operation was successful or not.
|
||||
*/
|
||||
exports.List.prototype.updateElement = function( child, newChild ) {
|
||||
|
||||
for ( _element in this.contents ) {
|
||||
var element = this.contents[ _element ];
|
||||
if ( child[ this.discriminator ] == element[ this.discriminator ] ) {
|
||||
this.contents[ _element ] = newChild;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
exports.List.prototype.concatSublists = function( whereList, discriminator ) {
|
||||
//this is meant to look at the contents, and assuming the contents are all lists, concatenate their values.
|
||||
|
||||
var concatList = new exports.List( discriminator );
|
||||
|
||||
for ( item of this.contents ) {
|
||||
var itemList = item[ whereList ];
|
||||
concatList.add( itemList.contents );
|
||||
}
|
||||
|
||||
return concatList;
|
||||
}
|
||||
|
||||
exports.List.prototype.filter = function( key, value, onlyOne, caseInsen ) {
|
||||
|
||||
var results = [];
|
||||
|
||||
value = change( value );
|
||||
|
||||
for ( index in this.contents ) {
|
||||
var child = this.contents[ index ];
|
||||
if ( change( child[ key ] ) == value ) {
|
||||
if ( onlyOne ) {
|
||||
return child;
|
||||
} else {
|
||||
results.push( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function change( val ) {
|
||||
if ( caseInsen ) {
|
||||
val = val.toUpperCase();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
if ( onlyOne ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var retList = new exports.List( this.discriminator );
|
||||
retList.contents = results;
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
exports.List.prototype.getValues = function( key ){
|
||||
|
||||
var valList = [];
|
||||
for( child of this.contents){
|
||||
valList.push( child[key] );
|
||||
}
|
||||
return valList;
|
||||
|
||||
}
|
||||
|
||||
exports.List.prototype.deepFilter = function( keys, value, onlyOne, caseInsen ) {
|
||||
|
||||
var results = [];
|
||||
|
||||
value = change( value );
|
||||
|
||||
for ( index in this.contents ) {
|
||||
var child = this.contents[ index ];
|
||||
var buffer = child;
|
||||
|
||||
for ( key of keys ) {
|
||||
if(buffer instanceof exports.List){
|
||||
buffer = buffer.contents;
|
||||
}
|
||||
if(buffer instanceof Array){
|
||||
for(elem of buffer){
|
||||
if( change(elem[key]) == value ){
|
||||
buffer = elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer = buffer[ key ];
|
||||
}
|
||||
|
||||
if ( change( buffer ) == value ) {
|
||||
if ( onlyOne ) {
|
||||
return child;
|
||||
} else {
|
||||
results.push( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function change( val ) {
|
||||
if ( caseInsen ) {
|
||||
val = val.toUpperCase();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
if ( onlyOne ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var retList = new exports.List( this.discriminator );
|
||||
retList.contents = results;
|
||||
|
||||
return retList;
|
||||
}
|
||||
Reference in New Issue
Block a user