2020-10-01 01:43:38 +03:00
|
|
|
import { modActionsCmd } from "../types";
|
2020-07-23 00:37:33 +03:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
|
|
import { Case } from "../../../data/entities/Case";
|
|
|
|
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
|
|
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|
|
|
import { LogType } from "../../../data/LogType";
|
|
|
|
import { CaseTypes } from "../../../data/CaseTypes";
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export const UpdateCmd = modActionsCmd({
|
2021-04-02 09:38:24 -04:00
|
|
|
trigger: ["update", "reason"],
|
2020-07-23 00:37:33 +03:00
|
|
|
permission: "can_note",
|
|
|
|
description:
|
|
|
|
"Update the specified case (or, if case number is omitted, your latest case) by adding more notes/details to it",
|
|
|
|
|
2020-07-24 02:25:33 +02:00
|
|
|
signature: [
|
|
|
|
{
|
|
|
|
caseNumber: ct.number(),
|
|
|
|
note: ct.string({ required: false, catchAll: true }),
|
|
|
|
},
|
|
|
|
{
|
2020-07-30 15:51:21 +03:00
|
|
|
note: ct.string({ required: false, catchAll: true }),
|
2020-07-24 02:25:33 +02:00
|
|
|
},
|
|
|
|
],
|
2020-07-23 00:37:33 +03:00
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
2020-11-09 20:03:57 +02:00
|
|
|
let theCase: Case | undefined;
|
2020-07-23 00:37:33 +03:00
|
|
|
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, "Case not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!args.note && msg.attachments.length === 0) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const note = formatReasonWithAttachments(args.note, msg.attachments);
|
|
|
|
|
|
|
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
|
|
|
await casesPlugin.createCaseNote({
|
|
|
|
caseId: theCase.id,
|
|
|
|
modId: msg.author.id,
|
|
|
|
body: note,
|
|
|
|
});
|
|
|
|
|
|
|
|
pluginData.state.serverLogs.log(LogType.CASE_UPDATE, {
|
|
|
|
mod: msg.author,
|
|
|
|
caseNumber: theCase.case_number,
|
|
|
|
caseType: CaseTypes[theCase.type],
|
|
|
|
note,
|
|
|
|
});
|
|
|
|
|
|
|
|
sendSuccessMessage(pluginData, msg.channel, `Case \`#${theCase.case_number}\` updated`);
|
|
|
|
},
|
|
|
|
});
|