mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-08 03:27:20 +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
|
@ -1,11 +1,10 @@
|
|||
import { CooldownManager } from "knub";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { makeIoTsConfigParser } from "../../pluginUtils";
|
||||
import { trimPluginDescription } from "../../utils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { VoiceStateUpdateEvt } from "./events/VoiceStateUpdateEvt";
|
||||
import { CompanionChannelsPluginType, ConfigSchema } from "./types";
|
||||
import { CompanionChannelsPluginType, zCompanionChannelsConfig } from "./types";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -23,11 +22,11 @@ export const CompanionChannelsPlugin = zeppelinGuildPlugin<CompanionChannelsPlug
|
|||
Once set up, any time a user joins one of the specified voice channels,
|
||||
they'll get channel permissions applied to them for the text channels.
|
||||
`),
|
||||
configSchema: ConfigSchema,
|
||||
configSchema: zCompanionChannelsConfig,
|
||||
},
|
||||
|
||||
dependencies: () => [LogsPlugin],
|
||||
configParser: makeIoTsConfigParser(ConfigSchema),
|
||||
configParser: (input) => zCompanionChannelsConfig.parse(input),
|
||||
defaultOptions,
|
||||
|
||||
events: [VoiceStateUpdateEvt],
|
||||
|
|
|
@ -1,28 +1,23 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, CooldownManager, guildPluginEventListener } from "knub";
|
||||
import z from "zod";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { tNullable } from "../../utils";
|
||||
import { zBoundedCharacters, zSnowflake } from "../../utils";
|
||||
|
||||
// Permissions using these numbers: https://abal.moe/Eris/docs/reference (add all allowed/denied ones up)
|
||||
export const CompanionChannelOpts = t.type({
|
||||
voice_channel_ids: t.array(t.string),
|
||||
text_channel_ids: t.array(t.string),
|
||||
permissions: t.number,
|
||||
enabled: tNullable(t.boolean),
|
||||
export const zCompanionChannelOpts = z.strictObject({
|
||||
voice_channel_ids: z.array(zSnowflake),
|
||||
text_channel_ids: z.array(zSnowflake),
|
||||
// See https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags
|
||||
permissions: z.number(),
|
||||
enabled: z.boolean().nullable().default(true),
|
||||
});
|
||||
export type TCompanionChannelOpts = t.TypeOf<typeof CompanionChannelOpts>;
|
||||
export type TCompanionChannelOpts = z.infer<typeof zCompanionChannelOpts>;
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
entries: t.record(t.string, CompanionChannelOpts),
|
||||
export const zCompanionChannelsConfig = z.strictObject({
|
||||
entries: z.record(zBoundedCharacters(0, 100), zCompanionChannelOpts),
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
export interface ICompanionChannelMap {
|
||||
[channelId: string]: TCompanionChannelOpts;
|
||||
}
|
||||
|
||||
export interface CompanionChannelsPluginType extends BasePluginType {
|
||||
config: TConfigSchema;
|
||||
config: z.infer<typeof zCompanionChannelsConfig>;
|
||||
state: {
|
||||
errorCooldownManager: CooldownManager;
|
||||
serverLogs: GuildLogs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue