koishi-plugin-starfx-bot 0.12.0 → 0.13.0

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.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface Config {
9
9
  openSold: boolean;
10
10
  bangdreamBorder: boolean;
11
11
  record: boolean;
12
+ tagWeight: number;
12
13
  saveArchive: boolean;
13
14
  roll: boolean;
14
15
  undo: boolean;
@@ -30,6 +31,7 @@ export declare const Config: Schema<Schemastery.ObjectS<{
30
31
  bangdreamBorder: Schema<boolean, boolean>;
31
32
  }> | Schemastery.ObjectS<{
32
33
  record: Schema<boolean, boolean>;
34
+ tagWeight: Schema<number, number>;
33
35
  saveArchive: Schema<boolean, boolean>;
34
36
  }> | Schemastery.ObjectS<{
35
37
  roll: Schema<boolean, boolean>;
@@ -54,6 +56,7 @@ export declare const Config: Schema<Schemastery.ObjectS<{
54
56
  bangdreamBorder: boolean;
55
57
  } & import("cosmokit").Dict & {
56
58
  record: boolean;
59
+ tagWeight: number;
57
60
  saveArchive: boolean;
58
61
  } & {
59
62
  roll: boolean;
package/lib/index.js CHANGED
@@ -66,10 +66,31 @@ async function addRecord(ctx, gid, avatarUrl) {
66
66
  return "投稿收到啦";
67
67
  }
68
68
  __name(addRecord, "addRecord");
69
- async function getRecord(gid) {
70
- const recordDir = `${assetsDir}/record/${gid}`;
71
- const files = import_fs.default.readdirSync(recordDir);
72
- return files?.length ? import_node_path.default.join(recordDir, import_koishi.Random.pick(files)) : null;
69
+ async function getRecord(cfg, gid, tag) {
70
+ const tagConfigPath = import_node_path.default.join(assetsDir, "tagConfig", `${gid}.json`);
71
+ const recordDir = import_node_path.default.join(assetsDir, "record", gid);
72
+ if (!import_fs.default.existsSync(recordDir)) return null;
73
+ const files = import_fs.default.readdirSync(recordDir).filter((file) => /\.(png|jpe?g|webp|gif)$/i.test(file));
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;
91
+ }
92
+ const selected = import_koishi.Random.pick(weightedFiles);
93
+ return selected ? import_node_path.default.join(recordDir, selected) : null;
73
94
  }
74
95
  __name(getRecord, "getRecord");
75
96
  function getTodayPrefix() {
@@ -447,6 +468,7 @@ var Config2 = import_koishi2.Schema.intersect([
447
468
  }).description("绘图功能"),
448
469
  import_koishi2.Schema.object({
449
470
  record: import_koishi2.Schema.boolean().default(true).description("开启群语录功能"),
471
+ tagWeight: import_koishi2.Schema.number().default(5).min(1).description("tag匹配时的权重,越高权重越大"),
450
472
  saveArchive: import_koishi2.Schema.boolean().default(false).description("开启入典功能").hidden()
451
473
  }).description("语录记录功能"),
452
474
  import_koishi2.Schema.object({
@@ -546,9 +568,9 @@ function apply(ctx, cfg) {
546
568
  return await addRecord(ctx, session.gid.replace(":", "_"), imageSrc);
547
569
  }
548
570
  });
549
- ctx.command("语录").action(async ({ session }) => {
571
+ ctx.command("语录 [tag:string]").action(async ({ session }, tag) => {
550
572
  if (detectControl(controlJson, session.guildId, "record")) {
551
- const filepath = await getRecord(session.gid.replace(":", "_"));
573
+ const filepath = await getRecord(cfg, session.gid.replace(":", "_"), tag);
552
574
  starfxLogger.info(`send record: ${filepath}`);
553
575
  if (!filepath) return "暂无语录呢";
554
576
  return import_koishi2.h.image(filepath);
@@ -588,6 +610,11 @@ function apply(ctx, cfg) {
588
610
  await iLoveYou(cfg, session, elements);
589
611
  return next();
590
612
  });
613
+ if (process.env.NODE_ENV === "development") {
614
+ ctx.command("test").action(async ({ session }) => {
615
+ await session.send(import_koishi2.h.video("https://video.twimg.com/amplify_video/1920672748596043776/vid/avc1/1080x1920/c3BNP3qg4-sT82fR.mp4?tag=21"));
616
+ });
617
+ }
591
618
  function initAssets() {
592
619
  const fromUrl = `${__dirname}/../assets`;
593
620
  assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
package/lib/utils.d.ts CHANGED
@@ -16,10 +16,12 @@ interface FeatureControl {
16
16
  export declare function addRecord(ctx: Context, gid: string, avatarUrl: string): Promise<string>;
17
17
  /**
18
18
  * 从当前群组的语录中随机获取一张,同样需要把gid的:替换为_
19
+ * @param cfg
19
20
  * @param gid
21
+ * @param tag
20
22
  * @return 图片的文件路径
21
23
  */
22
- export declare function getRecord(gid: string): Promise<string>;
24
+ export declare function getRecord(cfg: Config, gid: string, tag: string): Promise<string | null>;
23
25
  /**
24
26
  * 返回当前日期,格式为yyyyMMdd
25
27
  * @return 日期
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.12.0",
7
+ "version": "0.13.0",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -14,13 +14,18 @@ StarFreedomX机器人的小功能,自用
14
14
  * BanG Dream!边框绘制
15
15
  * 群语录
16
16
  * 复读
17
+ * echo
18
+ * 撤回
19
+ * 黑白名单配置
17
20
 
18
21
  ## List to Do
19
22
 
20
- * 为每种功能添加单独的群聊控制开关
21
23
  * 修改BanG Dream!边框的绘制为使用sharp,加快速度
22
- * 增加入典功能
23
24
 
25
+ # 语录tag可视化控制
26
+
27
+ 详情见[StarFreedomX/image-tag-editor-web: 为starfx-bot的语录功能可视化添加tag](https://github.com/StarFreedomX/image-tag-editor-web)
28
+ 配置项的imageFolderPath填写Koishi数据文件夹下的/data/starfx-bot/record/
24
29
 
25
30
  ## 🔧 功能权限控制(可选)
26
31
 
@@ -28,7 +33,6 @@ StarFreedomX机器人的小功能,自用
28
33
 
29
34
  配置格式为 JSON
30
35
 
31
-
32
36
  - `whitelist: true`:启用白名单模式,仅允许列出的群使用该功能
33
37
  - `whitelist: false`:启用黑名单模式,禁止列出的群使用该功能
34
38
  - `groups`:群号数组,必须为数字
@@ -39,19 +43,20 @@ StarFreedomX机器人的小功能,自用
39
43
 
40
44
  ### 📌 可配置功能键一览
41
45
 
42
- | 键名 | 功能说明 |
43
- |------------|----------------------------------------|
44
- | `lock` | 明日方舟封印功能(对应 `openLock`) |
45
- | `sold` | 闲鱼“卖掉了”功能(对应 `openSold`) |
46
- | `repeat` | 群复读功能(对应 `openRepeat`) |
47
- | `record` | 群语录功能(对应 `投稿、语录`) |
48
- | `atNotSay` | “艾特我/他又不说话”系列功能 |
49
- | `replyBot` | “我才不是机器人!”系列功能 |
50
- | `iLoveYou` | “我也喜欢你”系列功能 |
51
- | `bdbd` | BanG Dream! 边框功能(对应 `bangdreamBorder`) |
52
- | `roll` | 随机数功能 |
53
- | `undo` | 撤回功能 |
54
- | `echo` | echo功能 |
46
+
47
+ | 键名 | 功能说明 |
48
+ | ---------- | --------------------------------------------- |
49
+ | `lock` | 明日方舟封印功能(对应`openLock`) |
50
+ | `sold` | 闲鱼“卖掉了”功能(对应`openSold`) |
51
+ | `repeat` | 群复读功能(对应`openRepeat`) |
52
+ | `record` | 群语录功能(对应`投稿、语录`) |
53
+ | `atNotSay` | “艾特我/他又不说话”系列功能 |
54
+ | `replyBot` | “我才不是机器人!”系列功能 |
55
+ | `iLoveYou` | “我也喜欢你”系列功能 |
56
+ | `bdbd` | BanG Dream! 边框功能(对应`bangdreamBorder`) |
57
+ | `roll` | 随机数功能 |
58
+ | `undo` | 撤回功能 |
59
+ | `echo` | echo功能 |
55
60
 
56
61
  ---
57
62
 
@@ -71,22 +76,25 @@ StarFreedomX机器人的小功能,自用
71
76
  ```
72
77
 
73
78
  ## 更新日志
74
- | 版本 | 更新日志 |
75
- |------------|-------------------------------|
76
- | `0.0.1` | 加入封印功能 |
77
- | `0.1.0` | 加入"卖掉了"功能 |
78
- | `0.2.0` | 加入"艾特我又不说话"回复功能 |
79
- | `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
80
- | `0.4.0` | 更改处理库为sharp |
81
- | `0.5.0` | 加入BanG Dream!边框功能 |
82
- | `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
83
- | `0.7.0` | 加入复读功能 |
84
- | `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
85
- | `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
86
- | `0.10.0` | 添加随机数功能 |
87
- | `0.10.1` | 修复随机数骰子功能输入负数报错的bug |
88
- | `0.10.2` | 增加roll功能的人称变化 |
89
- | `0.11.0` | 增加适配于onebot(主要是qq)的撤回功能 |
90
- | `0.11.1` | 修复bdbd传参错误问题 |
91
- | `0.11.2` | 优化消息捕获图片逻辑 |
92
- | `0.12.0` | 加入echo功能 |
79
+
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` | 加入复读功能 |
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以及调整权重 |