components by tag

This commit is contained in:
Erik 2020-07-26 23:09:54 +03:00
parent 47ab29f901
commit 13b404bffd

View File

@ -15,12 +15,12 @@ class Resolver {
* @returns
* @memberof Resolver
*/
components(str = '', type, exact = true) {
components(str = '', type = 'any', exact = true) {
const string = str.toLowerCase();
const components = this.client.registry.components
.filter((c) => c.type === type)
.filter((c) => type === 'any' ? ['command', 'setting'].includes(c.type) : c.type === type)
.filter(exact ? filterExact(string) : filterInexact(string)) //eslint-disable-line no-use-before-define
.array();
@ -28,6 +28,19 @@ class Resolver {
}
componentsByTag(str, type, exact = true) {
const key = str.toLowerCase();
const components = this.client.registry.components
.filter((c) => c.type === type)
.filter(exact ? (c) => c.tags.includes(key) : filterInexactTags(key))
.array();
return components || [];
}
timeAgo(diff, extraMin = false, extraHours = false, extraDays = false) {
diff = parseInt(diff);
@ -500,4 +513,10 @@ const filterExact = (search) => (comp) => comp.id.toLowerCase() === search ||
const filterInexact = (search) => (comp) => comp.id.toLowerCase().includes(search) ||
comp.resolveable.toLowerCase().includes(search) ||
comp.aliases && (comp.aliases.some((ali) => `${comp.type}:${ali}`.toLowerCase().includes(search)) ||
comp.aliases.some((ali) => ali.toLowerCase().includes(search)));
comp.aliases.some((ali) => ali.toLowerCase().includes(search)));
const filterInexactTags = (search) => (comp) => comp.id.toLowerCase().includes(search.toLowerCase()) ||
comp.resolveable.toLowerCase().includes(search.toLowerCase()) ||
comp.aliases && (comp.aliases.some((ali) => `${comp.type}:${ali}`.toLowerCase().includes(search.toLowerCase())) ||
comp.aliases.some((ali) => ali.toLowerCase().includes(search.toLowerCase())) ||
comp.tags.some((tag) => tag.toLowerCase().includes(search.toLowerCase())));