Skip to content

Commit

Permalink
chore(*): remove target option from other user app commands
Browse files Browse the repository at this point in the history
  • Loading branch information
almostSouji committed May 17, 2024
1 parent 5a4ccf3 commit 4cee71a
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 85 deletions.
4 changes: 1 addition & 3 deletions src/functions/algoliaResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export async function algoliaResponse(
algoliaObjectId: string,
emojiId: string,
emojiName: string,
target?: string,
ephemeral?: boolean,
): Promise<Response> {
const full = `http://${algoliaAppId}.${API_BASE_ALGOLIA}/1/indexes/${algoliaIndex}/${encodeURIComponent(
Expand All @@ -43,14 +42,13 @@ export async function algoliaResponse(
: null;

const contentParts = [
target ? `${italic(`Suggestion for ${userMention(target)}:`)}` : null,
`<:${emojiName}:${emojiId}> ${bold(resolveHitToNamestring(hit))}${headlineSuffix ? ` ${headlineSuffix}` : ''}`,
hit.content?.length ? `${truncate(decode(hit.content), 300)}` : null,
docsBody?.lines.length ? docsBody.lines.at(0) : null,
`${hyperlink('read more', hideLinkEmbed(hit.url))}`,
].filter(Boolean) as string[];

prepareResponse(res, contentParts.join('\n'), ephemeral ?? false, target ? [target] : []);
prepareResponse(res, contentParts.join('\n'), ephemeral ?? false);
} catch {
prepareErrorResponse(res, 'Invalid result. Make sure to select an entry from the autocomplete.');
}
Expand Down
9 changes: 2 additions & 7 deletions src/functions/mdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function escape(text: string) {
return text.replaceAll('||', '|\u200B|').replaceAll('*', '\\*');
}

export async function mdnSearch(res: Response, query: string, target?: string, ephemeral?: boolean): Promise<Response> {
export async function mdnSearch(res: Response, query: string, ephemeral?: boolean): Promise<Response> {
const trimmedQuery = query.trim();
try {
const qString = `${API_BASE_MDN}/${trimmedQuery}/index.json`;
Expand Down Expand Up @@ -41,12 +41,7 @@ export async function mdnSearch(res: Response, query: string, target?: string, e
intro,
];

prepareResponse(
res,
`${target ? `${italic(`Documentation suggestion for ${userMention(target)}:`)}\n` : ''}${parts.join('\n')}`,
ephemeral ?? false,
target ? [target] : [],
);
prepareResponse(res, parts.join('\n'), ephemeral ?? false);

return res;
} catch (error) {
Expand Down
8 changes: 1 addition & 7 deletions src/functions/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export async function nodeSearch(
res: Response,
query: string,
version = 'latest-v18.x',
target?: string,
ephemeral?: boolean,
): Promise<Response> {
const trimmedQuery = query.trim();
Expand Down Expand Up @@ -117,12 +116,7 @@ export async function nodeSearch(
.replaceAll(boldCodeBlockRegex, bold(inlineCode('$1'))),
);

prepareResponse(
res,
`${target ? `${italic(`Documentation suggestion for ${userMention(target)}:`)}\n` : ''}${parts.join('\n')}`,
ephemeral ?? false,
target ? [target] : [],
);
prepareResponse(res, parts.join('\n'), ephemeral ?? false);

return res;
} catch (error) {
Expand Down
10 changes: 4 additions & 6 deletions src/functions/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { fetch } from 'undici';
import { REMOTE_TAG_URL, PREFIX_SUCCESS } from '../util/constants.js';
import { logger } from '../util/logger.js';
import { prepareResponse, prepareErrorResponse } from '../util/respond.js';
import { suggestionString } from '../util/suggestionString.js';

export type Tag = {
content: string;
Expand Down Expand Up @@ -49,11 +48,11 @@ export async function loadTags(tagCache: Collection<string, Tag>, remote = false
}
}

export function findTag(tagCache: Collection<string, Tag>, query: string, target?: string): string | null {
export function findTag(tagCache: Collection<string, Tag>, query: string): string | null {
const cleanQuery = query.replaceAll(/\s+/g, '-');
const tag = tagCache.get(cleanQuery) ?? tagCache.find((tag) => tag.keywords.includes(cleanQuery));
if (!tag) return null;
return suggestionString('tag', tag.content, target);
return tag.content;
}

export async function reloadTags(res: Response, tagCache: Collection<string, Tag>, remote = true) {
Expand Down Expand Up @@ -84,13 +83,12 @@ export function showTag(
res: Response,
query: string,
tagCache: Collection<string, Tag>,
target?: string,
ephemeral?: boolean,
): Response {
const trimmedQuery = query.trim().toLowerCase();
const content = findTag(tagCache, trimmedQuery, target);
const content = findTag(tagCache, trimmedQuery);
if (content) {
prepareResponse(res, content, ephemeral ?? false, target ? [target] : []);
prepareResponse(res, content, ephemeral ?? false);
} else {
prepareErrorResponse(res, `Could not find a tag with name or alias similar to \`${trimmedQuery}\`.`);
}
Expand Down
9 changes: 3 additions & 6 deletions src/handling/handleApplicationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export async function handleApplicationCommand(
castArgs.query,
EMOJI_ID_CLYDE_BLURPLE,
'discord',
castArgs.target,
castArgs.hide,
);
break;
Expand All @@ -90,7 +89,6 @@ export async function handleApplicationCommand(
castArgs.query,
EMOJI_ID_DTYPES,
'dtypes',
castArgs.target,
castArgs.hide,
);

