mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 05:45:02 +00:00
Fixes, refactoring and PR feedback
This commit is contained in:
parent
0be54912c4
commit
893a77d562
202 changed files with 1037 additions and 1069 deletions
|
@ -9,8 +9,8 @@ import {
|
|||
} from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { canActOn } from "src/pluginUtils";
|
||||
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
|
||||
import { canActOn } from "../../../pluginUtils";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { logger } from "../../../logger";
|
||||
import { convertDelayStringToMS, renderUserUsername } from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
|
@ -36,17 +36,13 @@ 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: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply
|
||||
.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: "Cannot ban: insufficient permissions", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,9 +53,7 @@ async function banAction(
|
|||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||
const result = await modactions.banUserId(target, reason, reason, { caseArgs }, durationMs);
|
||||
if (result.status === "failed") {
|
||||
await interactionToReply
|
||||
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -73,9 +67,7 @@ async function banAction(
|
|||
await updateAction(pluginData, executingMember, result.case, evidence);
|
||||
}
|
||||
|
||||
await interactionToReply
|
||||
.editReply({ content: banMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Ban interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: banMessage, embeds: [], components: [] });
|
||||
}
|
||||
|
||||
export async function launchBanActionModal(
|
||||
|
@ -112,9 +104,7 @@ export async function launchBanActionModal(
|
|||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Ban interaction defer failed: ${err}`));
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
}
|
||||
|
||||
const duration = submitted.fields.getTextInputValue("duration");
|
||||
|
@ -122,6 +112,5 @@ export async function launchBanActionModal(
|
|||
const evidence = submitted.fields.getTextInputValue("evidence");
|
||||
|
||||
await banAction(pluginData, duration, reason, evidence, target, interaction, submitted);
|
||||
})
|
||||
.catch((err) => logger.error(`Ban modal interaction failed: ${err}`));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -61,15 +61,11 @@ export async function launchCleanActionModal(
|
|||
await interaction
|
||||
.awaitModalSubmit({ time: MODAL_TIMEOUT, filter: (i) => i.customId == modalId })
|
||||
.then(async (submitted) => {
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Clean interaction defer failed: ${err}`));
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
|
||||
const amount = submitted.fields.getTextInputValue("amount");
|
||||
if (isNaN(Number(amount))) {
|
||||
interaction
|
||||
.editReply({ content: `Error: Amount '${amount}' is invalid`, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Clean interaction reply failed: ${err}`));
|
||||
interaction.editReply({ content: `Error: Amount '${amount}' is invalid`, embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -81,6 +77,5 @@ export async function launchCleanActionModal(
|
|||
interaction.channelId,
|
||||
submitted,
|
||||
);
|
||||
})
|
||||
.catch((err) => logger.error(`Clean modal interaction failed: ${err}`));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -39,25 +39,21 @@ 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: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot mute: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -78,17 +74,13 @@ async function muteAction(
|
|||
await updateAction(pluginData, executingMember, result.case!, evidence);
|
||||
}
|
||||
|
||||
await interactionToReply
|
||||
.editReply({ content: muteMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
} catch (e) {
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Plugin error, please check your BOT_ALERTs",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Mute interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Plugin error, please check your BOT_ALERTs",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
|
||||
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
|
@ -134,9 +126,7 @@ export async function launchMuteActionModal(
|
|||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Mute interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Mute interaction defer failed: ${err}`));
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
}
|
||||
|
||||
const duration = submitted.fields.getTextInputValue("duration");
|
||||
|
@ -144,6 +134,5 @@ export async function launchMuteActionModal(
|
|||
const evidence = submitted.fields.getTextInputValue("evidence");
|
||||
|
||||
await muteAction(pluginData, duration, reason, evidence, target, interaction, submitted);
|
||||
})
|
||||
.catch((err) => logger.error(`Mute modal interaction failed: ${err}`));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import {
|
|||
TextInputStyle,
|
||||
} from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { canActOn } from "src/pluginUtils";
|
||||
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
|
||||
import { canActOn } from "../../../pluginUtils";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { logger } from "../../../logger";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
|
@ -34,25 +34,21 @@ 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: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot note: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -72,13 +68,11 @@ async function noteAction(
|
|||
});
|
||||
|
||||
const userName = renderUserUsername(targetMember.user);
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: `Note added on **${userName}** (Case #${createdCase.case_number})`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Note interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: `Note added on **${userName}** (Case #${createdCase.case_number})`,
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
}
|
||||
|
||||
export async function launchNoteActionModal(
|
||||
|
@ -99,14 +93,11 @@ export async function launchNoteActionModal(
|
|||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Note interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Note interaction defer failed: ${err}`));
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
}
|
||||
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
|
||||
await noteAction(pluginData, reason, target, interaction, submitted);
|
||||
})
|
||||
.catch((err) => logger.error(`Note modal interaction failed: ${err}`));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ import { GuildMember } from "discord.js";
|
|||
import { GuildPluginData } from "knub";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
export async function updateAction(
|
||||
|
@ -19,7 +19,7 @@ export async function updateAction(
|
|||
body: value,
|
||||
});
|
||||
|
||||
pluginData.getPlugin(LogsPlugin).logCaseUpdate({
|
||||
void pluginData.getPlugin(LogsPlugin).logCaseUpdate({
|
||||
mod: executingMember.user,
|
||||
caseNumber: theCase.case_number,
|
||||
caseType: CaseTypes[theCase.type],
|
||||
|
|
|
@ -8,8 +8,8 @@ import {
|
|||
TextInputStyle,
|
||||
} from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { canActOn } from "src/pluginUtils";
|
||||
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
|
||||
import { canActOn } from "../../../pluginUtils";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { logger } from "../../../logger";
|
||||
import { renderUserUsername } from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
|
@ -34,25 +34,21 @@ 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: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = await pluginData.guild.members.fetch(target);
|
||||
if (!canActOn(pluginData, executingMember, targetMember)) {
|
||||
await interactionToReply
|
||||
.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
})
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({
|
||||
content: "Cannot warn: insufficient permissions",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -62,9 +58,7 @@ async function warnAction(
|
|||
|
||||
const result = await modactions.warnMember(targetMember, reason, reason, { caseArgs });
|
||||
if (result.status === "failed") {
|
||||
await interactionToReply
|
||||
.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,9 +70,7 @@ async function warnAction(
|
|||
await updateAction(pluginData, executingMember, result.case, evidence);
|
||||
}
|
||||
|
||||
await interactionToReply
|
||||
.editReply({ content: muteMessage, embeds: [], components: [] })
|
||||
.catch((err) => logger.error(`Warn interaction reply failed: ${err}`));
|
||||
await interactionToReply.editReply({ content: muteMessage, embeds: [], components: [] });
|
||||
}
|
||||
|
||||
export async function launchWarnActionModal(
|
||||
|
@ -105,15 +97,12 @@ export async function launchWarnActionModal(
|
|||
if (interaction.isButton()) {
|
||||
await submitted.deferUpdate().catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
|
||||
} else if (interaction.isContextMenuCommand()) {
|
||||
await submitted
|
||||
.deferReply({ ephemeral: true })
|
||||
.catch((err) => logger.error(`Warn interaction defer failed: ${err}`));
|
||||
await submitted.deferReply({ ephemeral: true });
|
||||
}
|
||||
|
||||
const reason = submitted.fields.getTextInputValue("reason");
|
||||
const evidence = submitted.fields.getTextInputValue("evidence");
|
||||
|
||||
await warnAction(pluginData, reason, evidence, target, interaction, submitted);
|
||||
})
|
||||
.catch((err) => logger.error(`Warn modal interaction failed: ${err}`));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue