Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default ban reason #420

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/src/plugins/ModActions/ModActionsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ 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_reasons: {
mute: "No reason specified",
kick: "No reason specified",
ban: "No reason specified",
},
alert_on_rejoin: false,
alert_channel: null,
warn_notify_enabled: false,
Expand Down
5 changes: 4 additions & 1 deletion backend/src/plugins/ModActions/commands/ForcebanCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export const ForcebanCmd = modActionsCmd({
mod = args.mod;
}

const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
const config = pluginData.config.get();
const reason = args.reason
? formatReasonWithAttachments(args.reason, [...msg.attachments.values()])
: config.default_reasons?.ban || "No reason specified";
iamshoXy marked this conversation as resolved.
Show resolved Hide resolved

ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export async function actualKickMemberCmd(
return;
}

const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const config = pluginData.config.get();
const reason = args.reason
? formatReasonWithAttachments(args.reason, msg.attachments)
: config.default_reasons?.kick || "No reason specified";
iamshoXy marked this conversation as resolved.
Show resolved Hide resolved

const kickResult = await kickMember(pluginData, memberToKick, reason, {
contactMethods,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export async function actualMuteUserCmd(
}

const timeUntilUnmute = args.time && humanizeDuration(args.time);
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined;

const config = pluginData.config.get();
const reason = args.reason
? formatReasonWithAttachments(args.reason, [...msg.attachments.values()])
: config.default_reasons?.mute || "No reason specified";
iamshoXy marked this conversation as resolved.
Show resolved Hide resolved

let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
Expand Down
12 changes: 7 additions & 5 deletions backend/src/plugins/ModActions/functions/banUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export async function banUserId(
banOptions: BanOptions = {},
banTime?: number,
): Promise<BanResult> {
const config = pluginData.config.get();
const user = await resolveUser(pluginData.client, userId);
if (!user.id) {
return {
Expand All @@ -42,10 +41,13 @@ export async function banUserId(
};
}

const config = pluginData.config.get();
reason ||= config.default_reasons?.ban || "No reason specified";
iamshoXy marked this conversation as resolved.
Show resolved Hide resolved

// 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");
Expand Down Expand Up @@ -113,7 +115,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;
Expand Down Expand Up @@ -171,15 +173,15 @@ export async function banUserId(
mod,
user,
caseNumber: createdCase.case_number,
reason: reason ?? "",
reason,
banTime: humanizeDuration(banTime),
});
} else {
pluginData.getPlugin(LogsPlugin).logMemberBan({
mod,
user,
caseNumber: createdCase.case_number,
reason: reason ?? "",
reason,
});
}

Expand Down
7 changes: 7 additions & 0 deletions backend/src/plugins/ModActions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const zModActionsConfig = z.strictObject({
kick_message: z.nullable(z.string()),
ban_message: z.nullable(z.string()),
tempban_message: z.nullable(z.string()),
default_reasons: z.nullable(
z.object({
mute: z.string().max(512).nullable(),
kick: z.string().max(512).nullable(),
ban: z.string().max(512).nullable(),
}),
),
alert_on_rejoin: z.boolean(),
alert_channel: z.nullable(z.string()),
warn_notify_enabled: z.boolean(),
Expand Down