koishi-plugin-starfx-bot 0.13.1 → 0.13.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.js +17 -20
- package/package.json +1 -1
- package/readme.md +2 -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() {
|
|
@@ -505,13 +502,13 @@ function apply(ctx, cfg) {
|
|
|
505
502
|
if (cfg.openLock) {
|
|
506
503
|
ctx.command("封印 [param]").action(async ({ session }, param) => {
|
|
507
504
|
if (detectControl(controlJson, session.guildId, "lock"))
|
|
508
|
-
|
|
505
|
+
await session.send(await drawLock(ctx, await getImageSrc(session, param)));
|
|
509
506
|
});
|
|
510
507
|
}
|
|
511
508
|
if (cfg.openSold) {
|
|
512
509
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
513
510
|
if (detectControl(controlJson, session.guildId, "sold"))
|
|
514
|
-
|
|
511
|
+
await session.send(await drawSold(ctx, await getImageSrc(session, param)));
|
|
515
512
|
});
|
|
516
513
|
}
|
|
517
514
|
if (cfg.roll) {
|
package/package.json
CHANGED