mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 10:32:43 +00:00
refactor(config): dedupe irc schema refinements
This commit is contained in:
@@ -740,7 +740,9 @@ export const IrcAccountSchemaBase = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) => {
|
type IrcBaseConfig = z.infer<typeof IrcAccountSchemaBase>;
|
||||||
|
|
||||||
|
function refineIrcAllowFromAndNickserv(value: IrcBaseConfig, ctx: z.RefinementCtx): void {
|
||||||
requireOpenAllowFrom({
|
requireOpenAllowFrom({
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
@@ -755,25 +757,16 @@ export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) =>
|
|||||||
message: "channels.irc.nickserv.register=true requires channels.irc.nickserv.registerEmail",
|
message: "channels.irc.nickserv.register=true requires channels.irc.nickserv.registerEmail",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) => {
|
||||||
|
refineIrcAllowFromAndNickserv(value, ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const IrcConfigSchema = IrcAccountSchemaBase.extend({
|
export const IrcConfigSchema = IrcAccountSchemaBase.extend({
|
||||||
accounts: z.record(z.string(), IrcAccountSchema.optional()).optional(),
|
accounts: z.record(z.string(), IrcAccountSchema.optional()).optional(),
|
||||||
}).superRefine((value, ctx) => {
|
}).superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
refineIrcAllowFromAndNickserv(value, ctx);
|
||||||
policy: value.dmPolicy,
|
|
||||||
allowFrom: value.allowFrom,
|
|
||||||
ctx,
|
|
||||||
path: ["allowFrom"],
|
|
||||||
message: 'channels.irc.dmPolicy="open" requires channels.irc.allowFrom to include "*"',
|
|
||||||
});
|
|
||||||
if (value.nickserv?.register && !value.nickserv.registerEmail?.trim()) {
|
|
||||||
ctx.addIssue({
|
|
||||||
code: z.ZodIssueCode.custom,
|
|
||||||
path: ["nickserv", "registerEmail"],
|
|
||||||
message: "channels.irc.nickserv.register=true requires channels.irc.nickserv.registerEmail",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const IMessageAccountSchemaBase = z
|
export const IMessageAccountSchemaBase = z
|
||||||
|
|||||||
Reference in New Issue
Block a user