3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 10:25:01 +00:00

Update createCase.ts

This commit is contained in:
srqc 2023-01-12 18:41:01 -05:00 committed by GitHub
parent 69da0fbc74
commit 15b2f892b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,8 +5,11 @@ import { resolveUser } from "../../../utils";
import { CaseArgs, CasesPluginType } from "../types";
import { createCaseNote } from "./createCaseNote";
import { postCaseToCaseLogChannel } from "./postToCaseLogChannel";
import { getDashboardUrl } from "../../../pluginUtils";
import { CaseTypes } from "../../../data/CaseTypes";
export async function createCase(pluginData: GuildPluginData<CasesPluginType>, args: CaseArgs) {
const casesTypesWithoutArchive = [CaseTypes.Note, CaseTypes.Unban];
const user = await resolveUser(pluginData.client, args.userId);
const userName = user.tag;
@ -41,6 +44,28 @@ export async function createCase(pluginData: GuildPluginData<CasesPluginType>, a
is_hidden: Boolean(args.hide),
});
if (!casesTypesWithoutArchive.includes(args.type)) {
const messagesToArchive = Array.from(await pluginData.state.savedMessages.getUserMessages(user.id, 50)).sort(
(a, b) => (a.posted_at > b.posted_at ? 1 : -1),
);
let noteBody = `No automatic archive was created because no messages were found for this user.`;
if (messagesToArchive.length > 0) {
const archiveId = await pluginData.state.archives.createFromSavedMessages(messagesToArchive, pluginData.guild);
const baseUrl = getDashboardUrl(pluginData);
noteBody = `Automatically archived messages: ${pluginData.state.archives.getUrl(baseUrl, archiveId)}`;
}
await createCaseNote(pluginData, {
caseId: createdCase.id,
modId: mod.id,
body: noteBody,
automatic: args.automatic,
postInCaseLogOverride: false,
});
}
if (args.reason || args.noteDetails?.length) {
await createCaseNote(pluginData, {
caseId: createdCase.id,