3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 13:55:03 +00:00

fix: interaction error handling

This commit is contained in:
Obliie 2023-07-16 00:38:35 +01:00
parent 7f2f2c8f98
commit 8fcbd50ea1
No known key found for this signature in database
GPG key ID: 9189A18F0D5B547E
6 changed files with 217 additions and 155 deletions

View file

@ -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");