Skip to content

Commit

Permalink
added default reasons object
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshoXy committed Dec 29, 2023
1 parent dceac6b commit 5ce01c8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
6 changes: 5 additions & 1 deletion backend/src/plugins/ModActions/ModActionsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +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_ban_reason: "No reason specified",
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";

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";

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";

let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
Expand Down
4 changes: 2 additions & 2 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,7 +41,8 @@ export async function banUserId(
};
}

reason = reason || (config.default_ban_reason || "No reason specified");
const config = pluginData.config.get();
reason ||= config.default_reasons?.ban || "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);
Expand Down
50 changes: 28 additions & 22 deletions backend/src/plugins/ModActions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ 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),
default_reasons: tNullable(
t.type({
mute: t.string,
kick: t.string,
ban: t.string,
}),
),
alert_on_rejoin: t.boolean,
alert_channel: tNullable(t.string),
warn_notify_enabled: t.boolean,
Expand Down Expand Up @@ -92,36 +98,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>;

Expand Down

0 comments on commit 5ce01c8

Please sign in to comment.