Automod work
This commit is contained in:
parent
140ba84544
commit
f657b169df
32 changed files with 1099 additions and 5 deletions
60
backend/src/plugins/Automod/helpers.ts
Normal file
60
backend/src/plugins/Automod/helpers.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { PluginData } from "knub";
|
||||
import { Awaitable } from "knub/dist/utils";
|
||||
import * as t from "io-ts";
|
||||
import { AutomodContext, AutomodPluginType } from "./types";
|
||||
|
||||
export interface AutomodTriggerMatchResult<TExtra extends any = unknown> {
|
||||
extraContexts?: AutomodContext[];
|
||||
extra?: TExtra;
|
||||
|
||||
silentClean?: boolean;
|
||||
}
|
||||
|
||||
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
context: AutomodContext;
|
||||
triggerConfig: TConfigType;
|
||||
}) => Awaitable<null | AutomodTriggerMatchResult<TMatchResultExtra>>;
|
||||
|
||||
type AutomodTriggerRenderMatchInformationFn<TConfigType, TMatchResultExtra> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
contexts: AutomodContext[];
|
||||
triggerConfig: TConfigType;
|
||||
matchResult: AutomodTriggerMatchResult<TMatchResultExtra>;
|
||||
}) => Awaitable<string>;
|
||||
|
||||
export interface AutomodTriggerBlueprint<TConfigType extends t.Any, TMatchResultExtra extends t.Any> {
|
||||
configType: TConfigType;
|
||||
defaultConfig: Partial<t.TypeOf<TConfigType>>;
|
||||
|
||||
matchResultType: TMatchResultExtra;
|
||||
|
||||
match: AutomodTriggerMatchFn<t.TypeOf<TConfigType>, t.TypeOf<TMatchResultExtra>>;
|
||||
renderMatchInformation: AutomodTriggerRenderMatchInformationFn<t.TypeOf<TConfigType>, t.TypeOf<TMatchResultExtra>>;
|
||||
}
|
||||
|
||||
export function automodTrigger<TConfigType extends t.Any, TMatchResultExtra extends t.Any>(
|
||||
blueprint: AutomodTriggerBlueprint<TConfigType, TMatchResultExtra>,
|
||||
): AutomodTriggerBlueprint<TConfigType, TMatchResultExtra> {
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
type AutomodActionApplyFn<TConfigType> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
contexts: AutomodContext[];
|
||||
actionConfig: TConfigType;
|
||||
}) => Awaitable<void>;
|
||||
|
||||
export interface AutomodActionBlueprint<TConfigType extends t.Any> {
|
||||
configType: TConfigType;
|
||||
apply: AutomodActionApplyFn<t.TypeOf<TConfigType>>;
|
||||
}
|
||||
|
||||
export function automodAction<TConfigType extends t.Any>(
|
||||
blueprint: AutomodActionBlueprint<TConfigType>,
|
||||
): AutomodActionBlueprint<TConfigType> {
|
||||
return blueprint;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue