Skip to content

Commit

Permalink
Fix stability when bad command is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
pattyjogal committed Sep 20, 2021
1 parent e29c1e6 commit c62a798
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/commands/tenmans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SubcommandTenmansStart extends MessageExecutable<CommandInteraction> {
time = this.interaction.options.getString("time");
tenmansQueue = [];
const queueChannel = this.interaction.guild.channels.cache.get(
"725570244256464896"
"885704092142428200"
) as TextChannel;

const queueId = "stub";
Expand All @@ -118,6 +118,14 @@ export async function cmd_tenmans(interaction, db: Db) {

// Wrap function call to pass same args to all methods
const Action = commands[interaction.options.getSubcommand()];
if (Action === undefined) {
console.error("Bad action:", interaction.options.getSubcommand());
interaction.reply({
ephemeral: true,
content: "Error logged; please tell an admin what you were trying to do"
});
return;
}
const command = new Action(interaction, db);
command.execute();
}
Expand All @@ -138,6 +146,14 @@ export async function handleButton(interaction: ButtonInteraction, db: Db) {
const actionParts = interaction.customId.split(".");
const [commandName, queueId] = actionParts[actionParts.length - 1].split(":");
const Action = commands[commandName];
if (Action === undefined) {
console.error("Bad action:", interaction.customId);
interaction.reply({
ephemeral: true,
content: "Error logged; please tell an admin what you were trying to do"
});
return;
}
const command = new Action(interaction, db, queueId);
command.execute();
}
Expand Down

0 comments on commit c62a798

Please sign in to comment.