Skip to content

Commit bc3e8d3

Browse files
authored
Slash Command のバグ修正 (#35)
* fix: Fix buildCommandStr * fix: Extract hardcode and Add gurad * fix: Fix to remove old commands * refactor: Remove unused class
1 parent f939156 commit bc3e8d3

2 files changed

Lines changed: 32 additions & 72 deletions

File tree

src/bot/skin/discord-command.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/bot/skin/interactions-command.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const prCommand: ApplicationCommand = {
5858

5959
const commands = [repositoryCommand, branchCommand, issueCommand, prCommand];
6060

61+
const GUILD_ID = "683939861539192860";
62+
6163
export type Handler = (message: Message) => Promise<void>;
6264

6365
export class InteractionsCommandReceiver {
@@ -67,16 +69,23 @@ export class InteractionsCommandReceiver {
6769
return;
6870
}
6971
this.initialized = true;
70-
const registrar = client.guilds.cache.get("683939861539192860")?.commands;
72+
const registrar = client.guilds.cache.get(GUILD_ID)?.commands;
7173
if (!registrar) {
7274
return;
7375
}
76+
const oldCommands = await registrar.fetch();
77+
await Promise.all(
78+
[...oldCommands.values()].map((com) => registrar.delete(com)),
79+
);
7480
await Promise.all(commands.map((command) => registrar.create(command)));
7581
});
7682
client.on("interactionCreate", (interaction) => {
7783
if (!interaction.isCommand()) {
7884
return;
7985
}
86+
if (interaction.guildId !== GUILD_ID) {
87+
return;
88+
}
8089
this.onCommand(interaction);
8190
});
8291
}
@@ -123,14 +132,28 @@ export class InteractionsCommandReceiver {
123132

124133
private buildCommandStr(interaction: CommandInteraction): string {
125134
let commandStr = `/${interaction.commandName} `;
126-
commandStr += interaction.options.data
127-
.filter(({ name }) => name !== "branch")
128-
.map(({ value }) => value)
129-
.join("/");
130-
commandStr += interaction.options.data
131-
.filter(({ name }) => name === "branch")
132-
.map(({ value }) => value)
133-
.join(" ");
135+
const [orgArg] = interaction.options.data.filter(
136+
({ name }) => name === "org",
137+
);
138+
if (orgArg) {
139+
commandStr += `${orgArg.value}/`;
140+
}
141+
const [repoArg] = interaction.options.data.filter(
142+
({ name }) => name === "repo",
143+
);
144+
commandStr += repoArg.value;
145+
const [issueArg] = interaction.options.data.filter(
146+
({ name }) => name === "issue",
147+
);
148+
if (issueArg) {
149+
commandStr += `/${issueArg.value}`;
150+
}
151+
const [branchArg] = interaction.options.data.filter(
152+
({ name }) => name === "branch",
153+
);
154+
if (branchArg) {
155+
commandStr += ` ${branchArg.value}`;
156+
}
134157
return commandStr;
135158
}
136159
}

0 commit comments

Comments
 (0)