3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 15:00:00 +00:00

mod actions reason aliases

Co-authored-by: metal0 <metal@i0.tf>
This commit is contained in:
almeidx 2023-12-28 10:40:05 +00:00
parent 3b98c3bdc1
commit 80c195f25e
No known key found for this signature in database
GPG key ID: 54402591B9053451
16 changed files with 92 additions and 34 deletions

View file

@ -47,6 +47,7 @@ import { BanOptions, ConfigSchema, KickOptions, ModActionsPluginType, WarnOption
import { LogsPlugin } from "../Logs/LogsPlugin"; import { LogsPlugin } from "../Logs/LogsPlugin";
import { onGuildEvent } from "../../data/GuildEvents"; import { onGuildEvent } from "../../data/GuildEvents";
import { clearTempban } from "./functions/clearTempban"; import { clearTempban } from "./functions/clearTempban";
import { ConfigPreprocessorFn } from "knub/dist/config/configTypes";
const defaultOptions = { const defaultOptions = {
config: { config: {
@ -84,6 +85,7 @@ const defaultOptions = {
can_deletecase: false, can_deletecase: false,
can_act_as_other: false, can_act_as_other: false,
create_cases_for_manual_actions: true, create_cases_for_manual_actions: true,
reason_aliases: {},
}, },
overrides: [ overrides: [
{ {
@ -112,6 +114,19 @@ const defaultOptions = {
], ],
}; };
/**
* Config preprocessor to fix values
*/
const configPreprocessor: ConfigPreprocessorFn<ModActionsPluginType> = (options) => {
if (options.config?.reason_aliases) {
options.config.reason_aliases = Object.fromEntries(
Object.entries(options.config.reason_aliases).map(([k, v]) => [k.toLowerCase(), v]),
);
}
return options;
};
export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
name: "mod_actions", name: "mod_actions",
showInDocs: true, showInDocs: true,
@ -125,6 +140,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
dependencies: () => [TimeAndDatePlugin, CasesPlugin, MutesPlugin, LogsPlugin], dependencies: () => [TimeAndDatePlugin, CasesPlugin, MutesPlugin, LogsPlugin],
configSchema: ConfigSchema, configSchema: ConfigSchema,
defaultOptions, defaultOptions,
configPreprocessor,
events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt], events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt],

View file

@ -1,14 +1,13 @@
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case"; import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../utils"; import { resolveMember, resolveUser } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { modActionsCmd } from "../types"; import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "../functions/parseReason";
const opts = { const opts = {
mod: ct.member({ option: true }), mod: ct.member({ option: true }),
@ -60,8 +59,8 @@ export const AddCaseCmd = modActionsCmd({
sendErrorMessage(pluginData, msg.channel, "Cannot add case: invalid case type"); sendErrorMessage(pluginData, msg.channel, "Cannot add case: invalid case type");
return; return;
} }
const config = pluginData.config.get();
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]); const reason = formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()]);
// Create the case // Create the case
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);

View file

@ -11,6 +11,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
import { isBanned } from "../functions/isBanned"; import { isBanned } from "../functions/isBanned";
import { IgnoredEventType, modActionsCmd } from "../types"; import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "../functions/parseReason";
const opts = { const opts = {
mod: ct.member({ option: true }), mod: ct.member({ option: true }),
@ -61,8 +62,8 @@ export const ForcebanCmd = modActionsCmd({
mod = args.mod; mod = args.mod;
} }
const config = pluginData.config.get();
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]); const reason = formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()]);
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);

View file

