This commit is contained in:
Aotumuri
2025-05-05 13:53:01 +09:00
parent 14186c2ab3
commit 12c391b0c7
+16 -7
View File
@@ -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<string>,
ZodLiteral<string>,
...ZodLiteral<string>[],
],
),
variables: z.record(z.string()).optional(),
});