From 12c391b0c7b70ba083e2bed4050cc784a7a006ce Mon Sep 17 00:00:00 2001 From: Aotumuri Date: Mon, 5 May 2025 13:53:01 +0900 Subject: [PATCH] fixed --- src/core/Schemas.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index c98a4c23d..0eb983a1b 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -1,4 +1,5 @@ -import { z } from "zod"; +import { z, ZodLiteral } from "zod"; +import quickChatData from "../../resources/QuickChat.json" with { type: "json" }; import { AllPlayers, Difficulty, @@ -271,15 +272,23 @@ export const MoveWarshipIntentSchema = BaseIntentSchema.extend({ tile: z.number(), }); +const allowedQuickChatKeys = Object.entries(quickChatData).flatMap( + ([category, entries]) => entries.map((entry) => `${category}.${entry.key}`), +); + +const literals = allowedQuickChatKeys.map((key) => z.literal(key)); + +// ✅ より型安全なアサーション export const QuickChatIntentSchema = BaseIntentSchema.extend({ type: z.literal("quick_chat"), recipient: ID, - quickChatKey: z - .string() - .regex(/^(help|attack|defend|greet|misc)\.[a-zA-Z0-9_]+$/) - .refine((val) => val.split(".")[1]?.length <= 50, { - message: "The key name (after the dot) must be 50 characters or less.", - }), + quickChatKey: z.union( + literals as [ + ZodLiteral, + ZodLiteral, + ...ZodLiteral[], + ], + ), variables: z.record(z.string()).optional(), });