diff --git a/src/commands/tags.ts b/src/commands/tags.ts index 6e9aba9..e7a1927 100644 --- a/src/commands/tags.ts +++ b/src/commands/tags.ts @@ -1,6 +1,6 @@ import { APIApplicationCommandInteractionDataStringOption, ApplicationCommandOptionType, InteractionResponseType, MessageFlags } from 'discord-api-types/v10'; import { Command } from '../structures/Command'; -import { findTags, getTag } from '../utils/tagsUtils'; +import { findTags, getTag, Tag } from '../utils/tagsUtils'; new Command({ name: 'tags', @@ -26,7 +26,7 @@ new Command({ const query: APIApplicationCommandInteractionDataStringOption = ctx.options[0] as APIApplicationCommandInteractionDataStringOption; const target = ctx?.resolved?.users ? Object.values(ctx?.resolved?.users)[0] : null; - const tag = getTag(query.value); + const tag = getTag(query.value, false); if (!tag) return ctx.respond({ type: InteractionResponseType.ChannelMessageWithSource, diff --git a/src/utils/tagsUtils.ts b/src/utils/tagsUtils.ts index 241c1c8..1ddb2ba 100644 --- a/src/utils/tagsUtils.ts +++ b/src/utils/tagsUtils.ts @@ -13,13 +13,13 @@ for (const [key, value] of Object.entries(tags)) { tagCache.set(key, value as unknown as Tag); } -export const getTag = (name: string, more?: boolean) => { +export const getTag = (name: string, more?: T): T extends true ? Tag[] : Tag => { if (more) { const tags = [...tagCache.filter(tag => tag.keywords.some(k => k.includes(name))).values()]; - return tags; + return tags as T extends true ? Tag[] : Tag; } else { const tag = tagCache.get(name) || tagCache.find(tag => tag.keywords.some(k => k.includes(name))); - return tag; + return tag as T extends true ? Tag[] : Tag; } } @@ -32,7 +32,7 @@ export const findTags = (name: string) => { })).slice(0, 25) ]; else { - const tags: Tag[] = getTag(name, true) as Tag[]; + const tags = getTag(name, true); if (tags.length > 0) return tags.map(tag => new Object({ name: tag.keywords[0],