3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-06 18:47:20 +00:00
zeppelin/backend/src/plugins/ModActions/functions/updateCase.ts
almeidx 80c195f25e
mod actions reason aliases
Co-authored-by: metal0 <metal@i0.tf>
2023-12-28 10:40:05 +00:00

50 lines
1.8 KiB
TypeScript

import { Message, TextChannel } from "discord.js";
import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { parseReason } from "./parseReason.js";
import { GuildPluginData } from "knub";
import { ModActionsPluginType } from "../types.js";
export async function updateCase(pluginData: GuildPluginData<ModActionsPluginType>, msg: Message, args) {
let theCase: Case | undefined;
if (args.caseNumber != null) {
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
} else {
theCase = await pluginData.state.cases.findLatestByModId(msg.author.id);
}
if (!theCase) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Case not found");
return;
}
if (!args.note && msg.attachments.size === 0) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Text or attachment required");
return;
}
const config = pluginData.config.get();
args.note &&= parseReason(config, args.note);
const note = formatReasonWithAttachments(args.note, [...msg.attachments.values()]);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
await casesPlugin.createCaseNote({
caseId: theCase.id,
modId: msg.author.id,
body: note,
});
pluginData.getPlugin(LogsPlugin).logCaseUpdate({
mod: msg.author,
caseNumber: theCase.case_number,
caseType: CaseTypes[theCase.type],
note,
});
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Case \`#${theCase.case_number}\` updated`);
}