3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 15:15:02 +00:00

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

@ -3,7 +3,7 @@ import { Case } from "../../data/entities/Case";
import { GuildArchives } from "../../data/GuildArchives";
import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs";
import { makeIoTsConfigParser, mapToPublicFn } from "../../pluginUtils";
import { mapToPublicFn } from "../../pluginUtils";
import { trimPluginDescription } from "../../utils";
import { InternalPosterPlugin } from "../InternalPoster/InternalPosterPlugin";
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
@ -16,7 +16,7 @@ import { getCaseTypeAmountForUserId } from "./functions/getCaseTypeAmountForUser
import { getRecentCasesByMod } from "./functions/getRecentCasesByMod";
import { getTotalCasesByMod } from "./functions/getTotalCasesByMod";
import { postCaseToCaseLogChannel } from "./functions/postToCaseLogChannel";
import { CaseArgs, CaseNoteArgs, CasesPluginType, ConfigSchema } from "./types";
import { CaseArgs, CaseNoteArgs, CasesPluginType, zCasesConfig } from "./types";
// The `any` cast here is to prevent TypeScript from locking up from the circular dependency
function getLogsPlugin(): Promise<any> {
@ -42,11 +42,11 @@ export const CasesPlugin = zeppelinGuildPlugin<CasesPluginType>()({
description: trimPluginDescription(`
This plugin contains basic configuration for cases created by other plugins
`),
configSchema: ConfigSchema,
configSchema: zCasesConfig,
},
dependencies: async () => [TimeAndDatePlugin, InternalPosterPlugin, (await getLogsPlugin()).LogsPlugin],
configParser: makeIoTsConfigParser(ConfigSchema),
configParser: (input) => zCasesConfig.parse(input),
defaultOptions,
public: {

View file

@ -1,24 +1,26 @@
import * as t from "io-ts";
import { BasePluginType } from "knub";
import { U } from "ts-toolbelt";
import z from "zod";
import { CaseNameToType, CaseTypes } from "../../data/CaseTypes";
import { GuildArchives } from "../../data/GuildArchives";
import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs";
import { tDelayString, tNullable, tPartialDictionary } from "../../utils";
import { tColor } from "../../utils/tColor";
import { keys, zBoundedCharacters, zDelayString, zSnowflake } from "../../utils";
import { zColor } from "../../utils/zColor";
export const ConfigSchema = t.type({
log_automatic_actions: t.boolean,
case_log_channel: tNullable(t.string),
show_relative_times: t.boolean,
relative_time_cutoff: tDelayString,
case_colors: tNullable(tPartialDictionary(t.keyof(CaseNameToType), tColor)),
case_icons: tNullable(tPartialDictionary(t.keyof(CaseNameToType), t.string)),
const caseKeys = keys(CaseNameToType) as U.ListOf<keyof typeof CaseNameToType>;
export const zCasesConfig = z.strictObject({
log_automatic_actions: z.boolean(),
case_log_channel: zSnowflake.nullable(),
show_relative_times: z.boolean(),
relative_time_cutoff: zDelayString.default("1w"),
case_colors: z.record(z.enum(caseKeys), zColor).nullable(),
case_icons: z.record(z.enum(caseKeys), zBoundedCharacters(0, 32)).nullable(),
});
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface CasesPluginType extends BasePluginType {
config: TConfigSchema;
config: z.infer<typeof zCasesConfig>;
state: {
logs: GuildLogs;
cases: GuildCases;