Expand All @@ -107,27 +105,26 @@ export async function handleApplicationCommand(
castArgs.query,
EMOJI_ID_GUIDE,
'guide',
castArgs.target,
castArgs.hide,
);
break;
}

case 'mdn': {
const castArgs = args as ArgumentsOf<typeof MdnCommand>;
await mdnSearch(res, castArgs.query, castArgs.target, castArgs.hide);
await mdnSearch(res, castArgs.query, castArgs.hide);
break;
}

case 'node': {
const castArgs = args as ArgumentsOf<typeof NodeCommand>;
await nodeSearch(res, castArgs.query, castArgs.version, castArgs.target, castArgs.hide);
await nodeSearch(res, castArgs.query, castArgs.version, castArgs.hide);
break;
}

case 'tag': {
const castArgs = args as ArgumentsOf<typeof TagCommand>;
showTag(res, castArgs.query, tagCache, castArgs.target, castArgs.hide);
showTag(res, castArgs.query, tagCache, castArgs.hide);
break;
}

Expand Down
6 changes: 0 additions & 6 deletions src/interactions/discorddocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ export const DiscordDocsCommand = {
autocomplete: true,
required: true,
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: 'User to mention',
required: false,
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hide',
Expand Down
7 changes: 0 additions & 7 deletions src/interactions/discordtypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApplicationCommandOptionType } from 'discord-api-types/v10';

const QUERY_DESCRIPTION = 'Type, Enum or Interface to search for' as const;
const TARGET_DESCRIPTION = 'User to mention' as const;
const VERSION_DESCRIPTION = 'Attempts to filter the results to the specified version' as const;
const EPHEMERAL_DESCRIPTION = 'Hide command output' as const;

Expand All @@ -16,12 +15,6 @@ export const DTypesCommand = {
required: true,
autocomplete: true,
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: TARGET_DESCRIPTION,
required: false,
},
{
type: ApplicationCommandOptionType.String,
name: 'version',
Expand Down
6 changes: 0 additions & 6 deletions src/interactions/guide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ export const GuideCommand = {
autocomplete: true,
required: true,
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: 'User to mention',
required: false,
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hide',
Expand Down
6 changes: 0 additions & 6 deletions src/interactions/mdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ export const MdnCommand = {
required: true,
autocomplete: true,
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: 'User to mention',
required: false,
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hide',
Expand Down
6 changes: 0 additions & 6 deletions src/interactions/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export const NodeCommand = {
},
],
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: 'User to mention',
required: false,
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hide',
Expand Down
6 changes: 0 additions & 6 deletions src/interactions/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ export const TagCommand = {
required: true,
autocomplete: true,
},
{
type: ApplicationCommandOptionType.User,
name: 'target',
description: 'User to mention',
required: false,
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'hide',
Expand Down
19 changes: 0 additions & 19 deletions src/util/suggestionString.ts

This file was deleted.

0 comments on commit 4cee71a

Please sign in to comment.