koishi-plugin-echo-cave 1.21.0 → 1.22.0

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.
@@ -12,5 +12,6 @@ export interface Config {
12
12
  useBase64ForMedia?: boolean;
13
13
  sendAllAsForwardMsg?: boolean;
14
14
  rankingTopCount?: number;
15
+ considerOriginUserAsRelated?: boolean;
15
16
  }
16
17
  export declare const Config: Schema<Config>;
package/lib/index.cjs CHANGED
@@ -44,7 +44,8 @@ var require_zh_CN = __commonJS({
44
44
  maxRecordSize: "\u6700\u5927\u5F55\u97F3\u5927\u5C0F (MB)",
45
45
  useBase64ForMedia: "\u662F\u5426\u4F7F\u7528 Base64 \u7F16\u7801\u53D1\u9001\u5A92\u4F53\u6587\u4EF6\uFF0C\u5F00\u542F\u540E\u5C06\u8BFB\u53D6 base64 \u7F16\u7801\u53D1\u9001\u800C\u4E0D\u662F\u4F7F\u7528 file uri",
46
46
  sendAllAsForwardMsg: "\u662F\u5426\u5C06\u6240\u6709\u6D88\u606F\u4EE5\u8F6C\u53D1\u6D88\u606F\u5F62\u5F0F\u53D1\u9001\uFF0C\u5F00\u542F\u540E\u666E\u901A\u6D88\u606F\u4E5F\u4F1A\u8F6C\u6362\u4E3A\u8F6C\u53D1\u6D88\u606F\u683C\u5F0F",
47
- rankingTopCount: "\u6392\u884C\u699C\u663E\u793A\u7684\u7528\u6237\u6570\u91CF"
47
+ rankingTopCount: "\u6392\u884C\u699C\u663E\u793A\u7684\u7528\u6237\u6570\u91CF",
48
+ considerOriginUserAsRelated: "\u662F\u5426\u5C06\u539F\u6D88\u606F\u53D1\u9001\u8005\u89C6\u4E3A\u76F8\u5173\u7528\u6237\uFF0C\u9ED8\u8BA4\u4E0D\u8003\u8651"
48
49
  };
49
50
  }
50
51
  });
@@ -179,14 +180,13 @@ var require_zh_CN2 = __commonJS({
179
180
  description: "\u67E5\u770B\u56DE\u58F0\u6D1E\u6392\u884C\u699C",
180
181
  messages: {
181
182
  invalidPeriod: "\u65E0\u6548\u7684\u65F6\u95F4\u6BB5\u53C2\u6570\u3002\u652F\u6301\u7684\u65F6\u95F4\u6BB5\uFF1A{0}",
182
- rankingTitle: "\u{1F4CA} \u56DE\u58F0\u6D1E\u6392\u884C\u699C\uFF08{0}\uFF09",
183
+ rankingTitle: "\u{1F4CA} \u56DE\u58F0\u6D1E\u6392\u884C\u699C ({0})",
183
184
  noData: "\u6682\u65E0\u6570\u636E",
184
- rankFormat: "{0} {1}\uFF1A{2} \u4E2A\u56DE\u58F0\u6D1E",
185
- rankingHeader: "\u4ECA\u65E5\u4EBA\u54C1\u6392\u884C\u699C",
185
+ rankFormat: "{rankEmoji} {userName}\uFF1A{count} \u4E2A\u56DE\u58F0\u6D1E",
186
186
  period: {
187
- day: "24\u5C0F\u65F6",
188
- week: "7\u5929",
189
- month: "1\u4E2A\u6708",
187
+ day: "24 \u5C0F\u65F6",
188
+ week: "7 \u5929",
189
+ month: "1 \u4E2A\u6708",
190
190
  all: "\u6240\u6709\u65F6\u95F4"
191
191
  }
192
192
  }
@@ -916,20 +916,21 @@ function getStartTime(period) {
916
916
  }
917
917
  return startTime;
918
918
  }
919
- function countUserOccurrences(caves) {
919
+ function countUserOccurrences(caves, considerOriginUser) {
920
920
  const countMap = /* @__PURE__ */ new Map();
921
921
  caves.forEach((cave) => {
922
922
  cave.relatedUsers.forEach((userId) => {
923
923
  countMap.set(userId, (countMap.get(userId) || 0) + 1);
924
924
  });
925
- countMap.set(cave.originUserId, (countMap.get(cave.originUserId) || 0) + 1);
925
+ if (considerOriginUser) {
926
+ countMap.set(cave.originUserId, (countMap.get(cave.originUserId) || 0) + 1);
927
+ }
926
928
  });
927
929
  return countMap;
928
930
  }
929
- async function generateRankingText(ctx, session, countMap, period, topCount) {
931
+ async function generateRankingText(ctx, session, countMap, topCount) {
930
932
  const sortedUsers = Array.from(countMap.entries()).sort(([, a], [, b]) => b - a).slice(0, topCount);
931
- const periodText = session.text(`.period.${period}`);
932
- let text = session.text(".rankingTitle", [periodText]) + "\n\n";
933
+ let text = "";
933
934
  if (sortedUsers.length === 0) {
934
935
  text += session.text(".noData");
935
936
  } else {
@@ -949,9 +950,14 @@ async function generateRankingText(ctx, session, countMap, period, topCount) {
949
950
  rankEmoji = "\u{1F949}";
950
951
  break;
951
952
  default:
952
- rankEmoji = `#${rank}`;
953
+ rankEmoji = `${rank}.`;
954
+ }
955
+ const rankData = { rankEmoji, userName, count };
956
+ if (i === sortedUsers.length - 1) {
957
+ text += session.text(".rankFormat", rankData);
958
+ } else {
959
+ text += session.text(".rankFormat", rankData) + "\n";
953
960
  }
954
- text += session.text(".rankFormat", [rankEmoji, userName, count]) + "\n";
955
961
  }
956
962
  }
957
963
  return text;
@@ -975,21 +981,13 @@ async function getRanking(ctx, session, cfg, period = "all") {
975
981
  $gte: startTime
976
982
  }
977
983
  });
978
- const countMap = countUserOccurrences(caves);
979
- const rankingText = await generateRankingText(
980
- ctx,
981
- session,
982
- countMap,
983
- normalizedPeriod,
984
- topCount
985
- );
984
+ const countMap = countUserOccurrences(caves, cfg.considerOriginUserAsRelated || false);
985
+ const rankingText = await generateRankingText(ctx, session, countMap, topCount);
986
986
  const botName = await getUserName(this.ctx, session, session.bot?.userId) || "Bot";
987
+ const periodText = session.text(`.period.${period}`);
988
+ let title = session.text(".rankingTitle", [periodText]);
987
989
  await session.onebot.sendGroupForwardMsg(channelId, [
988
- createTextMsgNode(
989
- session.bot?.userId || session.userId,
990
- botName,
991
- session.text(".rankingHeader")
992
- ),
990
+ createTextMsgNode(session.bot?.userId || session.userId, botName, title),
993
991
  createTextMsgNode(session.bot?.userId || session.userId, botName, rankingText)
994
992
  ]);
995
993
  }
@@ -1044,7 +1042,8 @@ var Config = import_koishi2.Schema.object({
1044
1042
  maxRecordSize: import_koishi2.Schema.number().default(512),
1045
1043
  useBase64ForMedia: import_koishi2.Schema.boolean().default(false),
1046
1044
  sendAllAsForwardMsg: import_koishi2.Schema.boolean().default(false),
1047
- rankingTopCount: import_koishi2.Schema.number().default(10)
1045
+ rankingTopCount: import_koishi2.Schema.number().default(10),
1046
+ considerOriginUserAsRelated: import_koishi2.Schema.boolean().default(true)
1048
1047
  }).i18n({
1049
1048
  "zh-CN": require_zh_CN()
1050
1049
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.21.0",
4
+ "version": "1.22.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",