mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 21:43:33 +01:00
2.6.2, added case-insensitive filtering and edit message error catching
This commit is contained in:
@@ -339,6 +339,23 @@ Commands[ "acceptinvite" ] = {
|
||||
}
|
||||
}
|
||||
|
||||
Commands[ "filtertest" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
console.log( message.channel.server.members.filter( "username", "HYDRABOLT" ) );
|
||||
console.log( message.channel.server.members.filter( "username", "HYDRABOLT", false, true ) );
|
||||
}
|
||||
}
|
||||
|
||||
Commands[ "test" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
|
||||
console.log( message.channel.server.channels.filter( "name", "a", true ) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Commands[ "remind" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
|
||||
5
index.js
5
index.js
@@ -448,7 +448,12 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||
data.mention_everyone = data.mention_everyone || formerMessage.everyoneMentioned;
|
||||
data.embeds = data.embeds || formerMessage.embeds;
|
||||
|
||||
try{
|
||||
newMessage = new Message( data, channel );
|
||||
}catch(e){
|
||||
self.debug("dropped a message update packet");
|
||||
return;
|
||||
}
|
||||
|
||||
self.triggerEvent( "messageUpdate", [ formerMessage, newMessage ] );
|
||||
|
||||
|
||||
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