Port CustomEventsPlugin
This commit is contained in:
parent
28de8a592b
commit
4c4496600b
9 changed files with 268 additions and 0 deletions
41
backend/src/plugins/CustomEvents/actions/createCaseAction.ts
Normal file
41
backend/src/plugins/CustomEvents/actions/createCaseAction.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { PluginData } from "knub";
|
||||
import { CustomEventsPluginType, TCustomEvent } from "../types";
|
||||
import * as t from "io-ts";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { ActionError } from "../ActionError";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
|
||||
export const CreateCaseAction = t.type({
|
||||
type: t.literal("create_case"),
|
||||
case_type: t.string,
|
||||
mod: t.string,
|
||||
target: t.string,
|
||||
reason: t.string,
|
||||
});
|
||||
export type TCreateCaseAction = t.TypeOf<typeof CreateCaseAction>;
|
||||
|
||||
export async function createCaseAction(
|
||||
pluginData: PluginData<CustomEventsPluginType>,
|
||||
action: TCreateCaseAction,
|
||||
values: any,
|
||||
event: TCustomEvent,
|
||||
eventData: any,
|
||||
) {
|
||||
const modId = await renderTemplate(action.mod, values, false);
|
||||
const targetId = await renderTemplate(action.target, values, false);
|
||||
|
||||
const reason = await renderTemplate(action.reason, values, false);
|
||||
|
||||
if (CaseTypes[action.case_type] == null) {
|
||||
throw new ActionError(`Invalid case type: ${action.type}`);
|
||||
}
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
await casesPlugin.createCase({
|
||||
userId: targetId,
|
||||
modId,
|
||||
type: CaseTypes[action.case_type],
|
||||
reason: `__[${event.name}]__ ${reason}`,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue