mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Port Cases plugin
This commit is contained in:
parent
a848e00fdd
commit
479cb56928
7 changed files with 349 additions and 0 deletions
73
backend/src/plugins/Cases/functions/createCase.ts
Normal file
73
backend/src/plugins/Cases/functions/createCase.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { CaseArgs, CasesPluginType } from "../types";
|
||||
import { resolveUser } from "../../../utils";
|
||||
import { PluginData } from "knub";
|
||||
import { createCaseNote } from "./createCaseNote";
|
||||
import { postToCaseLogChannel } from "./postToCaseLogChannel";
|
||||
|
||||
export async function createCase(pluginData: PluginData<CasesPluginType>, args: CaseArgs) {
|
||||
const user = await resolveUser(pluginData.client, args.userId);
|
||||
const userName = `${user.username}#${user.discriminator}`;
|
||||
|
||||
const mod = await resolveUser(pluginData.client, args.modId);
|
||||
const modName = `${mod.username}#${mod.discriminator}`;
|
||||
|
||||
let ppName = null;
|
||||
if (args.ppId) {
|
||||
const pp = await resolveUser(pluginData.client, args.ppId);
|
||||
ppName = `${pp.username}#${pp.discriminator}`;
|
||||
}
|
||||
|
||||
if (args.auditLogId) {
|
||||
const existingAuditLogCase = await pluginData.state.cases.findByAuditLogId(args.auditLogId);
|
||||
if (existingAuditLogCase) {
|
||||
delete args.auditLogId;
|
||||
console.warn(`Duplicate audit log ID for mod case: ${args.auditLogId}`);
|
||||
}
|
||||
}
|
||||
|
||||
const createdCase = await pluginData.state.cases.create({
|
||||
type: args.type,
|
||||
user_id: args.userId,
|
||||
user_name: userName,
|
||||
mod_id: args.modId,
|
||||
mod_name: modName,
|
||||
audit_log_id: args.auditLogId,
|
||||
pp_id: args.ppId,
|
||||
pp_name: ppName,
|
||||
});
|
||||
|
||||
if (args.reason || (args.noteDetails && args.noteDetails.length)) {
|
||||
await createCaseNote(pluginData, {
|
||||
caseId: createdCase.id,
|
||||
modId: args.modId,
|
||||
body: args.reason || "",
|
||||
automatic: args.automatic,
|
||||
postInCaseLogOverride: false,
|
||||
noteDetails: args.noteDetails,
|
||||
});
|
||||
}
|
||||
|
||||
if (args.extraNotes) {
|
||||
for (const extraNote of args.extraNotes) {
|
||||
await createCaseNote(pluginData, {
|
||||
caseId: createdCase.id,
|
||||
modId: args.modId,
|
||||
body: extraNote,
|
||||
automatic: args.automatic,
|
||||
postInCaseLogOverride: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const config = pluginData.config.get();
|
||||
|
||||
if (
|
||||
config.case_log_channel &&
|
||||
(!args.automatic || config.log_automatic_actions) &&
|
||||
args.postInCaseLogOverride !== false
|
||||
) {
|
||||
await postToCaseLogChannel(pluginData, createdCase);
|
||||
}
|
||||
|
||||
return createdCase;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue