mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
fix the derp
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -44,6 +44,21 @@ class Collection extends Map {
|
|||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the items in this collection have a delete method (e.g. messages), invoke
|
||||||
|
* the delete method. Returns an array of promises
|
||||||
|
* @return {Array<Promise>}
|
||||||
|
*/
|
||||||
|
deleteAll() {
|
||||||
|
const returns = [];
|
||||||
|
for (const item of this.array()) {
|
||||||
|
if (item.delete) {
|
||||||
|
returns.push(item.delete());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returns;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The length (size) of this collection.
|
* The length (size) of this collection.
|
||||||
* @readonly
|
* @readonly
|
||||||
@@ -105,6 +120,22 @@ class Collection extends Map {
|
|||||||
_arrayMethod(method, args) {
|
_arrayMethod(method, args) {
|
||||||
return Array.prototype[method].apply(this.array(), args);
|
return Array.prototype[method].apply(this.array(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identical to [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
|
||||||
|
* but returns a Collection instead of an Array.
|
||||||
|
* @param {Function} callback the callback used to filter
|
||||||
|
* @param {Object} [thisArg] value to set as this when filtering
|
||||||
|
* @returns {Collection}
|
||||||
|
*/
|
||||||
|
filter(...args) {
|
||||||
|
const newArray = this.array().filter(...args);
|
||||||
|
const collection = new Collection();
|
||||||
|
for (const item of newArray) {
|
||||||
|
collection.set(item.id, item);
|
||||||
|
}
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Collection;
|
module.exports = Collection;
|
||||||
|
|||||||
Reference in New Issue
Block a user