koishi-plugin-echo-cave 1.22.1 → 1.23.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,6 +12,5 @@ export interface Config {
12
12
  useBase64ForMedia?: boolean;
13
13
  sendAllAsForwardMsg?: boolean;
14
14
  rankingTopCount?: number;
15
- considerOriginUserAsRelated?: boolean;
16
15
  }
17
16
  export declare const Config: Schema<Config>;
@@ -1,5 +1,5 @@
1
1
  import { Config } from '../../config/config';
2
2
  import { Context, Session } from 'koishi';
3
- export type Period = 'day' | 'week' | 'month' | 'all';
3
+ export type Period = 'lday' | 'lweek' | 'lmonth' | 'day' | 'week' | 'month' | 'all';
4
4
  export declare const SUPPORTED_PERIODS: Period[];
5
5
  export declare function getRanking(ctx: Context, session: Session, cfg: Config, period?: string): Promise<void>;
package/lib/index.cjs CHANGED
@@ -44,8 +44,7 @@ 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",
48
- considerOriginUserAsRelated: "\u662F\u5426\u5C06\u539F\u6D88\u606F\u53D1\u9001\u8005\u89C6\u4E3A\u76F8\u5173\u7528\u6237\uFF0C\u9ED8\u8BA4\u4E0D\u8003\u8651"
47
+ rankingTopCount: "\u6392\u884C\u699C\u663E\u793A\u7684\u7528\u6237\u6570\u91CF"
49
48
  };
50
49
  }
51
50
  });
@@ -176,7 +175,7 @@ var require_zh_CN2 = __commonJS({
176
175
  userBoundSuccess: "\u2705 \u5DF2\u6210\u529F\u5C06\u7528\u6237\u7ED1\u5B9A\u5230\u56DE\u58F0\u6D1E #{0}\uFF01"
177
176
  }
178
177
  },
