koishi-plugin-starfx-bot 0.13.1 → 0.13.2
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 +15 -18
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -72,25 +72,22 @@ async function getRecord(cfg, gid, tag) {
|
|
|
72
72
|
if (!import_fs.default.existsSync(recordDir)) return null;
|
|
73
73
|
const files = import_fs.default.readdirSync(recordDir).filter((file) => /\.(png|jpe?g|webp|gif)$/i.test(file));
|
|
74
74
|
if (!files.length) return null;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
weightedFiles = files;
|
|
75
|
+
const tagConfigJson = import_fs.default.existsSync(tagConfigPath) ? JSON.parse(import_fs.default.readFileSync(tagConfigPath, "utf8") || "{}") : {};
|
|
76
|
+
const weighted = files.map((file) => {
|
|
77
|
+
const name2 = import_node_path.default.parse(file).name;
|
|
78
|
+
const tags = tagConfigJson[name2] || [];
|
|
79
|
+
const weight = tag && tags.includes(tag) ? cfg.tagWeight : 1;
|
|
80
|
+
return { file, weight };
|
|
81
|
+
});
|
|
82
|
+
const totalWeight = weighted.reduce((acc, cur) => acc + cur.weight, 0);
|
|
83
|
+
let rand = Math.random() * totalWeight;
|
|
84
|
+
for (const item of weighted) {
|
|
85
|
+
rand -= item.weight;
|
|
86
|
+
if (rand <= 0) {
|
|
87
|
+
return import_node_path.default.join(recordDir, item.file);
|
|
88
|
+
}
|
|
91
89
|
}
|
|
92
|
-
|
|
93
|
-
return selected ? import_node_path.default.join(recordDir, selected) : null;
|
|
90
|
+
return null;
|
|
94
91
|
}
|
|
95
92
|
__name(getRecord, "getRecord");
|
|
96
93
|
function getTodayPrefix() {
|
package/package.json
CHANGED
package/readme.md
CHANGED