koishi-plugin-starfx-bot 0.24.0 → 0.25.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
@@ -53,9 +53,12 @@ export interface Config {
53
53
  repeatPossibility: number;
54
54
  originImg: boolean;
55
55
  originImgRSSUrl: string;
56
- proxyUrl: string;
57
56
  filePathToBase64: boolean;
58
- featureControl: string;
57
+ featureControl: Array<{
58
+ functionName: string;
59
+ whitelist: boolean;
60
+ groups: string;
61
+ }>;
59
62
  }
60
63
  export declare const Config: Schema<Schemastery.ObjectS<{}>, {} & import("cosmokit").Dict>;
61
64
  export declare function apply(ctx: Context, cfg: Config): void;
package/lib/index.js CHANGED
@@ -63,7 +63,7 @@ var package_default = {
63
63
  contributors: [
64
64
  "StarFreedomX <starfreedomx@outlook.com>"
65
65
  ],
66
- version: "0.23.0",
66
+ version: "0.25.0",
67
67
  main: "lib/index.js",
68
68
  typings: "lib/index.d.ts",
69
69
  files: [
@@ -693,15 +693,25 @@ async function iLoveYou(cfg, session, elements) {
693
693
  }
694
694
  }
695
695
  __name(iLoveYou, "iLoveYou");
696
- function parseJsonControl(text) {
696
+ function parseFeatureControl(array) {
697
697
  try {
698
- return JSON.parse(text);
698
+ return Object.fromEntries(
699
+ array.map(
700
+ ({ functionName, whitelist, groups }) => functionName?.length ? [
701
+ functionName,
702
+ {
703
+ whitelist: !!whitelist,
704
+ groups: groups?.split(",")?.map(Number).filter(Boolean) || []
705
+ }
706
+ ] : void 0
707
+ )
708
+ ) || {};
699
709
  } catch (e) {
700
- starfxLogger.warn("[功能控制] JSON 解析失败", e);
701
- return null;
710
+ starfxLogger.warn("[功能控制] 解析失败", e);
711
+ return {};
702
712
  }
703
713
  }
704
- __name(parseJsonControl, "parseJsonControl");
714
+ __name(parseFeatureControl, "parseFeatureControl");
705
715
  function detectControl(controlJson, guildId, funName) {
706
716
  const rule = controlJson?.[funName];
707
717
  if (!rule || rule.whitelist === void 0 || !Array.isArray(rule.groups)) {
@@ -1221,6 +1231,26 @@ var usage = `
1221
1231
  <li>bdbd</li>
1222
1232
  `;
1223
1233
  var repeatContextMap = /* @__PURE__ */ new Map();
1234
+ var functionNames = [
1235
+ "lock",
1236
+ "sold",
1237
+ "repeat",
1238
+ "record",
1239
+ "record-push",
1240
+ "record-get",
1241
+ "atNotSay",
1242
+ "replyBot",
1243
+ "iLoveYou",
1244
+ "bdbd",
1245
+ "roll",
1246
+ "undo",
1247
+ "echo",
1248
+ "originImg",
1249
+ "sendLocalImage",
1250
+ "forward",
1251
+ "exchangeRate",
1252
+ "myId"
1253
+ ];
1224
1254
  var Config = import_koishi5.Schema.intersect([
1225
1255
  import_koishi5.Schema.object({
1226
1256
  openLock: import_koishi5.Schema.boolean().default(true).description("开启明日方舟封印功能"),
@@ -1292,14 +1322,19 @@ var Config = import_koishi5.Schema.intersect([
1292
1322
  import_koishi5.Schema.union([
1293
1323
  import_koishi5.Schema.object({
1294
1324
  originImg: import_koishi5.Schema.const(true).required(),
1295
- originImgRSSUrl: import_koishi5.Schema.string().required().description("推特列表rss地址"),
1296
- proxyUrl: import_koishi5.Schema.string().default("http://127.0.0.1:7890").description("代理地址")
1325
+ originImgRSSUrl: import_koishi5.Schema.string().required().description("推特列表rss地址")
1297
1326
  }),
1298
1327
  import_koishi5.Schema.object({})
1299
1328
  ]),
1300
1329
  import_koishi5.Schema.object({
1301
- featureControl: import_koishi5.Schema.string().role("textarea", { rows: [15] }).default("{\n\n}").description(`黑/白名单配置,语法为JSON格式(可以不缩进),<br>
1302
- 可配置功能键及语法详见 [项目地址](https://github.com/StarFreedomX/starfx-bot)或[npm发布页](https://www.npmjs.com/package/koishi-plugin-bangdream-ccg)`)
1330
+ featureControl: import_koishi5.Schema.array(
1331
+ import_koishi5.Schema.object({
1332
+ functionName: import_koishi5.Schema.union(functionNames),
1333
+ whitelist: import_koishi5.Schema.boolean(),
1334
+ groups: import_koishi5.Schema.string()
1335
+ })
1336
+ ).role("table").description(`黑/白名单配置,群组间用英文半角逗号分隔,<br>
1337
+ 可配置功能键及用法详见 [项目地址](https://github.com/StarFreedomX/starfx-bot)或[npm发布页](https://www.npmjs.com/package/koishi-plugin-bangdream-ccg)`)
1303
1338
  }).description("高级配置")
1304
1339
  ]);
1305
1340
  function apply(ctx, cfg) {
@@ -1307,10 +1342,10 @@ function apply(ctx, cfg) {
1307
1342
  baseDir = ctx.baseDir;
1308
1343
  assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
1309
1344
  initAssets();
1310
- const controlJson = parseJsonControl(cfg.featureControl);
1345
+ const featureControl = parseFeatureControl(cfg.featureControl);
1311
1346
  if (cfg.openLock) {
1312
1347
  ctx.command("封印 [param]").action(async ({ session }, param) => {
1313
- if (detectControl(controlJson, session.guildId, "lock"))
1348
+ if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "lock"))
1314
1349
  await session.send(
1315
1350
  await drawLock(ctx, await getImageSrc(session, param))
1316
1351
  );
@@ -1318,7 +1353,7 @@ function apply(ctx, cfg) {
1318
1353
  }
1319
1354
  if (cfg.openSold) {
1320
1355
  ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
1321
- if (detectControl(controlJson, session.guildId, "sold"))
1356
+ if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "sold"))
1322
1357
  await session.send(
1323
1358
  await drawSold(ctx, await getImageSrc(session, param))
1324
1359
  );
@@ -1326,14 +1361,14 @@ function apply(ctx, cfg) {
1326
1361
  }
1327
1362
  if (cfg.roll) {
1328
1363
  ctx.command("roll").action(async ({ session }) => {
1329
- if (detectControl(controlJson, session.guildId, "roll")) {
1364
+ if (detectControl(featureControl, session.guildId, "roll")) {
1330
1365
  return handleRoll(session);
1331
1366
  }
1332
1367
  });
1333
1368
  }
1334
1369
  if (cfg.echo) {
1335
1370
  ctx.command("echo <params>").option("time", "-t <time: number> 指定时间(min)").action(async ({ session, options }, params) => {
1336
- if (detectControl(controlJson, session.guildId, "echo")) {
1371
+ if (detectControl(featureControl, session.guildId, "echo")) {
1337
1372
  const elements = session.elements;
1338
1373
  const getEchoMessage = /* @__PURE__ */ __name(() => {
1339
1374
  try {
@@ -1377,7 +1412,7 @@ function apply(ctx, cfg) {
1377
1412
  }
1378
1413
  if (cfg.bangdreamBorder) {
1379
1414
  ctx.command("bdbd [param]").option("starNum", "-n <starNum: number>").option("color", "-c <color: string>").option("train", "-t <train: string>").option("band", "-b <band: string>").action(async ({ session, options }, param) => {
1380
- if (detectControl(controlJson, session.guildId, "bdbd")) {
1415
+ if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "bdbd")) {
1381
1416
  const drawConfig = await handleBanGDreamConfig(options);
1382
1417
  const imgSrc = await getImageSrc(session, param);
1383
1418
  if (!imgSrc?.length) return "输入无效";
@@ -1393,7 +1428,7 @@ function apply(ctx, cfg) {
1393
1428
  }
1394
1429
  if (cfg.record) {
1395
1430
  ctx.command("投稿 [param]").action(async ({ session }, param) => {
1396
- if (detectControl(controlJson, session.guildId, "record") && detectControl(controlJson, session.guildId, "record-push")) {
1431
+ if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-push")) {
1397
1432
  const imageSrc = await getImageSrc(session, param, {
1398
1433
  img: true,
1399
1434
  at: false,
@@ -1412,7 +1447,7 @@ function apply(ctx, cfg) {
1412
1447
  }
1413
1448
  });
1414
1449
  ctx.command("语录 [tag:string]").action(async ({ session }, tag) => {
1415
- if (detectControl(controlJson, session.guildId, "record") && detectControl(controlJson, session.guildId, "record-get")) {
1450
+ if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-get")) {
1416
1451
  const filepath = await getRecord(
1417
1452
  cfg,
1418
1453
  session.gid.replaceAll(":", "_"),
@@ -1426,7 +1461,11 @@ function apply(ctx, cfg) {
1426
1461
  }
1427
1462
  for (const key in cfg.sendLocalImage) {
1428
1463
  ctx.command(key, { hidden: cfg.sendLocalImage[key].hiddenInHelp }).action(async ({ session }) => {
1429
- if (detectControl(controlJson, session.guildId, "sendLocalImage") && detectControl(controlJson, session.guildId, key))
1464
+ if (detectControl(
1465
+ featureControl,
1466
+ session.guildId,
1467
+ "sendLocalImage"
1468
+ ) && detectControl(featureControl, session.guildId, key))
1430
1469
  return import_koishi5.h.image(
1431
1470
  safeQuote(cfg.sendLocalImage[key].imgPath, false)
1432
1471
  );
@@ -1469,13 +1508,13 @@ function apply(ctx, cfg) {
1469
1508
  }
1470
1509
  if (cfg.undo) {
1471
1510
  ctx.command("undo").alias("撤回").usage("撤回消息").action(async ({ session }) => {
1472
- if (detectControl(controlJson, session.guildId, "undo"))
1511
+ if (detectControl(featureControl, session.guildId, "undo"))
1473
1512
  await undo(cfg, session);
1474
1513
  });
1475
1514
  }
1476
1515
  if (cfg.forward) {
1477
1516
  ctx.command("forward").option("group", "-g <group:string>").option("platform", "-p <platform:string>").usage("转发消息").action(async ({ session, options }) => {
1478
- if (detectControl(controlJson, session.guildId, "forward")) {
1517
+ if (detectControl(featureControl, session.guildId, "forward")) {
1479
1518
  const mapPath = import_node_path4.default.join(assetsDir, "forward.json");
1480
1519
  const groupMap = readMap(mapPath);
1481
1520
  if (options.group) {
@@ -1505,7 +1544,7 @@ function apply(ctx, cfg) {
1505
1544
  }
1506
1545
  if (cfg.originImg) {
1507
1546
  ctx.command("获取X原图").alias("推特原图").usage("获取推特原图").action(async ({ session }) => {
1508
- if (detectControl(controlJson, session.guildId, "originImg")) {
1547
+ if (detectControl(featureControl, session.guildId, "originImg")) {
1509
1548
  let [xUrls, xIndex] = await Promise.all([
1510
1549
  getXUrl(session?.quote?.content),
1511
1550
  getXNum(session)
@@ -1521,15 +1560,21 @@ function apply(ctx, cfg) {
1521
1560
  });
1522
1561
  }
1523
1562
  if (cfg.myId) {
1524
- ctx.command("my-gid").action(({ session }) => session.gid);
1525
- ctx.command("my-uid").action(({ session }) => session.uid);
1526
- ctx.command("my-cid").action(({ session }) => session.cid);
1563
+ ctx.command("my-gid").action(
1564
+ ({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.gid : ""
1565
+ );
1566
+ ctx.command("my-uid").action(
1567
+ ({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.uid : ""
1568
+ );
1569
+ ctx.command("my-cid").action(
1570
+ ({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.cid : ""
1571
+ );
1527
1572
  }
1528
- if (cfg.searchExchangeRate && ctx.skia) {
1573
+ if (cfg.searchExchangeRate) {
1529
1574
  ctx.command("查汇率 <exchangeParam:text>").usage("查询当前汇率").example("查汇率 JPY : 查询日元兑换人民币的汇率(3位字母)").example("查汇率 JPYCNY : 查询日元兑换人民币的汇率(6位字母)").example("查汇率 -r avdzk2 : 查询日元兑换人民币的汇率(msn代码avdzk2)").example(
1530
1575
  "查汇率 -r auvwoc : 查询黄金的价格(msn代码auvwoc, 很怪吧我也不知道为什么是这个)"
1531
1576
  ).option("raw", "-r <raw:string>").action(async ({ session, options }, exchangeParam) => {
1532
- if (detectControl(controlJson, session.guildId, "exchangeRate")) {
1577
+ if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
1533
1578
  return await getExchangeRate(
1534
1579
  ctx,
1535
1580
  cfg,
@@ -1540,9 +1585,9 @@ function apply(ctx, cfg) {
1540
1585
  }
1541
1586
  });
1542
1587
  }
1543
- if (cfg.intervalGetExchangeRate && ctx.skia) {
1588
+ if (cfg.intervalGetExchangeRate) {
1544
1589
  ctx.command("开启汇率推送 [exchangeParam:string]").action(async ({ session }, exchangeParam) => {
1545
- if (detectControl(controlJson, session.guildId, "exchangeRate")) {
1590
+ if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
1546
1591
  const exchangeRatePath = import_node_path4.default.join(assetsDir, "exchangeRate.json");
1547
1592
  return await intervalGetExchangeRate(
1548
1593
  ctx,
@@ -1620,7 +1665,7 @@ function apply(ctx, cfg) {
1620
1665
  }
1621
1666
  ctx.middleware(async (session, next) => {
1622
1667
  const elements = session.elements;
1623
- if (cfg.openRepeat && detectControl(controlJson, session.guildId, "repeat")) {
1668
+ if (cfg.openRepeat && detectControl(featureControl, session.guildId, "repeat")) {
1624
1669
  const content = session.content;
1625
1670
  const ctxArr = repeatContextMap.get(session.gid);
1626
1671
  if (!ctxArr || ctxArr[0] !== content) {
@@ -1632,11 +1677,11 @@ function apply(ctx, cfg) {
1632
1677
  }
1633
1678
  }
1634
1679
  }
1635
- if (cfg.atNotSay && detectControl(controlJson, session.guildId, "atNotSay"))
1680
+ if (cfg.atNotSay && detectControl(featureControl, session.guildId, "atNotSay"))
1636
1681
  await atNotSayReply(cfg, session, elements);
1637
- if (cfg.replyBot && detectControl(controlJson, session.guildId, "replyBot"))
1682
+ if (cfg.replyBot && detectControl(featureControl, session.guildId, "replyBot"))
1638
1683
  await replyBot(cfg, session, elements);
1639
- if (cfg.iLoveYou && detectControl(controlJson, session.guildId, "iLoveYou"))
1684
+ if (cfg.iLoveYou && detectControl(featureControl, session.guildId, "iLoveYou"))
1640
1685
  await iLoveYou(cfg, session, elements);
1641
1686
  return next();
1642
1687
  });
@@ -17,14 +17,14 @@ export declare function handleBanGDreamConfig(options: any): Promise<{
17
17
  * @param baseImage 被封印的图片url
18
18
  * @return 画完的图片 h对象
19
19
  */
20
- export declare function drawLock(ctx: Context, baseImage: string): Promise<h | "发生错误" | "输入无效">;
20
+ export declare function drawLock(ctx: Context, baseImage: string): Promise<"发生错误" | "输入无效" | h>;
21
21
  /**
22
22
  * "卖掉了"绘图函数
23
23
  * @param ctx
24
24
  * @param baseImage
25
25
  * @return 画完的图片 h对象
26
26
  */
27
- export declare function drawSold(ctx: Context, baseImage: string): Promise<h | "发生错误" | "输入无效">;
27
+ export declare function drawSold(ctx: Context, baseImage: string): Promise<"发生错误" | "输入无效" | h>;
28
28
  /**
29
29
  * BanG Dream!边框绘制功能
30
30
  * @param ctx Koishi上下文
package/lib/utils.d.ts CHANGED
@@ -91,7 +91,11 @@ export declare function replyBot(cfg: Config, session: Session, elements: h[]):
91
91
  * @param elements 当前消息elements
92
92
  */
93
93
  export declare function iLoveYou(cfg: Config, session: Session, elements: h[]): Promise<void>;
94
- export declare function parseJsonControl(text: string): FeatureControl | null;
94
+ export declare function parseFeatureControl(array: {
95
+ functionName: string;
96
+ whitelist: boolean;
97
+ groups: string;
98
+ }[]): FeatureControl | null;
95
99
  export declare function detectControl(controlJson: FeatureControl, guildId: string, funName: string): boolean;
96
100
  export declare function handleRoll(session: Session): string;
97
101
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.24.0",
7
+ "version": "0.25.0",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -22,25 +22,26 @@ StarFreedomX机器人的小功能,自用
22
22
  * 撤回
23
23
  * 汇率推送
24
24
  * 黑白名单配置
25
+ * 我的会话信息
25
26
 
26
27
  ## List to Do
27
28
 
28
- * 修改BanG Dream!边框的绘制为使用sharp等库,加快速度
29
+ * 语录token通过聊天获取,并自动与语录web控制台通信
30
+ * 语录支持bot端添加tag
29
31
 
30
32
  ## 语录tag可视化控制
31
33
 
32
34
  详情见[StarFreedomX/image-tag-editor-web: 为starfx-bot的语录功能可视化添加tag](https://github.com/StarFreedomX/image-tag-editor-web)
35
+
33
36
  配置项的imageFolderPath填写Koishi数据文件夹下的/data/starfx-bot/record/
34
37
 
35
38
  ## 🔧 功能权限控制(可选)
36
39
 
37
40
  本插件支持为各个功能设置 **群聊白名单 / 黑名单**,用于控制不同功能在指定群聊中是否启用。
38
41
 
39
- 配置格式为 JSON
40
-
41
- - `whitelist: true`:启用白名单模式,仅允许列出的群使用该功能
42
- - `whitelist: false`:启用黑名单模式,禁止列出的群使用该功能
43
- - `groups`:群号数组,必须为数字
42
+ - `whitelist: ✅`:启用白名单模式,仅允许列出的群使用该功能
43
+ - `whitelist: 🟪`:启用黑名单模式,禁止列出的群使用该功能
44
+ - `groups`:群号数组,必须为数字,用半角逗号分隔
44
45
 
45
46
  若未配置某功能项,则默认所有群均可使用。
46
47
 
@@ -68,23 +69,17 @@ StarFreedomX机器人的小功能,自用
68
69
  | `sendLocalImage` | 自定义指令发送图片功能(自定义指令也可配置,键为自定义的指令名称) |
69
70
  | `forward` | 消息转发功能 |
70
71
  | `exchangeRate` | 汇率播报功能 |
72
+ | `myId` | 我的会话信息 |
71
73
 
72
74
  ---
73
75
 
74
76
  ### 🧪 示例:仅允许特定群使用 `roll`,禁止某群使用 `sold`
75
77
 
76
- ```json
77
- {
78
- "roll": {
79
- "whitelist": true,
80
- "groups": [123456789,114514191]
81
- },
82
- "sold": {
83
- "whitelist": false,
84
- "groups": [987654321]
85
- }
86
- }
87
- ```
78
+
79
+ | functionName | whitelist | groups |
80
+ |--------------|-----------|-----------|
81
+ | roll | ✅ | 123456789 |
82
+ | sold | 🟪 | 789456123 |
88
83
 
89
84
  ## 更新日志
90
85
 
@@ -128,3 +123,6 @@ StarFreedomX机器人的小功能,自用
128
123
  | `0.22.0` | sharp改用koishi服务实现 |
129
124
  | `0.23.0` | jimp转sharp |
130
125
  | `0.24.0` | build |
126
+ | `0.24.1` | 检测sharp服务,删除无用配置 |
127
+ | `0.24.2` | 修复检测逻辑 |
128
+ | `0.25.0` | 优化功能控制模块 |