mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-17 07:05:03 +00:00
refactor: replace io-ts with zod
This commit is contained in:
parent
fafaefa1fb
commit
28692962bc
161 changed files with 1450 additions and 2105 deletions
|
@ -2,7 +2,6 @@ import { PluginOptions } from "knub";
|
|||
import { Queue } from "../../Queue";
|
||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { makeIoTsConfigParser } from "../../pluginUtils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { ClearReactionRolesCmd } from "./commands/ClearReactionRolesCmd";
|
||||
|
@ -10,7 +9,7 @@ import { InitReactionRolesCmd } from "./commands/InitReactionRolesCmd";
|
|||
import { RefreshReactionRolesCmd } from "./commands/RefreshReactionRolesCmd";
|
||||
import { AddReactionRoleEvt } from "./events/AddReactionRoleEvt";
|
||||
import { MessageDeletedEvt } from "./events/MessageDeletedEvt";
|
||||
import { ConfigSchema, ReactionRolesPluginType } from "./types";
|
||||
import { ReactionRolesPluginType, zReactionRolesConfig } from "./types";
|
||||
|
||||
const MIN_AUTO_REFRESH = 1000 * 60 * 15; // 15min minimum, let's not abuse the API
|
||||
|
||||
|
@ -40,11 +39,11 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin<ReactionRolesPluginType>(
|
|||
info: {
|
||||
prettyName: "Reaction roles",
|
||||
legacy: "Consider using the [Role buttons](/docs/plugins/role_buttons) plugin instead.",
|
||||
configSchema: ConfigSchema,
|
||||
configSchema: zReactionRolesConfig,
|
||||
},
|
||||
|
||||
dependencies: () => [LogsPlugin],
|
||||
configParser: makeIoTsConfigParser(ConfigSchema),
|
||||
configParser: (input) => zReactionRolesConfig.parse(input),
|
||||
defaultOptions,
|
||||
|
||||
// prettier-ignore
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand } from "knub";
|
||||
import z from "zod";
|
||||
import { Queue } from "../../Queue";
|
||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { tNullable } from "../../utils";
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
auto_refresh_interval: t.number,
|
||||
remove_user_reactions: t.boolean,
|
||||
can_manage: t.boolean,
|
||||
button_groups: tNullable(t.unknown),
|
||||
export const zReactionRolesConfig = z.strictObject({
|
||||
auto_refresh_interval: z.number(),
|
||||
remove_user_reactions: z.boolean(),
|
||||
can_manage: z.boolean(),
|
||||
button_groups: z.nullable(z.unknown()),
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
export type RoleChangeMode = "+" | "-";
|
||||
|
||||
|
@ -24,12 +22,14 @@ export type PendingMemberRoleChanges = {
|
|||
}>;
|
||||
};
|
||||
|
||||
const ReactionRolePair = t.union([t.tuple([t.string, t.string, t.string]), t.tuple([t.string, t.string])]);
|
||||
export type TReactionRolePair = t.TypeOf<typeof ReactionRolePair>;
|
||||
type ReactionRolePair = [string, string, string?];
|
||||
const zReactionRolePair = z.union([
|
||||
z.tuple([z.string(), z.string(), z.string()]),
|
||||
z.tuple([z.string(), z.string()]),
|
||||
]);
|
||||
export type TReactionRolePair = z.infer<typeof zReactionRolePair>;
|
||||
|
||||
export interface ReactionRolesPluginType extends BasePluginType {
|
||||
config: TConfigSchema;
|
||||
config: z.infer<typeof zReactionRolesConfig>;
|
||||
state: {
|
||||
reactionRoles: GuildReactionRoles;
|
||||
savedMessages: GuildSavedMessages;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue