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 { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { MutesPlugin } from "../Mutes/MutesPlugin";
import { UtilityPlugin } from "../Utility/UtilityPlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { ContextClickedEvt } from "./events/ContextClickedEvt";
import { ConfigSchema, ContextMenuPluginType } from "./types";
import { ContextMenuPluginType, zContextMenusConfig } from "./types";
import { loadAllCommands } from "./utils/loadAllCommands";
const defaultOptions: PluginOptions<ContextMenuPluginType> = {
@ -37,7 +36,7 @@ export const ContextMenuPlugin = zeppelinGuildPlugin<ContextMenuPluginType>()({
showInDocs: false,
dependencies: () => [MutesPlugin, LogsPlugin, UtilityPlugin],
configParser: makeIoTsConfigParser(ConfigSchema),
configParser: (input) => zContextMenusConfig.parse(input),
defaultOptions,
// prettier-ignore

View file

@ -45,9 +45,9 @@ export async function muteAction(
try {
const result = await mutes.muteUser(userId, durationMs, "Context Menu Action", { caseArgs });
const muteMessage = `Muted **${result.case.user_name}** ${
const muteMessage = `Muted **${result.case!.user_name}** ${
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
} (Case #${result.case.case_number}) (user notified via ${
} (Case #${result.case!.case_number}) (user notified via ${
result.notifyResult.method ?? "dm"
})\nPlease update the new case with the \`update\` command`;

View file

@ -1,22 +1,20 @@
import * as t from "io-ts";
import { BasePluginType, guildPluginEventListener } from "knub";
import z from "zod";
import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks";
export const ConfigSchema = t.type({
can_use: t.boolean,
user_muteindef: t.boolean,
user_mute1d: t.boolean,
user_mute1h: t.boolean,
user_info: t.boolean,
message_clean10: t.boolean,
message_clean25: t.boolean,
message_clean50: t.boolean,
export const zContextMenusConfig = z.strictObject({
can_use: z.boolean(),
user_muteindef: z.boolean(),
user_mute1d: z.boolean(),
user_mute1h: z.boolean(),
user_info: z.boolean(),
message_clean10: z.boolean(),
message_clean25: z.boolean(),
message_clean50: z.boolean(),
});
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface ContextMenuPluginType extends BasePluginType {
config: TConfigSchema;
config: z.infer<typeof zContextMenusConfig>;
state: {
contextMenuLinks: GuildContextMenuLinks;
};