mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-17 07:05:03 +00:00
PR: Fix issues with both ban commands
This commit is contained in:
parent
aa10e28dac
commit
2fc42c217a
6 changed files with 51 additions and 59 deletions
|
@ -53,7 +53,7 @@ async function banAction(
|
||||||
};
|
};
|
||||||
|
|
||||||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||||
const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs);
|
const result = await modactions.banUserId(targetMember.id, reason, { caseArgs }, durationMs);
|
||||||
if (result.status === "failed") {
|
if (result.status === "failed") {
|
||||||
await interactionToReply
|
await interactionToReply
|
||||||
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })
|
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })
|
||||||
|
|
|
@ -66,7 +66,7 @@ async function muteAction(
|
||||||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await mutes.muteUser(target, durationMs, reason, { caseArgs });
|
const result = await mutes.muteUser(targetMember.id, durationMs, reason, { caseArgs });
|
||||||
|
|
||||||
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
|
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
|
||||||
const muteMessage = `Muted **${result.case.user_name}** ${
|
const muteMessage = `Muted **${result.case.user_name}** ${
|
||||||
|
|
|
@ -137,19 +137,7 @@ export const BanCmd = modActionsCmd({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ask the mod if we should upgrade to a forceban as the user is not on the server
|
forceban = true;
|
||||||
const reply = await waitForButtonConfirm(
|
|
||||||
msg.channel,
|
|
||||||
{ content: "User not on server, forceban instead?" },
|
|
||||||
{ confirmText: "Yes", cancelText: "No", restrictToId: msg.member.id },
|
|
||||||
);
|
|
||||||
if (!reply) {
|
|
||||||
sendErrorMessage(pluginData, msg.channel, "User not on server, ban cancelled by moderator");
|
|
||||||
lock.unlock();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
forceban = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import { Snowflake } from "discord.js";
|
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
import { resolveMember, resolveUser } from "../../../utils";
|
||||||
import { DAYS, MINUTES, resolveMember, resolveUser } from "../../../utils";
|
import { banLock } from "../../../utils/lockNameHelpers";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
|
import { banUserId } from "../functions/banUserId";
|
||||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||||
import { ignoreEvent } from "../functions/ignoreEvent";
|
import { ignoreEvent } from "../functions/ignoreEvent";
|
||||||
import { isBanned } from "../functions/isBanned";
|
import { isBanned } from "../functions/isBanned";
|
||||||
import { IgnoredEventType, modActionsCmd } from "../types";
|
import { BanResult, IgnoredEventType, modActionsCmd } from "../types";
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
mod: ct.member({ option: true }),
|
mod: ct.member({ option: true }),
|
||||||
|
@ -62,39 +61,44 @@ export const ForcebanCmd = modActionsCmd({
|
||||||
}
|
}
|
||||||
|
|
||||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||||
|
const lock = await pluginData.locks.acquire(banLock(user));
|
||||||
|
|
||||||
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
|
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
|
||||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
|
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
|
||||||
|
|
||||||
|
let banResult: BanResult;
|
||||||
try {
|
try {
|
||||||
// FIXME: Use banUserId()?
|
const deleteMessageDays =
|
||||||
await pluginData.guild.bans.create(user.id as Snowflake, {
|
args["delete-days"] ?? (await pluginData.config.getForMessage(msg)).ban_delete_message_days;
|
||||||
deleteMessageSeconds: (1 * DAYS) / MINUTES,
|
banResult = await banUserId(pluginData, user.id, reason, {
|
||||||
reason: reason ?? undefined,
|
contactMethods: [],
|
||||||
|
caseArgs: {
|
||||||
|
modId: mod.id,
|
||||||
|
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
||||||
|
},
|
||||||
|
deleteMessageDays,
|
||||||
|
modId: mod.id,
|
||||||
});
|
});
|
||||||
|
if (banResult.status === "failed") {
|
||||||
|
sendErrorMessage(pluginData, msg.channel, `Failed to ban member: ${banResult.error}`);
|
||||||
|
lock.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
|
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
|
||||||
|
lock.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a case
|
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
|
||||||
const createdCase = await casesPlugin.createCase({
|
|
||||||
userId: user.id,
|
|
||||||
modId: mod.id,
|
|
||||||
type: CaseTypes.Ban,
|
|
||||||
reason,
|
|
||||||
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Confirm the action
|
// Confirm the action
|
||||||
sendSuccessMessage(pluginData, msg.channel, `Member forcebanned (Case #${createdCase.case_number})`);
|
sendSuccessMessage(pluginData, msg.channel, `Member forcebanned (Case #${banResult.case.case_number})`);
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
// Log the action
|
// Log the action
|
||||||
pluginData.getPlugin(LogsPlugin).logMemberForceban({
|
pluginData.getPlugin(LogsPlugin).logMemberForceban({
|
||||||
mod,
|
mod,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
caseNumber: createdCase.case_number,
|
caseNumber: banResult.case.case_number,
|
||||||
reason,
|
reason,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ export async function banUserId(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
reason = reason || (config.default_ban_reason || "No reason specified");
|
reason ||= config.default_ban_reason || "No reason specified";
|
||||||
|
|
||||||
// Attempt to message the user *before* banning them, as doing it after may not be possible
|
// Attempt to message the user *before* banning them, as doing it after may not be possible
|
||||||
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
||||||
|
@ -170,4 +170,4 @@ export async function banUserId(
|
||||||
case: createdCase,
|
case: createdCase,
|
||||||
notifyResult,
|
notifyResult,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,36 +92,36 @@ export interface IIgnoredEvent {
|
||||||
|
|
||||||
export type WarnResult =
|
export type WarnResult =
|
||||||
| {
|
| {
|
||||||
status: "failed";
|
status: "failed";
|
||||||
error: string;
|
error: string;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
status: "success";
|
status: "success";
|
||||||
case: Case;
|
case: Case;
|
||||||
notifyResult: UserNotificationResult;
|
notifyResult: UserNotificationResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type KickResult =
|
export type KickResult =
|
||||||
| {
|
| {
|
||||||
status: "failed";
|
status: "failed";
|
||||||
error: string;
|
error: string;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
status: "success";
|
status: "success";
|
||||||
case: Case;
|
case: Case;
|
||||||
notifyResult: UserNotificationResult;
|
notifyResult: UserNotificationResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BanResult =
|
export type BanResult =
|
||||||
| {
|
| {
|
||||||
status: "failed";
|
status: "failed";
|
||||||
error: string;
|
error: string;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
status: "success";
|
status: "success";
|
||||||
case: Case;
|
case: Case;
|
||||||
notifyResult: UserNotificationResult;
|
notifyResult: UserNotificationResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WarnMemberNotifyRetryCallback = () => boolean | Promise<boolean>;
|
export type WarnMemberNotifyRetryCallback = () => boolean | Promise<boolean>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue