3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 19:17:19 +00:00
This commit is contained in:
iamshoXy 2023-09-09 15:15:02 +02:00
parent b30b81c4ed
commit 0612b6f17d
7 changed files with 58 additions and 49 deletions

View file

@ -62,6 +62,7 @@ const defaultOptions = {
kick_message: "You have been kicked from the {guildName} server. Reason given: {reason}",
ban_message: "You have been banned from the {guildName} server. Reason given: {reason}",
tempban_message: "You have been banned from the {guildName} server for {banTime}. Reason given: {reason}",
default_ban_reason: "No reason specified",
alert_on_rejoin: false,
alert_channel: null,
warn_notify_enabled: false,

View file

@ -42,10 +42,12 @@ export async function banUserId(
};
}
reason = 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);
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason && member) {
if (member) {
const contactMethods = banOptions?.contactMethods
? banOptions.contactMethods
: getDefaultContactMethods(pluginData, "ban");
@ -91,7 +93,7 @@ export async function banUserId(
const deleteMessageDays = Math.min(7, Math.max(0, banOptions.deleteMessageDays ?? 1));
await pluginData.guild.bans.create(userId as Snowflake, {
deleteMessageSeconds: (deleteMessageDays * DAYS) / SECONDS,
reason: reason ?? undefined,
reason,
});
} catch (e) {
let errorMessage;
@ -149,7 +151,7 @@ export async function banUserId(
mod,
user,
caseNumber: createdCase.case_number,
reason: reason ?? "",
reason,
banTime: humanizeDuration(banTime),
});
} else {
@ -157,7 +159,7 @@ export async function banUserId(
mod,
user,
caseNumber: createdCase.case_number,
reason: reason ?? "",
reason,
});
}
@ -168,4 +170,4 @@ export async function banUserId(
case: createdCase,
notifyResult,
};
}
}

View file

@ -23,6 +23,7 @@ export const ConfigSchema = t.type({
kick_message: tNullable(t.string),
ban_message: tNullable(t.string),
tempban_message: tNullable(t.string),
default_ban_reason: tNullable(t.string),
alert_on_rejoin: t.boolean,
alert_channel: tNullable(t.string),
warn_notify_enabled: t.boolean,
@ -91,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>;