fix: tag typings

This commit is contained in:
xHyroM 2022-07-13 08:11:59 +02:00
parent c310a8ca42
commit a86d702006
2 changed files with 6 additions and 6 deletions

View file

@ -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,

View file

@ -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 = <T extends boolean>(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],