mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 05:45:02 +00:00
fix: interaction error handling
This commit is contained in:
parent
7f2f2c8f98
commit
8fcbd50ea1
6 changed files with 217 additions and 155 deletions
|
@ -34,13 +34,17 @@ async function banAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasBanPermission(executingMember, interaction.channelId))) {
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,7 +55,9 @@ async function banAction(
|
|||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||
const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs);
|
||||
if (result.status === "failed") {
|
||||
await interactionToReply.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -61,7 +67,9 @@ async function banAction(
|
|||
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
|
||||
} (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interactionToReply.editReply({ content: banMessage, embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: banMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
}
|
||||
|
||||
export async function launchBanActionModal(
|
||||
|
@ -90,9 +98,11 @@ export async function launchBanActionModal(
|
|||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate();
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
|
||||
}
|
||||
|
||||
const duration = submitted.fields.getTextInputValue("duration");
|
||||
|
|
|
@ -19,16 +19,20 @@ export async function cleanAction(
|
|||
const utility = pluginData.getPlugin(UtilityPlugin);
|
||||
|
||||
if (!userCfg.can_use || !(await utility.hasPermission(executingMember, interaction.channelId, "can_clean"))) {
|
||||
await interaction.editReply({ content: "Cannot clean: insufficient permissions", embeds: [], components: [] });
|
||||
await interaction
|
||||
.editReply({ content: "Cannot clean: insufficient permissions", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Clean interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Implement message cleaning
|
||||
await interaction.editReply({
|
||||
content: `TODO: Implementation incomplete`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interaction
|
||||
.editReply({
|
||||
content: `TODO: Implementation incomplete`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Clean interaction reply failed: ${err}`));
|
||||
}
|
||||
|
||||
export async function launchCleanActionModal(
|
||||
|
@ -46,11 +50,13 @@ export async function launchCleanActionModal(
|
|||
await interaction
|
||||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
await submitted.deferUpdate();
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Clean interaction defer failed: ${err}`));
|
||||
|
||||
const amount = submitted.fields.getTextInputValue("amount");
|
||||
if (isNaN(Number(amount))) {
|
||||
interaction.editReply({ content: `Error: Amount '${amount}' is invalid`, embeds: [], components: [] });
|
||||
interaction
|
||||
.editReply({ content: `Error: Amount '${amount}' is invalid`, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Clean interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,21 +37,25 @@ async function muteAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasMutePermission(executingMember, interaction.channelId))) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,13 +73,17 @@ async function muteAction(
|
|||
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
|
||||
} (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: muteMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
} catch (e) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Plugin error, please check your BOT_ALERTs",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Plugin error, please check your BOT_ALERTs",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
|
||||
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
|
@ -113,9 +121,11 @@ export async function launchMuteActionModal(
|
|||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate();
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Mute interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Mute interaction defer failed: ${err}`));
|
||||
}
|
||||
|
||||
const duration = submitted.fields.getTextInputValue("duration");
|
||||
|
|
|
@ -34,21 +34,25 @@ async function noteAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasNotePermission(executingMember, interaction.channelId))) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -68,11 +72,13 @@ async function noteAction(
|
|||
});
|
||||
|
||||
const userName = renderUserUsername(targetMember.user);
|
||||
await interactionToReply.editReply({
|
||||
content: `Note added on **${userName}** (Case #${createdCase.case_number})`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: `Note added on **${userName}** (Case #${createdCase.case_number})`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
}
|
||||
|
||||
export async function launchNoteActionModal(
|
||||
|
@ -91,9 +97,11 @@ export async function launchNoteActionModal(
|
|||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate();
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Note interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Note interaction defer failed: ${err}`));
|
||||
}
|
||||
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
|
|
@ -32,21 +32,25 @@ async function warnAction(
|
|||
|
||||
const modactions = pluginData.getPlugin(ModActionsPlugin);
|
||||
if (!userCfg.can_use || !(await modactions.hasWarnPermission(executingMember, interaction.channelId))) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,7 +60,9 @@ async function warnAction(
|
|||
|
||||
const result = await modactions.warnMember(targetMember, reason, { caseArgs });
|
||||
if (result.status === "failed") {
|
||||
await interactionToReply.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -64,7 +70,9 @@ async function warnAction(
|
|||
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
|
||||
const muteMessage = `Warned **${userName}** (Case #${result.case.case_number})${messageResultText}`;
|
||||
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
await interactionToReply
|
||||
.editReply({ content: muteMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
}
|
||||
|
||||
export async function launchWarnActionModal(
|
||||
|
@ -83,14 +91,16 @@ export async function launchWarnActionModal(
|
|||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate();
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
|
||||
}
|
||||
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
||||
await warnAction(pluginData, reason, target, interaction, submitted);
|
||||
})
|
||||
.catch((err) => logger.error(`Mute modal interaction failed: ${err}`));
|
||||
.catch((err) => logger.error(`Warn modal interaction failed: ${err}`));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue