mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 14:41:05 +01:00
feat: allow more tags in findTags
This commit is contained in:
parent
f69c0b97f1
commit
119d8dee7b
1 changed files with 14 additions and 11 deletions
|
@ -13,10 +13,15 @@ for (const [key, value] of Object.entries(tags)) {
|
|||
tagCache.set(key, value as unknown as Tag);
|
||||
}
|
||||
|
||||
export const getTag = (name: string) => {
|
||||
export const getTag = (name: string, more?: boolean) => {
|
||||
if (more) {
|
||||
const tags = [...tagCache.filter(tag => tag.keywords.some(k => k.includes(name))).values()];
|
||||
return tags;
|
||||
} else {
|
||||
const tag = tagCache.get(name) || tagCache.find(tag => tag.keywords.some(k => k.includes(name)));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
export const findTags = (name: string) => {
|
||||
if (!name)
|
||||
|
@ -27,14 +32,12 @@ export const findTags = (name: string) => {
|
|||
})).slice(0, 25)
|
||||
];
|
||||
else {
|
||||
const tag = getTag(name);
|
||||
if (tag)
|
||||
return [
|
||||
{
|
||||
const tags: Tag[] = getTag(name, true) as Tag[];
|
||||
if (tags.length > 0)
|
||||
return tags.map(tag => new Object({
|
||||
name: tag.keywords[0],
|
||||
value: tag.keywords[0],
|
||||
}
|
||||
];
|
||||
value: tag.keywords[0]
|
||||
}));
|
||||
else return findTags(null);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue