koishi-plugin-starfx-bot 0.24.2 → 0.25.1
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 +57 -30
- package/lib/plugins/drawHead.d.ts +2 -2
- package/lib/utils.d.ts +5 -1
- package/package.json +3 -2
- package/readme.md +15 -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: [
|
|
@@ -113,7 +113,8 @@ var package_default = {
|
|
|
113
113
|
"@biomejs/biome": "2.3.7",
|
|
114
114
|
"@ltxhhz/koishi-plugin-skia-canvas": "^0.0.10",
|
|
115
115
|
"@quanhuzeyu/koishi-plugin-qhzy-sharp": "^1.2.1",
|
|
116
|
-
"@quanhuzeyu/sharp-for-koishi": "^0.0.7"
|
|
116
|
+
"@quanhuzeyu/sharp-for-koishi": "^0.0.7",
|
|
117
|
+
"@types/mime-types": "^3.0.1"
|
|
117
118
|
}
|
|
118
119
|
};
|
|
119
120
|
|
|
@@ -693,15 +694,25 @@ async function iLoveYou(cfg, session, elements) {
|
|
|
693
694
|
}
|
|
694
695
|
}
|
|
695
696
|
__name(iLoveYou, "iLoveYou");
|
|
696
|
-
function
|
|
697
|
+
function parseFeatureControl(array) {
|
|
697
698
|
try {
|
|
698
|
-
return
|
|
699
|
+
return Object.fromEntries(
|
|
700
|
+
array.map(
|
|
701
|
+
({ functionName, whitelist, groups }) => functionName?.length ? [
|
|
702
|
+
functionName,
|
|
703
|
+
{
|
|
704
|
+
whitelist: !!whitelist,
|
|
705
|
+
groups: groups?.split(",")?.map(Number).filter(Boolean) || []
|
|
706
|
+
}
|
|
707
|
+
] : void 0
|
|
708
|
+
)
|
|
709
|
+
) || {};
|
|
699
710
|
} catch (e) {
|
|
700
|
-
starfxLogger.warn("[功能控制]
|
|
701
|
-
return
|
|
711
|
+
starfxLogger.warn("[功能控制] 解析失败", e);
|
|
712
|
+
return {};
|
|
702
713
|
}
|
|
703
714
|
}
|
|
704
|
-
__name(
|
|
715
|
+
__name(parseFeatureControl, "parseFeatureControl");
|
|
705
716
|
function detectControl(controlJson, guildId, funName) {
|
|
706
717
|
const rule = controlJson?.[funName];
|
|
707
718
|
if (!rule || rule.whitelist === void 0 || !Array.isArray(rule.groups)) {
|
|
@@ -1297,8 +1308,14 @@ var Config = import_koishi5.Schema.intersect([
|
|
|
1297
1308
|
import_koishi5.Schema.object({})
|
|
1298
1309
|
]),
|
|
1299
1310
|
import_koishi5.Schema.object({
|
|
1300
|
-
featureControl: import_koishi5.Schema.
|
|
1301
|
-
|
|
1311
|
+
featureControl: import_koishi5.Schema.array(
|
|
1312
|
+
import_koishi5.Schema.object({
|
|
1313
|
+
functionName: import_koishi5.Schema.string(),
|
|
1314
|
+
whitelist: import_koishi5.Schema.boolean(),
|
|
1315
|
+
groups: import_koishi5.Schema.string()
|
|
1316
|
+
})
|
|
1317
|
+
).role("table").description(`黑/白名单配置,群组间用英文半角逗号分隔,<br>
|
|
1318
|
+
可配置功能键及用法详见 [项目地址](https://github.com/StarFreedomX/starfx-bot)或[npm发布页](https://www.npmjs.com/package/koishi-plugin-bangdream-ccg)`)
|
|
1302
1319
|
}).description("高级配置")
|
|
1303
1320
|
]);
|
|
1304
1321
|
function apply(ctx, cfg) {
|
|
@@ -1306,10 +1323,10 @@ function apply(ctx, cfg) {
|
|
|
1306
1323
|
baseDir = ctx.baseDir;
|
|
1307
1324
|
assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
|
|
1308
1325
|
initAssets();
|
|
1309
|
-
|
|
1326
|
+
let featureControl = parseFeatureControl(cfg.featureControl);
|
|
1310
1327
|
if (cfg.openLock) {
|
|
1311
1328
|
ctx.command("封印 [param]").action(async ({ session }, param) => {
|
|
1312
|
-
if (ctx.QhzySharp && detectControl(
|
|
1329
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "lock"))
|
|
1313
1330
|
await session.send(
|
|
1314
1331
|
await drawLock(ctx, await getImageSrc(session, param))
|
|
1315
1332
|
);
|
|
@@ -1317,7 +1334,7 @@ function apply(ctx, cfg) {
|
|
|
1317
1334
|
}
|
|
1318
1335
|
if (cfg.openSold) {
|
|
1319
1336
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
1320
|
-
if (ctx.QhzySharp && detectControl(
|
|
1337
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "sold"))
|
|
1321
1338
|
await session.send(
|
|
1322
1339
|
await drawSold(ctx, await getImageSrc(session, param))
|
|
1323
1340
|
);
|
|
@@ -1325,14 +1342,14 @@ function apply(ctx, cfg) {
|
|
|
1325
1342
|
}
|
|
1326
1343
|
if (cfg.roll) {
|
|
1327
1344
|
ctx.command("roll").action(async ({ session }) => {
|
|
1328
|
-
if (detectControl(
|
|
1345
|
+
if (detectControl(featureControl, session.guildId, "roll")) {
|
|
1329
1346
|
return handleRoll(session);
|
|
1330
1347
|
}
|
|
1331
1348
|
});
|
|
1332
1349
|
}
|
|
1333
1350
|
if (cfg.echo) {
|
|
1334
1351
|
ctx.command("echo <params>").option("time", "-t <time: number> 指定时间(min)").action(async ({ session, options }, params) => {
|
|
1335
|
-
if (detectControl(
|
|
1352
|
+
if (detectControl(featureControl, session.guildId, "echo")) {
|
|
1336
1353
|
const elements = session.elements;
|
|
1337
1354
|
const getEchoMessage = /* @__PURE__ */ __name(() => {
|
|
1338
1355
|
try {
|
|
@@ -1376,7 +1393,7 @@ function apply(ctx, cfg) {
|
|
|
1376
1393
|
}
|
|
1377
1394
|
if (cfg.bangdreamBorder) {
|
|
1378
1395
|
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(
|
|
1396
|
+
if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "bdbd")) {
|
|
1380
1397
|
const drawConfig = await handleBanGDreamConfig(options);
|
|
1381
1398
|
const imgSrc = await getImageSrc(session, param);
|
|
1382
1399
|
if (!imgSrc?.length) return "输入无效";
|
|
@@ -1392,7 +1409,7 @@ function apply(ctx, cfg) {
|
|
|
1392
1409
|
}
|
|
1393
1410
|
if (cfg.record) {
|
|
1394
1411
|
ctx.command("投稿 [param]").action(async ({ session }, param) => {
|
|
1395
|
-
if (detectControl(
|
|
1412
|
+
if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-push")) {
|
|
1396
1413
|
const imageSrc = await getImageSrc(session, param, {
|
|
1397
1414
|
img: true,
|
|
1398
1415
|
at: false,
|
|
@@ -1411,7 +1428,7 @@ function apply(ctx, cfg) {
|
|
|
1411
1428
|
}
|
|
1412
1429
|
});
|
|
1413
1430
|
ctx.command("语录 [tag:string]").action(async ({ session }, tag) => {
|
|
1414
|
-
if (detectControl(
|
|
1431
|
+
if (detectControl(featureControl, session.guildId, "record") && detectControl(featureControl, session.guildId, "record-get")) {
|
|
1415
1432
|
const filepath = await getRecord(
|
|
1416
1433
|
cfg,
|
|
1417
1434
|
session.gid.replaceAll(":", "_"),
|
|
@@ -1425,7 +1442,11 @@ function apply(ctx, cfg) {
|
|
|
1425
1442
|
}
|
|
1426
1443
|
for (const key in cfg.sendLocalImage) {
|
|
1427
1444
|
ctx.command(key, { hidden: cfg.sendLocalImage[key].hiddenInHelp }).action(async ({ session }) => {
|
|
1428
|
-
if (detectControl(
|
|
1445
|
+
if (detectControl(
|
|
1446
|
+
featureControl,
|
|
1447
|
+
session.guildId,
|
|
1448
|
+
"sendLocalImage"
|
|
1449
|
+
) && detectControl(featureControl, session.guildId, key))
|
|
1429
1450
|
return import_koishi5.h.image(
|
|
1430
1451
|
safeQuote(cfg.sendLocalImage[key].imgPath, false)
|
|
1431
1452
|
);
|
|
@@ -1468,13 +1489,13 @@ function apply(ctx, cfg) {
|
|
|
1468
1489
|
}
|
|
1469
1490
|
if (cfg.undo) {
|
|
1470
1491
|
ctx.command("undo").alias("撤回").usage("撤回消息").action(async ({ session }) => {
|
|
1471
|
-
if (detectControl(
|
|
1492
|
+
if (detectControl(featureControl, session.guildId, "undo"))
|
|
1472
1493
|
await undo(cfg, session);
|
|
1473
1494
|
});
|
|
1474
1495
|
}
|
|
1475
1496
|
if (cfg.forward) {
|
|
1476
1497
|
ctx.command("forward").option("group", "-g <group:string>").option("platform", "-p <platform:string>").usage("转发消息").action(async ({ session, options }) => {
|
|
1477
|
-
if (detectControl(
|
|
1498
|
+
if (detectControl(featureControl, session.guildId, "forward")) {
|
|
1478
1499
|
const mapPath = import_node_path4.default.join(assetsDir, "forward.json");
|
|
1479
1500
|
const groupMap = readMap(mapPath);
|
|
1480
1501
|
if (options.group) {
|
|
@@ -1504,7 +1525,7 @@ function apply(ctx, cfg) {
|
|
|
1504
1525
|
}
|
|
1505
1526
|
if (cfg.originImg) {
|
|
1506
1527
|
ctx.command("获取X原图").alias("推特原图").usage("获取推特原图").action(async ({ session }) => {
|
|
1507
|
-
if (detectControl(
|
|
1528
|
+
if (detectControl(featureControl, session.guildId, "originImg")) {
|
|
1508
1529
|
let [xUrls, xIndex] = await Promise.all([
|
|
1509
1530
|
getXUrl(session?.quote?.content),
|
|
1510
1531
|
getXNum(session)
|
|
@@ -1520,15 +1541,21 @@ function apply(ctx, cfg) {
|
|
|
1520
1541
|
});
|
|
1521
1542
|
}
|
|
1522
1543
|
if (cfg.myId) {
|
|
1523
|
-
ctx.command("my-gid").action(
|
|
1524
|
-
|
|
1525
|
-
|
|
1544
|
+
ctx.command("my-gid").action(
|
|
1545
|
+
({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.gid : ""
|
|
1546
|
+
);
|
|
1547
|
+
ctx.command("my-uid").action(
|
|
1548
|
+
({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.uid : ""
|
|
1549
|
+
);
|
|
1550
|
+
ctx.command("my-cid").action(
|
|
1551
|
+
({ session }) => detectControl(featureControl, session.guildId, "myId") ? session.cid : ""
|
|
1552
|
+
);
|
|
1526
1553
|
}
|
|
1527
1554
|
if (cfg.searchExchangeRate) {
|
|
1528
1555
|
ctx.command("查汇率 <exchangeParam:text>").usage("查询当前汇率").example("查汇率 JPY : 查询日元兑换人民币的汇率(3位字母)").example("查汇率 JPYCNY : 查询日元兑换人民币的汇率(6位字母)").example("查汇率 -r avdzk2 : 查询日元兑换人民币的汇率(msn代码avdzk2)").example(
|
|
1529
1556
|
"查汇率 -r auvwoc : 查询黄金的价格(msn代码auvwoc, 很怪吧我也不知道为什么是这个)"
|
|
1530
1557
|
).option("raw", "-r <raw:string>").action(async ({ session, options }, exchangeParam) => {
|
|
1531
|
-
if (ctx.skia && detectControl(
|
|
1558
|
+
if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
|
|
1532
1559
|
return await getExchangeRate(
|
|
1533
1560
|
ctx,
|
|
1534
1561
|
cfg,
|
|
@@ -1541,7 +1568,7 @@ function apply(ctx, cfg) {
|
|
|
1541
1568
|
}
|
|
1542
1569
|
if (cfg.intervalGetExchangeRate) {
|
|
1543
1570
|
ctx.command("开启汇率推送 [exchangeParam:string]").action(async ({ session }, exchangeParam) => {
|
|
1544
|
-
if (ctx.skia && detectControl(
|
|
1571
|
+
if (ctx.skia && detectControl(featureControl, session.guildId, "exchangeRate")) {
|
|
1545
1572
|
const exchangeRatePath = import_node_path4.default.join(assetsDir, "exchangeRate.json");
|
|
1546
1573
|
return await intervalGetExchangeRate(
|
|
1547
1574
|
ctx,
|
|
@@ -1619,7 +1646,7 @@ function apply(ctx, cfg) {
|
|
|
1619
1646
|
}
|
|
1620
1647
|
ctx.middleware(async (session, next) => {
|
|
1621
1648
|
const elements = session.elements;
|
|
1622
|
-
if (cfg.openRepeat && detectControl(
|
|
1649
|
+
if (cfg.openRepeat && detectControl(featureControl, session.guildId, "repeat")) {
|
|
1623
1650
|
const content = session.content;
|
|
1624
1651
|
const ctxArr = repeatContextMap.get(session.gid);
|
|
1625
1652
|
if (!ctxArr || ctxArr[0] !== content) {
|
|
@@ -1631,11 +1658,11 @@ function apply(ctx, cfg) {
|
|
|
1631
1658
|
}
|
|
1632
1659
|
}
|
|
1633
1660
|
}
|
|
1634
|
-
if (cfg.atNotSay && detectControl(
|
|
1661
|
+
if (cfg.atNotSay && detectControl(featureControl, session.guildId, "atNotSay"))
|
|
1635
1662
|
await atNotSayReply(cfg, session, elements);
|
|
1636
|
-
if (cfg.replyBot && detectControl(
|
|
1663
|
+
if (cfg.replyBot && detectControl(featureControl, session.guildId, "replyBot"))
|
|
1637
1664
|
await replyBot(cfg, session, elements);
|
|
1638
|
-
if (cfg.iLoveYou && detectControl(
|
|
1665
|
+
if (cfg.iLoveYou && detectControl(featureControl, session.guildId, "iLoveYou"))
|
|
1639
1666
|
await iLoveYou(cfg, session, elements);
|
|
1640
1667
|
return next();
|
|
1641
1668
|
});
|
|
@@ -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<
|
|
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<
|
|
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
|
|
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.
|
|
7
|
+
"version": "0.25.1",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
10
10
|
"files": [
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@biomejs/biome": "2.3.7",
|
|
55
55
|
"@ltxhhz/koishi-plugin-skia-canvas": "^0.0.10",
|
|
56
56
|
"@quanhuzeyu/koishi-plugin-qhzy-sharp": "^1.2.1",
|
|
57
|
-
"@quanhuzeyu/sharp-for-koishi": "^0.0.7"
|
|
57
|
+
"@quanhuzeyu/sharp-for-koishi": "^0.0.7",
|
|
58
|
+
"@types/mime-types": "^3.0.1"
|
|
58
59
|
}
|
|
59
60
|
}
|
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,5 @@ StarFreedomX机器人的小功能,自用
|
|
|
130
125
|
| `0.24.0` | build |
|
|
131
126
|
| `0.24.1` | 检测sharp服务,删除无用配置 |
|
|
132
127
|
| `0.24.2` | 修复检测逻辑 |
|
|
128
|
+
| `0.25.0` | 优化功能控制模块 |
|
|
129
|
+
| `0.25.1` | 修正功能控制模块功能名相关bug |
|