koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.53k stars 246 forks source link

Bug: `Schema.dynamic` 设置为数组多选项时不工作 #1475

Open dingyi222666 opened 3 weeks ago

dingyi222666 commented 3 weeks ago

Describe the bug

image

如图,上面 1,2,3 是动态设置的 schema,其中 2,3 是多选的数组,无法显示。4,5是手动设置的 schema,正常显示。

Steps to reproduce

import { Context, Schema } from "koishi";

export const name = "test";

export interface Config {}

enum Intents {
  FOO = 1,
  BAR = 2,
  QUX = 4,
}

export const Config: Schema<Config> = Schema.object({
  dynamicBitset: Schema.dynamic("dynamicBitset"),
  dynamicArray: Schema.dynamic("dynamicArray").role("checkbox"),
  dynamicSelect: Schema.dynamic("dynamicSelect").role("select"),
  bitset: Schema.bitset(Intents)
    .default(Intents.FOO | Intents.QUX)
    .role("checkbox"),
  array: Schema.array(Schema.union(["FOO", "BAR", "QUX"]))
    .default(["FOO", "QUX"])
    .role("select"),
});

export function apply(ctx: Context, config: Config) {
  ctx.schema.set(
    "dynamicBitset",
    Schema.bitset(Intents)
      .default(Intents.FOO | Intents.QUX)
      .role("checkbox")
  );
  ctx.schema.set(
    "dynamicArray",
    Schema.array(Schema.union(["FOO", "BAR", "QUX"]))
  );
  ctx.schema.set(
    "dynamicSelect",
    Schema.array(Schema.union(["FOO", "BAR", "QUX"])).role("select")
  );
}

Expected behavior

全部正常显示。

Screenshots

No response

Versions

Additional context

yarn dev 模式下运行,则所有用 dynamic 设置的 schema 都无法正常显示。

image