@ -1,6 +1,5 @@
import { Snowflake, TextChannel } from "discord.js"; import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers"; import { waitForReply } from "knub/dist/helpers";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -11,6 +10,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
import { isBanned } from "../functions/isBanned"; import { isBanned } from "../functions/isBanned";
import { IgnoredEventType, modActionsCmd } from "../types"; import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "../functions/parseReason";
export const MassunbanCmd = modActionsCmd({ export const MassunbanCmd = modActionsCmd({
trigger: "massunban", trigger: "massunban",
@ -37,8 +37,10 @@ export const MassunbanCmd = modActionsCmd({
sendErrorMessage(pluginData, msg.channel, "Cancelled"); sendErrorMessage(pluginData, msg.channel, "Cancelled");
return; return;
} }
const config = pluginData.config.get();
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, [...msg.attachments.values()]); const unbanReason = formatReasonWithAttachments(parseReason(config, unbanReasonReply.content), [
...msg.attachments.values(),
]);
// Ignore automatic unban cases and logs for these users // Ignore automatic unban cases and logs for these users
// We'll create our own cases below and post a single "mass unbanned" log instead // We'll create our own cases below and post a single "mass unbanned" log instead

View file

@ -1,6 +1,5 @@
import { Snowflake, TextChannel } from "discord.js"; import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers"; import { waitForReply } from "knub/dist/helpers";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger"; import { logger } from "../../../logger";
@ -9,6 +8,7 @@ import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginU
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { modActionsCmd } from "../types"; import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "../functions/parseReason";
export const MassmuteCmd = modActionsCmd({ export const MassmuteCmd = modActionsCmd({
trigger: "massmute", trigger: "massmute",
@ -40,7 +40,10 @@ export const MassmuteCmd = modActionsCmd({
return; return;
} }
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, [...msg.attachments.values()]); const config = pluginData.config.get();
const muteReason = formatReasonWithAttachments(parseReason(config, muteReasonReceived.content), [
...msg.attachments.values(),
]);
// Verify we can act upon all users // Verify we can act upon all users
for (const userId of args.userIds) { for (const userId of args.userIds) {

View file

@ -1,5 +1,4 @@
import { Snowflake } from "discord.js"; import { Snowflake } from "discord.js";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -11,6 +10,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
import { IgnoredEventType, modActionsCmd } from "../types"; import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { clearExpiringTempban } from "../../../data/loops/expiringTempbansLoop"; import { clearExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
import { parseReason } from "../functions/parseReason";
const opts = { const opts = {
mod: ct.member({ option: true }), mod: ct.member({ option: true }),
@ -49,7 +49,8 @@ export const UnbanCmd = modActionsCmd({
} }
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id); pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]); const config = pluginData.config.get();
const reason = formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()]);
try { try {
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id); ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);

View file

@ -7,6 +7,7 @@ import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { isBanned } from "../functions/isBanned"; import { isBanned } from "../functions/isBanned";
import { parseReason } from "../functions/parseReason";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { warnMember } from "../functions/warnMember"; import { warnMember } from "../functions/warnMember";
import { modActionsCmd } from "../types"; import { modActionsCmd } from "../types";
@ -63,7 +64,7 @@ export const WarnCmd = modActionsCmd({
} }
const config = pluginData.config.get(); const config = pluginData.config.get();
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]); const reason = formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()]);
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn); const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);

View file

