koishi-plugin-mcdle 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -35,6 +35,7 @@ interface Mcdle {
35
35
  gameEnded: boolean;
36
36
  lastGameStartTime: Date;
37
37
  gameMode: 'mob' | 'item' | 'block' | null;
38
+ formatVersion: number;
38
39
  }
39
40
  interface McdleRank {
40
41
  id: number;
package/lib/index.js CHANGED
@@ -15608,6 +15608,7 @@ var Config = import_koishi.Schema.object({
15608
15608
  allowRepeatedGuesses: import_koishi.Schema.boolean().default(false).description("允许重复猜测已猜过的词语(防止撤回时历史不可见)"),
15609
15609
  disableImages: import_koishi.Schema.boolean().default(false).description("不发送图片,全部改用文本(解决网络问题导致的图片下载失败)")
15610
15610
  });
15611
+ var FORMAT_VERSION = 1;
15611
15612
  function apply(ctx, cfg) {
15612
15613
  ctx.model.extend(
15613
15614
  "mcdle",
@@ -15620,7 +15621,10 @@ function apply(ctx, cfg) {
15620
15621
  dailyPlayedToday: { type: "unsigned", initial: 0 },
15621
15622
  gameEnded: { type: "boolean", initial: true },
15622
15623
  lastGameStartTime: { type: "timestamp", initial: /* @__PURE__ */ new Date(0) },
15623
- gameMode: { type: "string", initial: null }
15624
+ gameMode: { type: "string", initial: null },
15625
+ // 猜测记录的写入格式:旧版本留下的进行中一局无法用现在的图片牌面渲染,
15626
+ // 靠这一列把它们认出来(老行迁移后为 0/null)
15627
+ formatVersion: { type: "unsigned", initial: 0 }
15624
15628
  },
15625
15629
  {
15626
15630
  primary: "channelId"
@@ -15911,6 +15915,18 @@ ${words.join(" ")}`).join("\n\n")
15911
15915
  const record = await ensureRecord(session);
15912
15916
  const now = /* @__PURE__ */ new Date();
15913
15917
  await resetDailyIfNeeded(session, record, now);
15918
+ if (!record.gameEnded && record.formatVersion !== FORMAT_VERSION) {
15919
+ if (record.guesses.length) {
15920
+ await rollbackLegacyGame(session, record, guess, now);
15921
+ return;
15922
+ }
15923
+ await ctx.database.set(
15924
+ "mcdle",
15925
+ { channelId: session.channelId },
15926
+ { formatVersion: FORMAT_VERSION }
15927
+ );
15928
+ record.formatVersion = FORMAT_VERSION;
15929
+ }
15914
15930
  if (record.gameEnded) {
15915
15931
  await startNewGame(session, record, guess, now);
15916
15932
  } else {
@@ -15918,6 +15934,47 @@ ${words.join(" ")}`).join("\n\n")
15918
15934
  }
15919
15935
  }
15920
15936
  __name(c, "c");
15937
+ async function rollbackLegacyGame(session, record, guess, now) {
15938
+ const answerTitle = record.answer?.chinese_title;
15939
+ const history = answerTitle ? record.historyChineseTitles.filter((title) => title !== answerTitle) : record.historyChineseTitles;
15940
+ const refunded = Math.max(0, record.dailyPlayedToday - 1);
15941
+ await ctx.database.set(
15942
+ "mcdle",
15943
+ { channelId: session.channelId },
15944
+ {
15945
+ gameEnded: true,
15946
+ answer: null,
15947
+ guesses: [],
15948
+ guessedChineseTitles: [],
15949
+ gameMode: null,
15950
+ historyChineseTitles: history,
15951
+ dailyPlayedToday: refunded,
15952
+ formatVersion: FORMAT_VERSION
15953
+ }
15954
+ );
15955
+ await sendMsg(
15956
+ session,
15957
+ textCard(
15958
+ "检测到旧版本遗留的一局",
15959
+ "这局是在旧版本下开始的,已有的猜测记录没法用新版图片牌面渲染。",
15960
+ answerTitle ? `「${answerTitle}」已退回词库,之后仍有机会被抽到。` : null,
15961
+ "这一局已作废并退还今日额度,马上为你重新开一局。"
15962
+ )
15963
+ );
15964
+ await startNewGame(
15965
+ session,
15966
+ {
15967
+ ...record,
15968
+ historyChineseTitles: history,
15969
+ dailyPlayedToday: refunded,
15970
+ gameEnded: true,
15971
+ formatVersion: FORMAT_VERSION
15972
+ },
15973
+ guess,
15974
+ now
15975
+ );
15976
+ }
15977
+ __name(rollbackLegacyGame, "rollbackLegacyGame");
15921
15978
  async function startNewGame(session, record, guess, now) {
15922
15979
  if (record.dailyPlayedToday >= cfg.dailyPlayLimit) {
15923
15980
  await sendMsg(
@@ -15945,7 +16002,8 @@ ${words.join(" ")}`).join("\n\n")
15945
16002
  lastGameStartTime: now,
15946
16003
  dailyPlayedToday: played,
15947
16004
  historyChineseTitles: [...record.historyChineseTitles, answer.chinese_title],
15948
- gameMode: mode
16005
+ gameMode: mode,
16006
+ formatVersion: FORMAT_VERSION
15949
16007
  }
15950
16008
  );
15951
16009
  await sendCard(session, startCard(mode, played, cfg.dailyPlayLimit), startText(mode, played));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-mcdle",
3
- "description": "Koishi 的 Minecraft 猜词游戏插件。根据 Minecraft 物品、生物和方块的属性特征,猜测正确的名称。",
4
- "version": "0.1.2",
3
+ "description": "Koishi 的 Minecraft 猜词游戏插件。",
4
+ "version": "0.1.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [