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 result = await modactions.banUserId(target, reason, { caseArgs }, durationMs);
|
||||
const result = await modactions.banUserId(targetMember.id, reason, { caseArgs }, durationMs);
|
||||
if (result.status === "failed") {
|
||||
await interactionToReply
|
||||
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })
|
||||
|
|
|
@ -66,7 +66,7 @@ async function muteAction(
|
|||
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
|
||||
|
||||
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 muteMessage = `Muted **${result.case.user_name}** ${
|
||||
|
|
|
@ -137,19 +137,7 @@ export const BanCmd = modActionsCmd({
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
// Ask the mod if we should upgrade to a forceban as the user is not on the server
|
||||
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;
|
||||
}
|
||||
forceban = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { DAYS, MINUTES, resolveMember, resolveUser } from "../../../utils";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { banLock } from "../../../utils/lockNameHelpers";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { banUserId } from "../functions/banUserId";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { ignoreEvent } from "../functions/ignoreEvent";
|
||||
import { isBanned } from "../functions/isBanned";
|
||||
import { IgnoredEventType, modActionsCmd } from "../types";
|
||||
import { BanResult, IgnoredEventType, modActionsCmd } from "../types";
|
||||
|
||||
const opts = {
|
||||
mod: ct.member({ option: true }),
|
||||
|
@ -62,39 +61,44 @@ export const ForcebanCmd = modActionsCmd({
|
|||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||
const lock = await pluginData.locks.acquire(banLock(user));
|
||||
|
||||
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
|
||||
|
||||
let banResult: BanResult;
|
||||
try {
|
||||
// FIXME: Use banUserId()?
|
||||
await pluginData.guild.bans.create(user.id as Snowflake, {
|
||||
deleteMessageSeconds: (1 * DAYS) / MINUTES,
|
||||
reason: reason ?? undefined,
|
||||
const deleteMessageDays =
|
||||
args["delete-days"] ?? (await pluginData.config.getForMessage(msg)).ban_delete_message_days;
|
||||
banResult = await banUserId(pluginData, user.id, reason, {
|
||||
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 {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
|
||||
lock.unlock();
|
||||
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
|
||||
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
|
||||
pluginData.getPlugin(LogsPlugin).logMemberForceban({
|
||||
mod,
|
||||
userId: user.id,
|
||||
caseNumber: createdCase.case_number,
|
||||
caseNumber: banResult.case.case_number,
|
||||
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
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
||||
|
|
|
@ -92,36 +92,36 @@ export interface IIgnoredEvent {
|
|||
|
||||
export type WarnResult =
|
||||
| {
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
| {
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
|
||||
export type KickResult =
|
||||
| {
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
| {
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
|
||||
export type BanResult =
|
||||
| {
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
status: "failed";
|
||||
error: string;
|
||||
}
|
||||
| {
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
status: "success";
|
||||
case: Case;
|
||||
notifyResult: UserNotificationResult;
|
||||
};
|
||||
|
||||
export type WarnMemberNotifyRetryCallback = () => boolean | Promise<boolean>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue