diff --git a/src/bot/skin/discord-command.ts b/src/bot/skin/discord-command.ts deleted file mode 100644 index b999129..0000000 --- a/src/bot/skin/discord-command.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { - ApplicationCommand, - ApplicationCommandOption, - ApplicationCommandOptionType, -} from "../abst/command"; -import { DiscordId } from "../exp/discord-id"; -import { MessageEmbed } from "discord.js"; - -export interface InteractionDataOption { - name: string; - type: ApplicationCommandOptionType; - value?: string; - options?: readonly InteractionDataOption[]; -} - -export interface InteractionData { - id: string; - name: string; - resolved?: string; - options?: readonly InteractionDataOption[]; -} - -export interface Interaction { - type: "1" | "2"; - token: string; - data: InteractionData; -} - -export class DiscordCommand implements ApplicationCommand { - constructor(private readonly interaction: Interaction) {} - - get name(): string { - throw new Error("Method not implemented."); - } - - get description(): string { - throw new Error("Method not implemented."); - } - - get options(): ApplicationCommandOption[] { - throw new Error("Method not implemented."); - } - - getAuthorId(): DiscordId { - throw new Error("Method not implemented."); - } - - matchCommand(regex: RegExp): Promise { - throw new Error("Method not implemented."); - } - - reply(message: string): Promise { - throw new Error("Method not implemented."); - } - - sendEmbed(embed: MessageEmbed): Promise { - throw new Error("Method not implemented."); - } - - panic(reason: unknown): never { - throw new Error("Method not implemented."); - } -} diff --git a/src/bot/skin/interactions-command.ts b/src/bot/skin/interactions-command.ts index 5498876..02fcd53 100644 --- a/src/bot/skin/interactions-command.ts +++ b/src/bot/skin/interactions-command.ts @@ -58,6 +58,8 @@ const prCommand: ApplicationCommand = { const commands = [repositoryCommand, branchCommand, issueCommand, prCommand]; +const GUILD_ID = "683939861539192860"; + export type Handler = (message: Message) => Promise; export class InteractionsCommandReceiver { @@ -67,16 +69,23 @@ export class InteractionsCommandReceiver { return; } this.initialized = true; - const registrar = client.guilds.cache.get("683939861539192860")?.commands; + const registrar = client.guilds.cache.get(GUILD_ID)?.commands; if (!registrar) { return; } + const oldCommands = await registrar.fetch(); + await Promise.all( + [...oldCommands.values()].map((com) => registrar.delete(com)), + ); await Promise.all(commands.map((command) => registrar.create(command))); }); client.on("interactionCreate", (interaction) => { if (!interaction.isCommand()) { return; } + if (interaction.guildId !== GUILD_ID) { + return; + } this.onCommand(interaction); }); } @@ -123,14 +132,28 @@ export class InteractionsCommandReceiver { private buildCommandStr(interaction: CommandInteraction): string { let commandStr = `/${interaction.commandName} `; - commandStr += interaction.options.data - .filter(({ name }) => name !== "branch") - .map(({ value }) => value) - .join("/"); - commandStr += interaction.options.data - .filter(({ name }) => name === "branch") - .map(({ value }) => value) - .join(" "); + const [orgArg] = interaction.options.data.filter( + ({ name }) => name === "org", + ); + if (orgArg) { + commandStr += `${orgArg.value}/`; + } + const [repoArg] = interaction.options.data.filter( + ({ name }) => name === "repo", + ); + commandStr += repoArg.value; + const [issueArg] = interaction.options.data.filter( + ({ name }) => name === "issue", + ); + if (issueArg) { + commandStr += `/${issueArg.value}`; + } + const [branchArg] = interaction.options.data.filter( + ({ name }) => name === "branch", + ); + if (branchArg) { + commandStr += ` ${branchArg.value}`; + } return commandStr; } }