koishi-plugin-starfx-bot 0.24.2 → 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 +5 -1
- package/lib/index.js +75 -29
- package/lib/utils.d.ts +5 -1
- package/package.json +1 -1
- package/readme.md +14 -18
package/lib/index.d.ts
CHANGED
|
@@ -54,7 +54,11 @@ export interface Config {
|
|
|
54
54
|
originImg: boolean;
|
|
55
55
|
originImgRSSUrl: string;
|
|
56
56
|
filePathToBase64: boolean;
|
|
57
|
-
featureControl:
|
|
57
|
+
featureControl: Array<{
|
|
58
|
+
functionName: string;
|
|
59
|
+
whitelist: boolean;
|
|
60
|
+
groups: string;
|
|
61
|
+
}>;
|
|
58
62
|
}
|
|
59
63
|
export declare const Config: Schema<Schemastery.ObjectS<{}>, {} & import("cosmokit").Dict>;
|
|
60
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.
|
|
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
|
|
696
|
+
function parseFeatureControl(array) {
|
|
697
697
|
try {
|
|
698
|
-
return
|
|
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("[功能控制]
|
|
701
|
-
return
|
|
710
|
+
starfxLogger.warn("[功能控制] 解析失败", e);
|
|
711
|
+
return {};
|
|
702
712
|
}
|
|
703
713
|
}
|
|
704
|
-
__name(
|
|
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("开启明日方舟封印功能"),
|
|
@@ -1297,8 +1327,14 @@ var Config = import_koishi5.Schema.intersect([
|
|
|
1297
1327
|
import_koishi5.Schema.object({})
|
|
1298
1328
|
]),
|
|
1299
1329
|
import_koishi5.Schema.object({
|
|
1300
|
-
featureControl: import_koishi5.Schema.
|
|
1301
|
-
|
|
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)`)
|
|
1302
1338
|
}).description("高级配置")
|
|
1303
1339
|
]);
|
|
1304
1340
|
function apply(ctx, cfg) {
|
|
@@ -1306,10 +1342,10 @@ function apply(ctx, cfg) {
|
|
|
1306
1342
|
baseDir = ctx.baseDir;
|
|
1307
1343
|
assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
|
|
1308
1344
|
initAssets();
|
|
1309
|
-
const
|
|
1345
|
+
const featureControl = parseFeatureControl(cfg.featureControl);
|
|
1310
1346
|
if (cfg.openLock) {
|
|
1311
1347
|
ctx.command("封印 [param]").action(async ({ session }, param) => {
|
|
1312
|
-
if (ctx.QhzySharp && detectControl(
|
|
1348
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "lock"))
|
|
1313
1349
|
await session.send(
|
|
1314
1350
|
await drawLock(ctx, await getImageSrc(session, param))
|
|
1315
1351
|
);
|
|
@@ -1317,7 +1353,7 @@ function apply(ctx, cfg) {
|
|
|
1317
1353
|
}
|
|
1318
1354
|
if (cfg.openSold) {
|
|
1319
1355
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
1320
|
-
if (ctx.QhzySharp && detectControl(
|
|
1356
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "sold"))
|
|
1321
1357
|
await session.send(
|
|
1322
1358
|
await drawSold(ctx, await getImageSrc(session, param))
|
|
1323
1359
|
);
|
|
@@ -1325,14 +1361,14 @@ function apply(ctx, cfg) {
|
|
|
1325
1361
|
}
|
|
1326
1362
|
if (cfg.roll) {
|
|
1327
1363
|
ctx.command("roll").action(async ({ session }) => {
|
|
1328
|
-
if (detectControl(
|
|
1364
|
+
if (detectControl(featureControl, session.guildId, "roll")) {
|
|
1329
1365
|
return handleRoll(session);
|
|
1330
1366
|
}
|
|
1331
1367
|
});
|
|
1332
1368
|
}
|
|
1333
1369
|
if (cfg.echo) {
|
|
1334
1370
|
ctx.command("echo <params>").option("time", "-t <time: number> 指定时间(min)").action(async ({ session, options }, params) => {
|
|
1335
|
-
if (detectControl(
|
|
1371
|
+
if (detectControl(featureControl, session.guildId, "echo")) {
|
|
1336
1372
|
const elements = session.elements;
|
|
1337
1373
|
const getEchoMessage = /* @__PURE__ */ __name(() => {
|
|
1338
1374
|
try {
|
|
@@ -1376,7 +1412,7 @@ function apply(ctx, cfg) {
|
|
|
1376
1412
|
}
|
|
1377
1413
|
if (cfg.bangdreamBorder) {
|
|
1378
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) => {
|
|
1379
|
-
if (ctx.QhzySharp && detectControl(
|
|
1415
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "bdbd")) {
|
|
1380
1416
|
const drawConfig = await handleBanGDreamConfig(options);
|
|
1381
1417
|
const imgSrc = await getImageSrc(session, param);
|
|
1382
1418
|
if (!imgSrc?.length) return "输入无效";
|
|
@@ -1392,7 +1428,7 @@ function apply(ctx, cfg) {
|
|
|
1392
1428
|
}
|
|
1393
1429
|
if (cfg.record) {
|
|
1394
1430
|
ctx.command("投稿 [param]").action(async ({ session }, param) => {
|
|
1395
|
-
if (detectControl(
|
|
1431
|
+
if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-push")) {
|
|
1396
1432
|
const imageSrc = await getImageSrc(session, param, {
|
|
1397
1433
|
img: true,
|
|
1398
1434
|
at: false,
|
|
@@ -1411,7 +1447,7 @@ function apply(ctx, cfg) {
|
|
|
1411
1447
|
}
|
|
1412
1448
|
});
|
|
1413
1449
|
ctx.command("语录 [tag:string]").action(async ({ session }, tag) => {
|
|
1414
|
-
if (detectControl(
|
|
1450
|
+
if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-get")) {
|
|
1415
1451
|
const filepath = await getRecord(
|
|
1416
1452
|
cfg,
|
|
1417
1453
|
session.gid.replaceAll(":", "_"),
|
|
@@ -1425,7 +1461,11 @@ function apply(ctx, cfg) {
|
|
|
1425
1461
|
}
|
|
1426
1462
|
for (const key in cfg.sendLocalImage) {
|
|
1427
1463
|
ctx.command(key, { hidden: cfg.sendLocalImage[key].hiddenInHelp }).action(async ({ session }) => {
|
|
1428
|
-
if (detectControl(
|
|
1464
|
+
if (detectControl(
|
|
1465
|
+
featureControl,
|
|
1466
|
+
session.guildId,
|
|
1467
|
+
"sendLocalImage"
|
|
1468
|
+
) && detectControl(featureControl, session.guildId, key))
|
|
1429
1469
|
return import_koishi5.h.image(
|
|
1430
1470
|
safeQuote(cfg.sendLocalImage[key].imgPath, false)
|
|
1431
1471
|
);
|
|
@@ -1468,13 +1508,13 @@ function apply(ctx, cfg) {
|
|
|
1468
1508
|
}
|
|
1469
1509
|
if (cfg.undo) {
|
|
1470
1510
|
ctx.command("undo").alias("撤回").usage("撤回消息").action(async ({ session }) => {
|
|
1471
|
-
if (detectControl(
|
|
1511
|
+
if (detectControl(featureControl, session.guildId, "undo"))
|
|
1472
1512
|
await undo(cfg, session);
|
|
1473
1513
|
});
|
|
1474
1514
|
}
|
|
1475
1515
|
if (cfg.forward) {
|
|
1476
1516
|
ctx.command("forward").option("group", "-g <group:string>").option("platform", "-p <platform:string>").usage("转发消息").action(async ({ session, options }) => {
|
|
1477
|
-
if (detectControl(
|
|
1517
|
+
if (detectControl(featureControl, session.guildId, "forward")) {
|
|
1478
1518
|
const mapPath = import_node_path4.default.join(assetsDir, "forward.json");
|
|
1479
1519
|
const groupMap = readMap(mapPath);
|
|
1480
1520
|
if (options.group) {
|
|
@@ -1504,7 +1544,7 @@ function apply(ctx, cfg) {
|
|
|
1504
1544
|
}
|
|
1505
1545
|
if (cfg.originImg) {
|
|
1506
1546
|
ctx.command("获取X原图").alias("推特原图").usage("获取推特原图").action(async ({ session }) => {
|
|
1507
|
-
if (detectControl(
|
|
1547
|
+
if (detectControl(featureControl, session.guildId, "originImg")) {
|
|
1508
1548
|
let [xUrls, xIndex] = await Promise.all([
|
|
1509
1549
|
getXUrl(session?.quote?.content),
|
|
1510
1550
|
getXNum(session)
|
|
@@ -1520,15 +1560,21 @@ function apply(ctx, cfg) {
|
|
|
1520
1560
|
});
|
|
1521
1561
|
}
|
|
1522
1562
|
if (cfg.myId) {
|
|
1523
|
-
ctx.command("my-gid").action(
|
|
1524
|
-
|
|
1525
|
-
|
|
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
|
+
);
|
|
1526
1572
|
}
|
|
1527
1573
|
if (cfg.searchExchangeRate) {
|
|
1528
1574
|
ctx.command("查汇率 <exchangeParam:text>").usage("查询当前汇率").example("查汇率 JPY : 查询日元兑换人民币的汇率(3位字母)").example("查汇率 JPYCNY : 查询日元兑换人民币的汇率(6位字母)").example("查汇率 -r avdzk2 : 查询日元兑换人民币的汇率(msn代码avdzk2)").example(
|
|
1529
1575
|
"查汇率 -r auvwoc : 查询黄金的价格(msn代码auvwoc, 很怪吧我也不知道为什么是这个)"
|
|
1530
1576
|
).option("raw", "-r <raw:string>").action(async ({ session, options }, exchangeParam) => {
|
|
1531
|
-
if (ctx.skia && detectControl(
|
|
1577
|
+
if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
|
|
1532
1578
|
return await getExchangeRate(
|
|
1533
1579
|
ctx,
|
|
1534
1580
|
cfg,
|
|
@@ -1541,7 +1587,7 @@ function apply(ctx, cfg) {
|
|
|
1541
1587
|
}
|
|
1542
1588
|
if (cfg.intervalGetExchangeRate) {
|
|
1543
1589
|
ctx.command("开启汇率推送 [exchangeParam:string]").action(async ({ session }, exchangeParam) => {
|
|
1544
|
-
if (ctx.skia && detectControl(
|
|
1590
|
+
if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
|
|
1545
1591
|
const exchangeRatePath = import_node_path4.default.join(assetsDir, "exchangeRate.json");
|
|
1546
1592
|
return await intervalGetExchangeRate(
|
|
1547
1593
|
ctx,
|
|
@@ -1619,7 +1665,7 @@ function apply(ctx, cfg) {
|
|
|
1619
1665
|
}
|
|
1620
1666
|
ctx.middleware(async (session, next) => {
|
|
1621
1667
|
const elements = session.elements;
|
|
1622
|
-
if (cfg.openRepeat && detectControl(
|
|
1668
|
+
if (cfg.openRepeat && detectControl(featureControl, session.guildId, "repeat")) {
|
|
1623
1669
|
const content = session.content;
|
|
1624
1670
|
const ctxArr = repeatContextMap.get(session.gid);
|
|
1625
1671
|
if (!ctxArr || ctxArr[0] !== content) {
|
|
@@ -1631,11 +1677,11 @@ function apply(ctx, cfg) {
|
|
|
1631
1677
|
}
|
|
1632
1678
|
}
|
|
1633
1679
|
}
|
|
1634
|
-
if (cfg.atNotSay && detectControl(
|
|
1680
|
+
if (cfg.atNotSay && detectControl(featureControl, session.guildId, "atNotSay"))
|
|
1635
1681
|
await atNotSayReply(cfg, session, elements);
|
|
1636
|
-
if (cfg.replyBot && detectControl(
|
|
1682
|
+
if (cfg.replyBot && detectControl(featureControl, session.guildId, "replyBot"))
|
|
1637
1683
|
await replyBot(cfg, session, elements);
|
|
1638
|
-
if (cfg.iLoveYou && detectControl(
|
|
1684
|
+
if (cfg.iLoveYou && detectControl(featureControl, session.guildId, "iLoveYou"))
|
|
1639
1685
|
await iLoveYou(cfg, session, elements);
|
|
1640
1686
|
return next();
|
|
1641
1687
|
});
|
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
|
|
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
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
|
-
*
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
- `
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
|
@@ -130,3 +125,4 @@ StarFreedomX机器人的小功能,自用
|
|
|
130
125
|
| `0.24.0` | build |
|
|
131
126
|
| `0.24.1` | 检测sharp服务,删除无用配置 |
|
|
132
127
|
| `0.24.2` | 修复检测逻辑 |
|
|
128
|
+
| `0.25.0` | 优化功能控制模块 |
|