mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 19:17:19 +00:00
refactor: move defaults to config schemas
This commit is contained in:
parent
09eb8e92f2
commit
83d35052c3
91 changed files with 450 additions and 888 deletions
|
@ -34,29 +34,6 @@ import { clearOldRecentActions } from "./functions/clearOldRecentActions.js";
|
|||
import { clearOldRecentSpam } from "./functions/clearOldRecentSpam.js";
|
||||
import { AutomodPluginType, zAutomodConfig } from "./types.js";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
rules: {},
|
||||
antiraid_levels: ["low", "medium", "high"],
|
||||
can_set_antiraid: false,
|
||||
can_view_antiraid: false,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
level: ">=50",
|
||||
config: {
|
||||
can_view_antiraid: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
level: ">=100",
|
||||
config: {
|
||||
can_set_antiraid: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const AutomodPlugin = guildPlugin<AutomodPluginType>()({
|
||||
name: "automod",
|
||||
|
||||
|
@ -71,8 +48,7 @@ export const AutomodPlugin = guildPlugin<AutomodPluginType>()({
|
|||
RoleManagerPlugin,
|
||||
],
|
||||
|
||||
defaultOptions,
|
||||
configParser: (input) => zAutomodConfig.parse(input),
|
||||
configSchema: zAutomodConfig,
|
||||
|
||||
customOverrideCriteriaFunctions: {
|
||||
antiraid_level: (pluginData, matchParams, value) => {
|
||||
|
|
|
@ -9,24 +9,12 @@ interface MatchResultType {
|
|||
mode: "blacklist" | "whitelist";
|
||||
}
|
||||
|
||||
const baseConfig = z.strictObject({
|
||||
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
const configSchema = z.strictObject({
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
});
|
||||
const configWithWhitelist = baseConfig.merge(
|
||||
z.strictObject({
|
||||
whitelist_enabled: z.literal(true),
|
||||
blacklist_enabled: z.literal(false).default(false),
|
||||
}),
|
||||
);
|
||||
const configWithBlacklist = baseConfig.merge(
|
||||
z.strictObject({
|
||||
blacklist_enabled: z.literal(true),
|
||||
whitelist_enabled: z.literal(false).default(false),
|
||||
}),
|
||||
);
|
||||
|
||||
const configSchema = z.union([configWithWhitelist, configWithBlacklist]);
|
||||
|
||||
export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
||||
configSchema,
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
import { escapeInlineCode } from "discord.js";
|
||||
import z from "zod/v4";
|
||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils.js";
|
||||
import { automodTrigger } from "../helpers.js";
|
||||
import z from "zod/v4";
|
||||
|
||||
interface MatchResultType {
|
||||
matchedType: string;
|
||||
mode: "blacklist" | "whitelist";
|
||||
}
|
||||
|
||||
const baseConfig = z.strictObject({
|
||||
mime_type_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
const configSchema = z.strictObject({
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
mime_type_whitelist: z.array(z.string().max(32)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
mime_type_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
});
|
||||
const configWithWhitelist = baseConfig.merge(
|
||||
z.strictObject({
|
||||
whitelist_enabled: z.literal(true),
|
||||
blacklist_enabled: z.literal(false).default(false),
|
||||
}),
|
||||
);
|
||||
const configWithBlacklist = baseConfig.merge(
|
||||
z.strictObject({
|
||||
blacklist_enabled: z.literal(true),
|
||||
whitelist_enabled: z.literal(false).default(false),
|
||||
}),
|
||||
);
|
||||
|
||||
const configSchema = z.union([configWithWhitelist, configWithBlacklist]);
|
||||
|
||||
export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
|
||||
configSchema,
|
||||
|
|
|
@ -58,14 +58,14 @@ const zRule = z.strictObject({
|
|||
export type TRule = z.infer<typeof zRule>;
|
||||
|
||||
export const zAutomodConfig = z.strictObject({
|
||||
rules: zBoundedRecord(z.record(z.string().max(100), zRule), 0, 255),
|
||||
antiraid_levels: z.array(z.string().max(100)).max(10),
|
||||
can_set_antiraid: z.boolean(),
|
||||
can_view_antiraid: z.boolean(),
|
||||
rules: zBoundedRecord(z.record(z.string().max(100), zRule), 0, 255).default({}),
|
||||
antiraid_levels: z.array(z.string().max(100)).max(10).default(["low", "medium", "high"]),
|
||||
can_set_antiraid: z.boolean().default(false),
|
||||
can_view_antiraid: z.boolean().default(false),
|
||||
});
|
||||
|
||||
export interface AutomodPluginType extends BasePluginType {
|
||||
config: z.output<typeof zAutomodConfig>;
|
||||
configSchema: typeof zAutomodConfig;
|
||||
|
||||
customOverrideCriteria: {
|
||||
antiraid_level?: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue