koishi-plugin-ciyi 1.2.3 → 1.2.5

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.js CHANGED
@@ -709,7 +709,7 @@ function renderWinCard(service, opts) {
709
709
  textLeft(ctx, stats[i].c, sx + s(14), y + s(44), `${s(10.5)}px ${FONT_SERIF}`, C.ink3);
710
710
  }
711
711
  const quip = opts.closest === null ? "一击即中,今日无需第二次落笔" : `从 #${opts.closest} 一步跨到 #1`;
712
- const footerTip = "明日零点换新题 · ciyi.排行榜";
712
+ const footerTip = opts.canStartToday ? "ciyi.猜 山水 · 开启今日新题" : "明日零点换新题 · ciyi.排行榜";
713
713
  drawFooter(
714
714
  ctx,
715
715
  ix,
@@ -734,8 +734,15 @@ function renderWinCard(service, opts) {
734
734
  __name(renderWinCard, "renderWinCard");
735
735
  function renderRankCard(service, opts) {
736
736
  const innerW = s(620);
737
- const rowCount = Math.max(opts.entries.length, 1);
738
- const innerH = s(120 + rowCount * 52 + (opts.hidden > 0 ? 36 : 0) + 60);
737
+ const headerH = s(87);
738
+ const contentGap = s(20);
739
+ const rowH = s(52);
740
+ const emptyH = s(92);
741
+ const hiddenH = opts.hidden > 0 ? s(36) : 0;
742
+ const footerGap = s(20);
743
+ const footerH = s(60);
744
+ const contentH = opts.entries.length ? opts.entries.length * rowH + hiddenH : emptyH;
745
+ const innerH = headerH + contentGap + contentH + footerGap + footerH;
739
746
  return toPng(service, innerW, innerH, (ctx, ix, iy, iw, ih) => {
740
747
  let y = iy + drawHeader(ctx, ix, iy, iw, "每日挑战 · 累计猜中", {
741
748
  big: String(opts.players),
@@ -743,11 +750,12 @@ function renderRankCard(service, opts) {
743
750
  });
744
751
  y += s(20);
745
752
  if (!opts.entries.length) {
753
+ drawPanel(ctx, ix + s(22), y, iw - s(44), emptyH);
746
754
  textCenter(
747
755
  ctx,
748
756
  "榜上无名。",
749
757
  ix + iw / 2,
750
- y + s(40),
758
+ y + s(31),
751
759
  `${s(13.5)}px ${FONT_SERIF}`,
752
760
  C.ink3
753
761
  );
@@ -755,7 +763,7 @@ function renderRankCard(service, opts) {
755
763
  ctx,
756
764
  "今日第一个猜中的人,会写在这里。",
757
765
  ix + iw / 2,
758
- y + s(68),
766
+ y + s(61),
759
767
  `${s(13.5)}px ${FONT_SERIF}`,
760
768
  C.ink3
761
769
  );
@@ -763,7 +771,6 @@ function renderRankCard(service, opts) {
763
771
  let ry = y;
764
772
  for (let i = 0; i < opts.entries.length; i++) {
765
773
  const e = opts.entries[i];
766
- const rowH = s(52);
767
774
  const midY = ry + rowH / 2;
768
775
  if (e.me) {
769
776
  ctx.fillStyle = "rgba(178,58,46,0.055)";
@@ -793,9 +800,13 @@ function renderRankCard(service, opts) {
793
800
  const name2 = e.username || "无名氏";
794
801
  const nameX = px + posSize + s(14);
795
802
  const nameFont = `${s(15)}px ${FONT_SERIF}`;
803
+ const score = String(e.score);
804
+ const scoreRight = ix + iw - s(38);
805
+ const scoreLeft = scoreRight - textWidth(score, s(19));
806
+ const meWidth = e.me ? textWidth("我", s(10.5)) + s(18) : 0;
796
807
  const fittedName = ellipsize(
797
808
  name2,
798
- ix + iw - s(118) - nameX - (e.me ? s(28) : 0),
809
+ Math.max(0, scoreLeft - s(18) - nameX - meWidth),
799
810
  s(15)
800
811
  );
801
812
  textLeft(ctx, fittedName, nameX, midY, nameFont, C.ink);
@@ -805,8 +816,8 @@ function renderRankCard(service, opts) {
805
816
  }
806
817
  textRight(
807
818
  ctx,
808
- String(e.score),
809
- ix + iw - s(38),
819
+ score,
820
+ scoreRight,
810
821
  midY,
811
822
  `700 ${s(19)}px ${FONT_NUM}`,
812
823
  C.ink
@@ -868,8 +879,8 @@ var usage = `# 词意
868
879
  var inject = { required: ["database"], optional: ["canvas"] };
869
880
  var Config = import_koishi.Schema.object({
870
881
  atReply: import_koishi.Schema.boolean().default(false).description("响应时 @"),
871
- quoteReply: import_koishi.Schema.boolean().default(true).description("响应时引用"),
872
- isEnableMiddleware: import_koishi.Schema.boolean().default(false).description("是否启用中间件(若启用,猜测词语时可以不使用指令直接猜测)"),
882
+ quoteReply: import_koishi.Schema.boolean().default(false).description("响应时引用"),
883
+ isEnableMiddleware: import_koishi.Schema.boolean().default(true).description("是否启用中间件(若启用,猜测词语时可以不使用指令直接猜测)"),
873
884
  renderImage: import_koishi.Schema.boolean().default(true).description("渲染图片(复用 Koishi Canvas 服务;不可用时使用等价文本)"),
874
885
  maxHistory: import_koishi.Schema.number().default(10).min(0).description("猜测板最多列出的历史条数(最新一次猜测始终会列出)"),
875
886
  maxRank: import_koishi.Schema.number().default(10).min(0).description("最大排行榜人数")
@@ -1041,7 +1052,7 @@ function apply(ctx, cfg) {
1041
1052
  `累计 ${o.username} 已猜中 ${o.score} 次`,
1042
1053
  o.neighbors.length ? `近旁 ${o.neighbors.join(" · ")}` : null
1043
1054
  ].filter(Boolean),
1044
- "明日零点换新题 · ciyi.排行榜 看战绩"
1055
+ o.canStartToday ? "继续 ciyi.猜 山水 · 开启今日新题" : "明日零点换新题 · ciyi.排行榜 看战绩"
1045
1056
  );
1046
1057
  }
1047
1058
  __name(winText, "winText");
@@ -1119,7 +1130,7 @@ function apply(ctx, cfg) {
1119
1130
  __name(phb, "phb");
1120
1131
  async function getTodayGame(session) {
1121
1132
  const current = (await ctx.database.get("ciyi", { channelId: session.channelId }))[0];
1122
- if (current && isSameDayInChina(session.timestamp, current.lastStartTimestamp)) {
1133
+ if (current && (!current.isOver || isSameDayInChina(session.timestamp, current.lastStartTimestamp))) {
1123
1134
  return current;
1124
1135
  }
1125
1136
  const oldGuessedWords = current?.guessedWords ?? [];
@@ -1214,7 +1225,11 @@ function apply(ctx, cfg) {
1214
1225
  // 榜首是答案自己,紧随其后的几个才是「最像它的词」
1215
1226
  neighbors: gameInfo.rankList.slice(1, 6),
1216
1227
  username: session.username,
1217
- score
1228
+ score,
1229
+ canStartToday: !isSameDayInChina(
1230
+ session.timestamp,
1231
+ gameInfo.lastStartTimestamp
1232
+ )
1218
1233
  };
1219
1234
  return await sendCard(session, () => renderWinCard(ctx.canvas, win), winText(win));
1220
1235
  }
package/lib/view.d.ts CHANGED
@@ -38,6 +38,7 @@ export interface WinOptions {
38
38
  neighbors: string[];
39
39
  username: string;
40
40
  score: number;
41
+ canStartToday: boolean;
41
42
  }
42
43
  export interface RankEntry {
43
44
  username: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ciyi",
3
3
  "description": "Koishi 的词意(猜词游戏)插件。根据词语的含义相似程度,猜测正确的词语。",
4
- "version": "1.2.3",
4
+ "version": "1.2.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [