koishi-plugin-echo-cave 1.24.0 → 1.24.1

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.
Files changed (2) hide show
  1. package/lib/index.cjs +13 -7
  2. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -925,7 +925,7 @@ function parseCustomTime(timeStr) {
925
925
  let totalMs = 0;
926
926
  let lastUnit = "";
927
927
  const unitOrder = ["M", "w", "d", "h", "m"];
928
- if (!/^\d+([mhdwM]\d*)*$/.test(timeStr)) {
928
+ if (!/^(\d+[mhdwM])+$/.test(timeStr)) {
929
929
  return null;
930
930
  }
931
931
  while ((match = regex.exec(timeStr)) !== null) {
@@ -941,10 +941,10 @@ function parseCustomTime(timeStr) {
941
941
  }
942
942
  return totalMs;
943
943
  }
944
- function getStartTime(period) {
944
+ function getStartTime(period, customTimeMs) {
945
945
  const now = /* @__PURE__ */ new Date();
946
946
  const startTime = /* @__PURE__ */ new Date();
947
- const customTime = parseCustomTime(period);
947
+ const customTime = customTimeMs !== void 0 ? customTimeMs : parseCustomTime(period);
948
948
  if (customTime !== null) {
949
949
  startTime.setTime(now.getTime() - customTime);
950
950
  return startTime;
@@ -1038,12 +1038,13 @@ async function getRanking(ctx, session, cfg, period = "all") {
1038
1038
  return;
1039
1039
  }
1040
1040
  const normalizedPeriod = period.toLowerCase();
1041
- if (!PREDEFINED_PERIODS.includes(normalizedPeriod) && parseCustomTime(normalizedPeriod) === null) {
1041
+ const customTimeMs = parseCustomTime(normalizedPeriod);
1042
+ if (!PREDEFINED_PERIODS.includes(normalizedPeriod) && customTimeMs === null) {
1042
1043
  await session.send(session.text(".invalidPeriod", [PREDEFINED_PERIODS.join(", ")]));
1043
1044
  return;
1044
1045
  }
1045
1046
  const { channelId } = session;
1046
- const startTime = getStartTime(normalizedPeriod);
1047
+ const startTime = getStartTime(normalizedPeriod, customTimeMs);
1047
1048
  const topCount = cfg.rankingTopCount || 10;
1048
1049
  const caves = await ctx.database.get("echo_cave_v2", {
1049
1050
  channelId,
@@ -1053,8 +1054,13 @@ async function getRanking(ctx, session, cfg, period = "all") {
1053
1054
  });
1054
1055
  const countMap = countUserOccurrences(caves);
1055
1056
  const rankingText = await generateRankingText(ctx, session, countMap, topCount);
1056
- const botName = await getUserName(this.ctx, session, session.bot?.userId) || "Bot";
1057
- const periodText = session.text(`.period.${period}`);
1057
+ const botName = await getUserName(ctx, session, session.bot?.userId) || "Bot";
1058
+ let periodText;
1059
+ if (customTimeMs !== null) {
1060
+ periodText = normalizedPeriod;
1061
+ } else {
1062
+ periodText = session.text(`.period.${normalizedPeriod}`);
1063
+ }
1058
1064
  let title = session.text(".rankingTitle", [periodText]);
1059
1065
  await session.onebot.sendGroupForwardMsg(channelId, [
1060
1066
  createTextMsgNode(session.bot?.userId || session.userId, botName, title),
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.24.0",
4
+ "version": "1.24.1",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",