3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +00:00

chore: run prettier

This commit is contained in:
Dragory 2024-01-27 14:23:13 +02:00
parent 77ab2718e7
commit 873bf7eb99
No known key found for this signature in database
54 changed files with 462 additions and 416 deletions

View file

@ -11,89 +11,99 @@ const zRoleButtonOption = z.strictObject({
label: z.string().nullable().default(null),
emoji: z.string().nullable().default(null),
// https://discord.js.org/#/docs/discord.js/v13/typedef/MessageButtonStyle
style: z.union([
z.literal(ButtonStyle.Primary),
z.literal(ButtonStyle.Secondary),
z.literal(ButtonStyle.Success),
z.literal(ButtonStyle.Danger),
style: z
.union([
z.literal(ButtonStyle.Primary),
z.literal(ButtonStyle.Secondary),
z.literal(ButtonStyle.Success),
z.literal(ButtonStyle.Danger),
// The following are deprecated
z.literal("PRIMARY"),
z.literal("SECONDARY"),
z.literal("SUCCESS"),
z.literal("DANGER"),
// z.literal("LINK"), // Role buttons don't use link buttons, but adding this here so it's documented why it's not available
]).nullable().default(null),
// The following are deprecated
z.literal("PRIMARY"),
z.literal("SECONDARY"),
z.literal("SUCCESS"),
z.literal("DANGER"),
// z.literal("LINK"), // Role buttons don't use link buttons, but adding this here so it's documented why it's not available
])
.nullable()
.default(null),
start_new_row: z.boolean().default(false),
});
export type TRoleButtonOption = z.infer<typeof zRoleButtonOption>;
const zRoleButtonsConfigItem = z.strictObject({
// Typed as "never" because you are not expected to supply this directly.
// The transform instead picks it up from the property key and the output type is a string.
name: z.never().optional().transform((_, ctx) => {
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
if (! ruleName) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Role buttons must have names",
});
return z.NEVER;
}
return ruleName;
}),
message: z.union([
z.strictObject({
channel_id: zSnowflake,
message_id: zSnowflake,
}),
z.strictObject({
channel_id: zSnowflake,
content: zMessageContent,
}),
]),
options: z.array(zRoleButtonOption).max(25),
exclusive: z.boolean().default(false),
})
.refine((parsed) => {
try {
createButtonComponents(parsed);
} catch (err) {
if (err instanceof TooManyComponentsError) {
return false;
const zRoleButtonsConfigItem = z
.strictObject({
// Typed as "never" because you are not expected to supply this directly.
// The transform instead picks it up from the property key and the output type is a string.
name: z
.never()
.optional()
.transform((_, ctx) => {
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
if (!ruleName) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Role buttons must have names",
});
return z.NEVER;
}
return ruleName;
}),
message: z.union([
z.strictObject({
channel_id: zSnowflake,
message_id: zSnowflake,
}),
z.strictObject({
channel_id: zSnowflake,
content: zMessageContent,
}),
]),
options: z.array(zRoleButtonOption).max(25),
exclusive: z.boolean().default(false),
})
.refine(
(parsed) => {
try {
createButtonComponents(parsed);
} catch (err) {
if (err instanceof TooManyComponentsError) {
return false;
}
throw err;
}
throw err;
}
return true;
}, {
message: "Too many options; can only have max 5 buttons per row on max 5 rows."
});
return true;
},
{
message: "Too many options; can only have max 5 buttons per row on max 5 rows.",
},
);
export type TRoleButtonsConfigItem = z.infer<typeof zRoleButtonsConfigItem>;
export const zRoleButtonsConfig = z.strictObject({
buttons: zBoundedRecord(
z.record(zBoundedCharacters(1, 16), zRoleButtonsConfigItem),
0,
100,
),
can_reset: z.boolean(),
})
.refine((parsed) => {
const seenMessages = new Set();
for (const button of Object.values(parsed.buttons)) {
if (button.message) {
if ("message_id" in button.message) {
if (seenMessages.has(button.message.message_id)) {
return false;
export const zRoleButtonsConfig = z
.strictObject({
buttons: zBoundedRecord(z.record(zBoundedCharacters(1, 16), zRoleButtonsConfigItem), 0, 100),
can_reset: z.boolean(),
})
.refine(
(parsed) => {
const seenMessages = new Set();
for (const button of Object.values(parsed.buttons)) {
if (button.message) {
if ("message_id" in button.message) {
if (seenMessages.has(button.message.message_id)) {
return false;
}
seenMessages.add(button.message.message_id);
}
seenMessages.add(button.message.message_id);
}
}
}
return true;
}, {
message: "Can't target the same message with two sets of role buttons",
});
return true;
},
{
message: "Can't target the same message with two sets of role buttons",
},
);
export interface RoleButtonsPluginType extends BasePluginType {
config: z.infer<typeof zRoleButtonsConfig>;