mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
2.6.2, added case-insensitive filtering and edit message error catching
This commit is contained in:
22
lib/list.js
22
lib/list.js
@@ -153,13 +153,14 @@ exports.List.prototype.concatSublists = function( whereList, discriminator ) {
|
||||
return concatList;
|
||||
}
|
||||
|
||||
exports.List.prototype.filter = function( key, value, onlyOne ) {
|
||||
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 ( child[ key ] == value ) {
|
||||
if ( change(child[ key ]) == value ) {
|
||||
if ( onlyOne ) {
|
||||
return child;
|
||||
} else {
|
||||
@@ -168,6 +169,13 @@ exports.List.prototype.filter = function( key, value, onlyOne ) {
|
||||
}
|
||||
}
|
||||
|
||||
function change(val){
|
||||
if(caseInsen){
|
||||
val = val.toUpperCase();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
if ( onlyOne ) {
|
||||
return false;
|
||||
}
|
||||
@@ -178,6 +186,7 @@ exports.List.prototype.filter = function( key, value, onlyOne ) {
|
||||
exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
|
||||
|
||||
var results = [];
|
||||
value = change(value);
|
||||
|
||||
for ( index in this.contents ) {
|
||||
var child = this.contents[ index ];
|
||||
@@ -187,7 +196,7 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
|
||||
buffer = buffer[ key ];
|
||||
}
|
||||
|
||||
if ( buffer == value ) {
|
||||
if ( change(buffer) == value ) {
|
||||
if ( onlyOne ) {
|
||||
return child;
|
||||
} else {
|
||||
@@ -196,6 +205,13 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
|
||||
}
|
||||
}
|
||||
|
||||
function change(val){
|
||||
if(caseInsen){
|
||||
val = val.toUpperCase();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
if ( onlyOne ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user