From 13b404bffd7c4b1d8d8b174bd21541342a856993 Mon Sep 17 00:00:00 2001 From: Navy Date: Sun, 26 Jul 2020 23:09:54 +0300 Subject: [PATCH] components by tag --- structure/client/Resolver.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/structure/client/Resolver.js b/structure/client/Resolver.js index 12b5525..d3cd092 100644 --- a/structure/client/Resolver.js +++ b/structure/client/Resolver.js @@ -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))); \ No newline at end of file + 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()))); \ No newline at end of file