179
- "cave.ranking": {
178
+ "cave.rank": {
180
179
  description: "\u67E5\u770B\u56DE\u58F0\u6D1E\u6392\u884C\u699C",
181
180
  messages: {
182
181
  invalidPeriod: "\u65E0\u6548\u7684\u65F6\u95F4\u6BB5\u53C2\u6570\u3002\u652F\u6301\u7684\u65F6\u95F4\u6BB5\uFF1A{0}",
@@ -184,9 +183,12 @@ var require_zh_CN2 = __commonJS({
184
183
  noData: "\u6682\u65E0\u6570\u636E",
185
184
  rankFormat: "{rankEmoji} {userName}\uFF1A{count} \u4E2A\u56DE\u58F0\u6D1E",
186
185
  period: {
187
- day: "24 \u5C0F\u65F6",
188
- week: "7 \u5929",
189
- month: "1 \u4E2A\u6708",
186
+ lday: "\u8FC7\u53BB 24 \u5C0F\u65F6",
187
+ lweek: "\u8FC7\u53BB 7 \u5929",
188
+ lmonth: "\u8FC7\u53BB 30 \u5929",
189
+ day: "\u4ECA\u5929",
190
+ week: "\u672C\u5468",
191
+ month: "\u672C\u6708",
190
192
  all: "\u6240\u6709\u65F6\u95F4"
191
193
  }
192
194
  }
@@ -895,35 +897,60 @@ async function bindUsersToCave(ctx, session, id, userIds) {
895
897
  return session.text(".userBoundSuccess", [id]);
896
898
  }
897
899
 
898
- // src/core/command/ranking.ts
899
- var SUPPORTED_PERIODS = ["day", "week", "month", "all"];
900
+ // src/core/command/rank.ts
901
+ var SUPPORTED_PERIODS = [
902
+ "lday",
903
+ "lweek",
904
+ "lmonth",
905
+ "day",
906
+ "week",
907
+ "month",
908
+ "all"
909
+ ];
900
910
  function getStartTime(period) {
901
911
  const now = /* @__PURE__ */ new Date();
902
912
  const startTime = /* @__PURE__ */ new Date();
903
913
  switch (period) {
904
- case "day":
914
+ // Last day/week/month (previous 24h, 7d, 30d)
915
+ case "lday":
905
916
  startTime.setDate(now.getDate() - 1);
906
917
  break;
907
- case "week":
918
+ case "lweek":
908
919
  startTime.setDate(now.getDate() - 7);
909
920
  break;
921
+ case "lmonth":
922
+ startTime.setDate(now.getDate() - 30);
923
+ break;
924
+ // This day/week/month (from start of period to now)
925
+ case "day":
926
+ startTime.setHours(0, 0, 0, 0);
927
+ break;
928
+ case "week":
929
+ const dayOfWeek = now.getDay();
930
+ const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1;
931
+ startTime.setDate(now.getDate() - daysToMonday);
932
+ startTime.setHours(0, 0, 0, 0);
933
+ break;
910
934
  case "month":
911
- startTime.setMonth(now.getMonth() - 1);
935
+ startTime.setDate(1);
936
+ startTime.setHours(0, 0, 0, 0);
912
937
  break;
938
+ // All time
913
939
  case "all":
914
940
  startTime.setTime(0);
915
941
  break;
916
942
  }
917
943
  return startTime;
918
944
  }
919
- function countUserOccurrences(caves, considerOriginUser) {
945
+ function countUserOccurrences(caves) {
920
946
  const countMap = /* @__PURE__ */ new Map();
921
947
  caves.forEach((cave) => {
922
- cave.relatedUsers.forEach((userId) => {
923
- countMap.set(userId, (countMap.get(userId) || 0) + 1);
924
- });
925
- if (considerOriginUser) {
948
+ if (cave.relatedUsers.length === 0) {
926
949
  countMap.set(cave.originUserId, (countMap.get(cave.originUserId) || 0) + 1);
950
+ } else {
951
+ cave.relatedUsers.forEach((userId) => {
952
+ countMap.set(userId, (countMap.get(userId) || 0) + 1);
953
+ });
927
954
  }
928
955
  });
929
956
  return countMap;
@@ -981,7 +1008,7 @@ async function getRanking(ctx, session, cfg, period = "all") {
981
1008
  $gte: startTime
982
1009
  }
983
1010
  });
984
- const countMap = countUserOccurrences(caves, cfg.considerOriginUserAsRelated || false);
1011
+ const countMap = countUserOccurrences(caves);
985
1012
  const rankingText = await generateRankingText(ctx, session, countMap, topCount);
986
1013
  const botName = await getUserName(this.ctx, session, session.bot?.userId) || "Bot";
987
1014
  const periodText = session.text(`.period.${period}`);
@@ -1042,8 +1069,7 @@ var Config = import_koishi2.Schema.object({
1042
1069
  maxRecordSize: import_koishi2.Schema.number().default(512),
1043
1070
  useBase64ForMedia: import_koishi2.Schema.boolean().default(false),
1044
1071
  sendAllAsForwardMsg: import_koishi2.Schema.boolean().default(false),
1045
- rankingTopCount: import_koishi2.Schema.number().default(10),
1046
- considerOriginUserAsRelated: import_koishi2.Schema.boolean().default(true)
1072
+ rankingTopCount: import_koishi2.Schema.number().default(10)
1047
1073
  }).i18n({
1048
1074
  "zh-CN": require_zh_CN()
1049
1075
  });
@@ -1119,7 +1145,7 @@ function apply(ctx, cfg) {
1119
1145
  ctx.command("cave.bind <id:number> <...userIds>", { authority: 4 }).action(
1120
1146
  async ({ session }, id, ...userIds) => await bindUsersToCave(ctx, session, id, userIds)
1121
1147
  );
1122
- ctx.command("cave.ranking [period:string]").action(
1148
+ ctx.command("cave.rank [period:string]").action(
1123
1149
  async ({ session }, period) => await getRanking(ctx, session, cfg, period)
1124
1150
  );
1125
1151
  }
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.22.1",
4
+ "version": "1.23.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",