3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +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

@ -1,6 +1,5 @@
import { PluginOptions } from "knub";
import { GuildLogs } from "../../data/GuildLogs";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { trimPluginDescription } from "../../utils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin";
@ -9,13 +8,13 @@ import { AddRoleCmd } from "./commands/AddRoleCmd";
import { MassAddRoleCmd } from "./commands/MassAddRoleCmd";
import { MassRemoveRoleCmd } from "./commands/MassRemoveRoleCmd";
import { RemoveRoleCmd } from "./commands/RemoveRoleCmd";
import { ConfigSchema, RolesPluginType } from "./types";
import { RolesPluginType, zRolesConfig } from "./types";
const defaultOptions: PluginOptions<RolesPluginType> = {
config: {
can_assign: false,
can_mass_assign: false,
assignable_roles: ["558037973581430785"],
assignable_roles: [],
},
overrides: [
{
@ -41,11 +40,11 @@ export const RolesPlugin = zeppelinGuildPlugin<RolesPluginType>()({
description: trimPluginDescription(`
Enables authorised users to add and remove whitelisted roles with a command.
`),
configSchema: ConfigSchema,
configSchema: zRolesConfig,
},
dependencies: () => [LogsPlugin, RoleManagerPlugin],
configParser: makeIoTsConfigParser(ConfigSchema),
configParser: (input) => zRolesConfig.parse(input),
defaultOptions,
// prettier-ignore

View file

@ -1,16 +1,15 @@
import * as t from "io-ts";
import { BasePluginType, guildPluginMessageCommand } from "knub";
import z from "zod";
import { GuildLogs } from "../../data/GuildLogs";
export const ConfigSchema = t.type({
can_assign: t.boolean,
can_mass_assign: t.boolean,
assignable_roles: t.array(t.string),
export const zRolesConfig = z.strictObject({
can_assign: z.boolean(),
can_mass_assign: z.boolean(),
assignable_roles: z.array(z.string()).max(100),
});
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface RolesPluginType extends BasePluginType {
config: TConfigSchema;
config: z.infer<typeof zRolesConfig>;
state: {
logs: GuildLogs;
};