refactor: replace io-ts with zod

This commit is contained in:
Dragory 2024-01-14 14:25:42 +00:00
parent fafaefa1fb
commit 28692962bc
No known key found for this signature in database
161 changed files with 1450 additions and 2105 deletions

View file

@ -1,12 +1,11 @@
import { PluginOptions } from "knub";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners";
import { trimPluginDescription } from "../../utils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { CensorPluginType, ConfigSchema } from "./types";
import { CensorPluginType, zCensorConfig } from "./types";
import { onMessageCreate } from "./util/onMessageCreate";
import { onMessageUpdate } from "./util/onMessageUpdate";
@ -54,11 +53,11 @@ export const CensorPlugin = zeppelinGuildPlugin<CensorPluginType>()({
For more advanced filtering, check out the Automod plugin!
`),
legacy: true,
configSchema: ConfigSchema,
configSchema: zCensorConfig,
},
dependencies: () => [LogsPlugin],
configParser: makeIoTsConfigParser(ConfigSchema),
configParser: (input) => zCensorConfig.parse(input),
defaultOptions,
beforeLoad(pluginData) {

View file

@ -1,30 +1,28 @@
import * as t from "io-ts";
import { BasePluginType } from "knub";
import z from "zod";
import { RegExpRunner } from "../../RegExpRunner";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { tNullable } from "../../utils";
import { TRegex } from "../../validatorUtils";
import { zBoundedCharacters, zRegex, zSnowflake } from "../../utils";
export const ConfigSchema = t.type({
filter_zalgo: t.boolean,
filter_invites: t.boolean,
invite_guild_whitelist: tNullable(t.array(t.string)),
invite_guild_blacklist: tNullable(t.array(t.string)),
invite_code_whitelist: tNullable(t.array(t.string)),
invite_code_blacklist: tNullable(t.array(t.string)),
allow_group_dm_invites: t.boolean,
filter_domains: t.boolean,
domain_whitelist: tNullable(t.array(t.string)),
domain_blacklist: tNullable(t.array(t.string)),
blocked_tokens: tNullable(t.array(t.string)),
blocked_words: tNullable(t.array(t.string)),
blocked_regex: tNullable(t.array(TRegex)),
export const zCensorConfig = z.strictObject({
filter_zalgo: z.boolean(),
filter_invites: z.boolean(),
invite_guild_whitelist: z.array(zSnowflake).nullable(),
invite_guild_blacklist: z.array(zSnowflake).nullable(),
invite_code_whitelist: z.array(zBoundedCharacters(0, 16)).nullable(),
invite_code_blacklist: z.array(zBoundedCharacters(0, 16)).nullable(),
allow_group_dm_invites: z.boolean(),
filter_domains: z.boolean(),
domain_whitelist: z.array(zBoundedCharacters(0, 255)).nullable(),
domain_blacklist: z.array(zBoundedCharacters(0, 255)).nullable(),
blocked_tokens: z.array(zBoundedCharacters(0, 2000)).nullable(),
blocked_words: z.array(zBoundedCharacters(0, 2000)).nullable(),
blocked_regex: z.array(zRegex(z.string().max(1000))).nullable(),
});
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface CensorPluginType extends BasePluginType {
config: TConfigSchema;
config: z.infer<typeof zCensorConfig>;
state: {
serverLogs: GuildLogs;
savedMessages: GuildSavedMessages;