@ -1,4 +1,4 @@
import { GuildMember, TextChannel, ThreadChannel } from "discord.js"; import { GuildMember, Message, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { hasPermission } from "knub/dist/helpers"; import { hasPermission } from "knub/dist/helpers";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -9,11 +9,12 @@ import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { ignoreEvent } from "./ignoreEvent"; import { ignoreEvent } from "./ignoreEvent";
import { isBanned } from "./isBanned"; import { isBanned } from "./isBanned";
import { kickMember } from "./kickMember"; import { kickMember } from "./kickMember";
import { parseReason } from "./parseReason";
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
export async function actualKickMemberCmd( export async function actualKickMemberCmd(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
msg, msg: Message,
args: { args: {
user: string; user: string;
reason: string; reason: string;
@ -24,8 +25,9 @@ export async function actualKickMemberCmd(
}, },
) { ) {
const user = await resolveUser(pluginData.client, args.user); const user = await resolveUser(pluginData.client, args.user);
if (!user.id) { const channel = msg.channel as TextChannel;
sendErrorMessage(pluginData, msg.channel, `User not found`); if (!user.id || !msg.member) {
sendErrorMessage(pluginData, channel, `User not found`);
return; return;
} }
@ -34,9 +36,9 @@ export async function actualKickMemberCmd(
if (!memberToKick) { if (!memberToKick) {
const banned = await isBanned(pluginData, user.id); const banned = await isBanned(pluginData, user.id);
if (banned) { if (banned) {
sendErrorMessage(pluginData, msg.channel, `User is banned`); sendErrorMessage(pluginData, channel, `User is banned`);
} else { } else {
sendErrorMessage(pluginData, msg.channel, `User not found on the server`); sendErrorMessage(pluginData, channel, `User not found on the server`);
} }
return; return;
@ -44,7 +46,7 @@ export async function actualKickMemberCmd(
// Make sure we're allowed to kick this member // Make sure we're allowed to kick this member
if (!canActOn(pluginData, msg.member, memberToKick)) { if (!canActOn(pluginData, msg.member, memberToKick)) {
sendErrorMessage(pluginData, msg.channel, "Cannot kick: insufficient permissions"); sendErrorMessage(pluginData, channel, "Cannot kick: insufficient permissions");
return; return;
} }
@ -52,7 +54,7 @@ export async function actualKickMemberCmd(
let mod = msg.member; let mod = msg.member;
if (args.mod) { if (args.mod) {
if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) { if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod"); sendErrorMessage(pluginData, channel, "You don't have permission to use -mod");
return; return;
} }
@ -63,17 +65,18 @@ export async function actualKickMemberCmd(
try { try {
contactMethods = readContactMethodsFromArgs(args); contactMethods = readContactMethodsFromArgs(args);
} catch (e) { } catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message); sendErrorMessage(pluginData, channel, e.message);
return; return;
} }
const reason = formatReasonWithAttachments(args.reason, msg.attachments); const config = pluginData.config.get();
const reason = formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()]);
const kickResult = await kickMember(pluginData, memberToKick, reason, { const kickResult = await kickMember(pluginData, memberToKick, reason, {
contactMethods, contactMethods,
caseArgs: { caseArgs: {
modId: mod.id, modId: mod.id,
ppId: mod.id !== msg.author.id ? msg.author.id : null, ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
}, },
}); });
@ -84,7 +87,7 @@ export async function actualKickMemberCmd(
try { try {
await memberToKick.ban({ days: 1, reason: "kick -clean" }); await memberToKick.ban({ days: 1, reason: "kick -clean" });
} catch { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)"); sendErrorMessage(pluginData, channel, "Failed to ban the user to clean messages (-clean)");
} }
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id); pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
@ -93,7 +96,7 @@ export async function actualKickMemberCmd(
try { try {
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean"); await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
} catch { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)"); sendErrorMessage(pluginData, channel, "Failed to unban the user after banning them (-clean)");
} }
} }
@ -106,5 +109,5 @@ export async function actualKickMemberCmd(
let response = `Kicked **${memberToKick.user.tag}** (Case #${kickResult.case.case_number})`; let response = `Kicked **${memberToKick.user.tag}** (Case #${kickResult.case.case_number})`;
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`; if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
sendSuccessMessage(pluginData, msg.channel, response); sendSuccessMessage(pluginData, channel, response);
} }

View file

@ -9,6 +9,7 @@ import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { MuteResult } from "../../Mutes/types"; import { MuteResult } from "../../Mutes/types";
import { ModActionsPluginType } from "../types"; import { ModActionsPluginType } from "../types";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { parseReason } from "./parseReason";
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
/** /**
@ -42,7 +43,10 @@ export async function actualMuteUserCmd(
} }
const timeUntilUnmute = args.time && humanizeDuration(args.time); 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(parseReason(config, args.reason), [...msg.attachments.values()])
: undefined;
let muteResult: MuteResult; let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin); const mutesPlugin = pluginData.getPlugin(MutesPlugin);

View file

@ -6,6 +6,7 @@ import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pl
import { asSingleLine, UnknownUser } from "../../../utils"; import { asSingleLine, UnknownUser } from "../../../utils";
import { ModActionsPluginType } from "../types"; import { ModActionsPluginType } from "../types";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { parseReason } from "./parseReason";
export async function actualUnmuteCmd( export async function actualUnmuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
@ -27,7 +28,10 @@ export async function actualUnmuteCmd(
pp = msg.author; pp = msg.author;
} }
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined; const config = pluginData.config.get();
const reason = args.reason
? formatReasonWithAttachments(parseReason(config, args.reason), [...msg.attachments.values()])
: undefined;
const mutesPlugin = pluginData.getPlugin(MutesPlugin); const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const result = await mutesPlugin.unmuteUser(user.id, args.time, { const result = await mutesPlugin.unmuteUser(user.id, args.time, {

View file

@ -20,6 +20,7 @@ import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { ignoreEvent } from "./ignoreEvent"; import { ignoreEvent } from "./ignoreEvent";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop"; import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
import { parseReason } from "./parseReason";
/** /**
* Ban the specified user id, whether or not they're actually on the server at the time. Generates a case. * Ban the specified user id, whether or not they're actually on the server at the time. Generates a case.
@ -39,6 +40,7 @@ export async function banUserId(
error: "Invalid user", error: "Invalid user",
}; };
} }
reason &&= parseReason(config, reason);
// 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
let notifyResult: UserNotificationResult = { method: null, success: true }; let notifyResult: UserNotificationResult = { method: null, success: true };

View file

@ -10,6 +10,7 @@ import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from
import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { ignoreEvent } from "./ignoreEvent"; import { ignoreEvent } from "./ignoreEvent";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "./parseReason";
/** /**
* Kick the specified server member. Generates a case. * Kick the specified server member. Generates a case.
@ -25,6 +26,7 @@ export async function kickMember(
// Attempt to message the user *before* kicking them, as doing it after may not be possible // Attempt to message the user *before* kicking them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true }; let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason) { if (reason) {
reason = parseReason(config, reason);
const contactMethods = kickOptions?.contactMethods const contactMethods = kickOptions?.contactMethods
? kickOptions.contactMethods ? kickOptions.contactMethods
: getDefaultContactMethods(pluginData, "kick"); : getDefaultContactMethods(pluginData, "kick");

View file

@ -0,0 +1,14 @@
import { TConfigSchema } from "../types";
const MAX_REASON_LENGTH = 512;
export function parseReason(config: TConfigSchema, reason: string): string {
if (!reason) return reason;
if (config?.reason_aliases) {
reason = config.reason_aliases[reason.toLowerCase()] ?? reason;
}
if (reason!.length > MAX_REASON_LENGTH) {
reason = reason!.substring(0, MAX_REASON_LENGTH - 4) + " […]";
}
return reason;
}

View file

@ -6,8 +6,11 @@ import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "./parseReason.js";
import { GuildPluginData } from "knub";
import { ModActionsPluginType } from "../types.js";
export async function updateCase(pluginData, msg: Message, args) { export async function updateCase(pluginData: GuildPluginData<ModActionsPluginType>, msg: Message, args) {
let theCase: Case | undefined; let theCase: Case | undefined;
if (args.caseNumber != null) { if (args.caseNumber != null) {
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber); theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
@ -24,6 +27,8 @@ export async function updateCase(pluginData, msg: Message, args) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Text or attachment required"); sendErrorMessage(pluginData, msg.channel as TextChannel, "Text or attachment required");
return; return;
} }
const config = pluginData.config.get();
args.note &&= parseReason(config, args.note);
const note = formatReasonWithAttachments(args.note, [...msg.attachments.values()]); const note = formatReasonWithAttachments(args.note, [...msg.attachments.values()]);

View file

@ -1,8 +1,7 @@
import { GuildMember, Snowflake } from "discord.js"; import { GuildMember, Snowflake } from "discord.js";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils"; import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
import { waitForButtonConfirm } from "../../../utils/waitForInteraction"; import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
@ -10,6 +9,7 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types"; import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "./parseReason";
export async function warnMember( export async function warnMember(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
@ -18,7 +18,7 @@ export async function warnMember(
warnOptions: WarnOptions = {}, warnOptions: WarnOptions = {},
): Promise<WarnResult> { ): Promise<WarnResult> {
const config = pluginData.config.get(); const config = pluginData.config.get();
reason = parseReason(config, reason);
let notifyResult: UserNotificationResult; let notifyResult: UserNotificationResult;
if (config.warn_message) { if (config.warn_message) {
const warnMessage = await renderTemplate( const warnMessage = await renderTemplate(

View file

@ -46,6 +46,7 @@ export const ConfigSchema = t.type({
can_deletecase: t.boolean, can_deletecase: t.boolean,
can_act_as_other: t.boolean, can_act_as_other: t.boolean,
create_cases_for_manual_actions: t.boolean, create_cases_for_manual_actions: t.boolean,
reason_aliases: tNullable(t.record(t.string, t.string)),
}); });
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>; export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;