mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-07 16:05:01 +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,15 +1,12 @@
|
|||
import { GuildRoleButtons } from "../../data/GuildRoleButtons";
|
||||
import { parseIoTsSchema, StrictValidationError } from "../../validatorUtils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { resetButtonsCmd } from "./commands/resetButtons";
|
||||
import { onButtonInteraction } from "./events/buttonInteraction";
|
||||
import { applyAllRoleButtons } from "./functions/applyAllRoleButtons";
|
||||
import { createButtonComponents } from "./functions/createButtonComponents";
|
||||
import { TooManyComponentsError } from "./functions/TooManyComponentsError";
|
||||
import { pluginInfo } from "./info";
|
||||
import { ConfigSchema, RoleButtonsPluginType } from "./types";
|
||||
import { RoleButtonsPluginType, zRoleButtonsConfig } from "./types";
|
||||
|
||||
export const RoleButtonsPlugin = zeppelinGuildPlugin<RoleButtonsPluginType>()({
|
||||
name: "role_buttons",
|
||||
|
@ -31,41 +28,7 @@ export const RoleButtonsPlugin = zeppelinGuildPlugin<RoleButtonsPluginType>()({
|
|||
],
|
||||
},
|
||||
|
||||
configParser(input) {
|
||||
// Auto-fill "name" property for buttons based on the object key
|
||||
const seenMessages = new Set();
|
||||
for (const [name, buttonsConfig] of Object.entries<any>((input as any).buttons ?? {})) {
|
||||
if (name.length > 16) {
|
||||
throw new StrictValidationError(["Name for role buttons can be at most 16 characters long"]);
|
||||
}
|
||||
|
||||
if (buttonsConfig) {
|
||||
buttonsConfig.name = name;
|
||||
|
||||
if (buttonsConfig.message) {
|
||||
if ("message_id" in buttonsConfig.message) {
|
||||
if (seenMessages.has(buttonsConfig.message.message_id)) {
|
||||
throw new StrictValidationError(["Can't target the same message with two sets of role buttons"]);
|
||||
}
|
||||
seenMessages.add(buttonsConfig.message.message_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (buttonsConfig.options) {
|
||||
try {
|
||||
createButtonComponents(buttonsConfig);
|
||||
} catch (err) {
|
||||
if (err instanceof TooManyComponentsError) {
|
||||
throw new StrictValidationError(["Too many options; can only have max 5 buttons per row on max 5 rows."]);
|
||||
}
|
||||
throw new StrictValidationError(["Error validating options"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parseIoTsSchema(ConfigSchema, input);
|
||||
},
|
||||
configParser: (input) => zRoleButtonsConfig.parse(input),
|
||||
|
||||
dependencies: () => [LogsPlugin, RoleManagerPlugin],
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue