feat(docs): add target + mention user

This commit is contained in:
Jozef Steinhübl 2023-08-24 23:01:54 +02:00
parent c60793dbff
commit d2ef2e9050

View file

@ -1,4 +1,4 @@
import { SlashCommandStringOption } from "discord.js"; import { SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
import { defineCommand } from "../loaders/commands"; import { defineCommand } from "../loaders/commands";
import { AutocompleteContext } from "../structs/context/AutocompleteContext"; import { AutocompleteContext } from "../structs/context/AutocompleteContext";
import { InteractionCommandContext } from "../structs/context/CommandContext"; import { InteractionCommandContext } from "../structs/context/CommandContext";
@ -34,15 +34,21 @@ defineCommand({
} }
}) })
); );
} },
},
{
...new SlashCommandUserOption()
.setName("target")
.setRequired(false)
.setDescription("User to mention")
.toJSON()
} }
], ],
run: async(context: InteractionCommandContext) => { run: async(context: InteractionCommandContext) => {
await context.interaction.deferReply({ await context.interaction.deferReply();
ephemeral: true,
});
const query = context.interaction.options.getString("query"); const query = context.interaction.options.getString("query");
const target = context.interaction.options.getUser("target");
const result = await algoliaIndex.search(query, { const result = await algoliaIndex.search(query, {
hitsPerPage: 1, hitsPerPage: 1,
@ -58,13 +64,19 @@ defineCommand({
const notice = hit.content?.replace(/\r/g, ""); const notice = hit.content?.replace(/\r/g, "");
const content = [ const content = [
target ? `*Suggestion for <@${target.id}>:*\n` : "",
`[*${name.full}*](<${url}>)`, `[*${name.full}*](<${url}>)`,
snippetContent ? snippetContent : "", snippetContent ? snippetContent : "",
notice ? notice.split("\n").map(s => `> ${s}`).join("\n") : "" notice ? notice.split("\n").map(s => `> ${s}`).join("\n") : ""
].join("\n") ].join("\n")
await context.interaction.editReply({
await context.interaction.editReply(content); content,
allowedMentions: {
parse: [ "users" ],
repliedUser: true,
}
});
} }
}) })