mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:41:36 +00:00
Discord: refine presence config defaults (#10855) (thanks @h0tp-ftw)
This commit is contained in:
@@ -335,11 +335,42 @@ export const DiscordAccountSchema = z
|
||||
activity: z.string().optional(),
|
||||
status: z.enum(["online", "dnd", "idle", "invisible"]).optional(),
|
||||
activityType: z
|
||||
.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(5)])
|
||||
.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)])
|
||||
.optional(),
|
||||
activityUrl: z.string().optional(),
|
||||
activityUrl: z.string().url().optional(),
|
||||
})
|
||||
.strict();
|
||||
.strict()
|
||||
.superRefine((value, ctx) => {
|
||||
const activityText = typeof value.activity === "string" ? value.activity.trim() : "";
|
||||
const hasActivity = Boolean(activityText);
|
||||
const hasActivityType = value.activityType !== undefined;
|
||||
const activityUrl = typeof value.activityUrl === "string" ? value.activityUrl.trim() : "";
|
||||
const hasActivityUrl = Boolean(activityUrl);
|
||||
|
||||
if ((hasActivityType || hasActivityUrl) && !hasActivity) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "channels.discord.activity is required when activityType or activityUrl is set",
|
||||
path: ["activity"],
|
||||
});
|
||||
}
|
||||
|
||||
if (value.activityType === 1 && !hasActivityUrl) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "channels.discord.activityUrl is required when activityType is 1 (Streaming)",
|
||||
path: ["activityUrl"],
|
||||
});
|
||||
}
|
||||
|
||||
if (hasActivityUrl && value.activityType !== 1) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "channels.discord.activityType must be 1 (Streaming) when activityUrl is set",
|
||||
path: ["activityType"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const DiscordConfigSchema = DiscordAccountSchema.extend({
|
||||
accounts: z.record(z.string(), DiscordAccountSchema.optional()).optional(),
|
||||
|
||||
Reference in New Issue
Block a user