koishi-plugin-starfx-bot 0.13.0 → 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.
Files changed (3) hide show
  1. package/lib/index.js +16 -19
  2. package/package.json +1 -1
  3. package/readme.md +33 -31
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
- let weightedFiles = [];
76
- if (tag && import_fs.default.existsSync(tagConfigPath)) {
77
- const tagConfigJson = JSON.parse(import_fs.default.readFileSync(tagConfigPath, "utf8") || "{}");
78
- files.forEach((file) => {
79
- const name2 = import_node_path.default.parse(file).name;
80
- const tags = tagConfigJson[name2] || [];
81
- if (tags.includes(tag)) {
82
- for (let i = 0; i < cfg.tagWeight; i++) {
83
- weightedFiles.push(file);
84
- }
85
- } else {
86
- weightedFiles.push(file);
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
- const selected = import_koishi.Random.pick(weightedFiles);
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() {
@@ -166,7 +163,7 @@ async function handleBanGDreamConfig(options) {
166
163
  const types = {
167
164
  cool: ["cool", "blue", "蓝", "蓝色"],
168
165
  powerful: ["powerful", "red", "红", "红色"],
169
- peer: ["peer", "green", "绿", "绿色"],
166
+ pure: ["pure", "green", "绿", "绿色"],
170
167
  happy: ["happy", "orange", "橙", "橙色"]
171
168
  };
172
169
  const bands = {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.13.0",
7
+ "version": "0.13.2",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -44,19 +44,19 @@ StarFreedomX机器人的小功能,自用
44
44
  ### 📌 可配置功能键一览
45
45
 
46
46
 
47
- | 键名 | 功能说明 |
48
- | ---------- | --------------------------------------------- |
49
- | `lock` | 明日方舟封印功能(对应`openLock`) |
50
- | `sold` | 闲鱼“卖掉了”功能(对应`openSold`) |
51
- | `repeat` | 群复读功能(对应`openRepeat`) |
52
- | `record` | 群语录功能(对应`投稿、语录`) |
53
- | `atNotSay` | “艾特我/他又不说话”系列功能 |
54
- | `replyBot` | “我才不是机器人!”系列功能 |
55
- | `iLoveYou` | “我也喜欢你”系列功能 |
47
+ | 键名 | 功能说明 |
48
+ |------------|---------------------------------------|
49
+ | `lock` | 明日方舟封印功能(对应`openLock`) |
50
+ | `sold` | 闲鱼“卖掉了”功能(对应`openSold`) |
51
+ | `repeat` | 群复读功能(对应`openRepeat`) |
52
+ | `record` | 群语录功能(对应`投稿、语录`) |
53
+ | `atNotSay` | “艾特我/他又不说话”系列功能 |
54
+ | `replyBot` | “我才不是机器人!”系列功能 |
55
+ | `iLoveYou` | “我也喜欢你”系列功能 |
56
56
  | `bdbd` | BanG Dream! 边框功能(对应`bangdreamBorder`) |
57
- | `roll` | 随机数功能 |
58
- | `undo` | 撤回功能 |
59
- | `echo` | echo功能 |
57
+ | `roll` | 随机数功能 |
58
+ | `undo` | 撤回功能 |
59
+ | `echo` | echo功能 |
60
60
 
61
61
  ---
62
62
 
@@ -78,23 +78,25 @@ StarFreedomX机器人的小功能,自用
78
78
  ## 更新日志
79
79
 
80
80
 
81
- | 版本 | 更新日志 |
82
- | -------- | -------------------------------------------------- |
83
- | `0.0.1` | 加入封印功能 |
84
- | `0.1.0` | 加入"卖掉了"功能 |
85
- | `0.2.0` | 加入"艾特我又不说话"回复功能 |
86
- | `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
87
- | `0.4.0` | 更改处理库为sharp |
88
- | `0.5.0` | 加入BanG Dream!边框功能 |
89
- | `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
90
- | `0.7.0` | 加入复读功能 |
81
+ | 版本 | 更新日志 |
82
+ |----------|-------------------------------|
83
+ | `0.0.1` | 加入封印功能 |
84
+ | `0.1.0` | 加入"卖掉了"功能 |
85
+ | `0.2.0` | 加入"艾特我又不说话"回复功能 |
86
+ | `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
87
+ | `0.4.0` | 更改处理库为sharp |
88
+ | `0.5.0` | 加入BanG Dream!边框功能 |
89
+ | `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
90
+ | `0.7.0` | 加入复读功能 |
91
91
  | `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
92
- | `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
93
- | `0.10.0` | 添加随机数功能 |
94
- | `0.10.1` | 修复随机数骰子功能输入负数报错的bug |
95
- | `0.10.2` | 增加roll功能的人称变化 |
96
- | `0.11.0` | 增加适配于onebot(主要是qq)的撤回功能 |
97
- | `0.11.1` | 修复bdbd传参错误问题 |
98
- | `0.11.2` | 优化消息捕获图片逻辑 |
99
- | `0.12.0` | 加入echo功能 |
100
- | `0.13.0` | 语录支持tag以及调整权重 |
92
+ | `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
93
+ | `0.10.0` | 添加随机数功能 |
94
+ | `0.10.1` | 修复随机数骰子功能输入负数报错的bug |
95
+ | `0.10.2` | 增加roll功能的人称变化 |
96
+ | `0.11.0` | 增加适配于onebot(主要是qq)的撤回功能 |
97
+ | `0.11.1` | 修复bdbd传参错误问题 |
98
+ | `0.11.2` | 优化消息捕获图片逻辑 |
99
+ | `0.12.0` | 加入echo功能 |
100
+ | `0.13.0` | 语录支持tag以及调整权重 |
101
+ | `0.13.1` | 修复pure类型绘图名称错误 |
102
+ | `0.13.2` | 优化了tag在权重很大情况下的筛选效率 |