koishi-plugin-echo-cave 1.24.1 → 1.24.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.cjs +16 -22
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -908,36 +908,30 @@ var PREDEFINED_PERIODS = [
|
|
|
908
908
|
"all"
|
|
909
909
|
];
|
|
910
910
|
var TIME_UNITS = {
|
|
911
|
-
m: 60 * 1e3,
|
|
912
|
-
// minutes
|
|
913
|
-
h: 60 * 60 * 1e3,
|
|
914
|
-
// hours
|
|
915
|
-
d: 24 * 60 * 60 * 1e3,
|
|
916
|
-
// days
|
|
911
|
+
m: 30 * 24 * 60 * 60 * 1e3,
|
|
917
912
|
w: 7 * 24 * 60 * 60 * 1e3,
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
// months (approximate)
|
|
913
|
+
d: 24 * 60 * 60 * 1e3,
|
|
914
|
+
h: 60 * 60 * 1e3
|
|
921
915
|
};
|
|
922
916
|
function parseCustomTime(timeStr) {
|
|
923
|
-
|
|
917
|
+
if (!timeStr || typeof timeStr !== "string") return null;
|
|
918
|
+
const s = timeStr.toLowerCase();
|
|
919
|
+
if (!/^(\d+(m|w|d|h))+$/i.test(s)) return null;
|
|
920
|
+
const regex = /(\d+)([mwdh])/g;
|
|
924
921
|
let match;
|
|
925
922
|
let totalMs = 0;
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
while ((match = regex.exec(timeStr)) !== null) {
|
|
932
|
-
const [, value, unit] = match;
|
|
933
|
-
const num = parseInt(value, 10);
|
|
923
|
+
const unitOrder = ["m", "w", "d", "h"];
|
|
924
|
+
let lastIndex = -1;
|
|
925
|
+
while ((match = regex.exec(s)) !== null) {
|
|
926
|
+
const value = parseInt(match[1], 10);
|
|
927
|
+
const unit = match[2].toLowerCase();
|
|
934
928
|
const currentIndex = unitOrder.indexOf(unit);
|
|
935
|
-
|
|
936
|
-
if (
|
|
929
|
+
if (currentIndex === -1) return null;
|
|
930
|
+
if (lastIndex !== -1 && currentIndex < lastIndex) {
|
|
937
931
|
return null;
|
|
938
932
|
}
|
|
939
|
-
totalMs +=
|
|
940
|
-
|
|
933
|
+
totalMs += value * (TIME_UNITS[unit] ?? 0);
|
|
934
|
+
lastIndex = currentIndex;
|
|
941
935
|
}
|
|
942
936
|
return totalMs;
|
|
943
937
|
}
|