koishi-plugin-starfx-bot 0.8.0 → 0.9.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 +26 -13
- package/lib/index.js +99 -56
- package/lib/utils.d.ts +9 -0
- package/package.json +1 -1
- package/readme.md +50 -9
package/lib/index.d.ts
CHANGED
|
@@ -8,48 +8,61 @@ export interface Config {
|
|
|
8
8
|
openLock: boolean;
|
|
9
9
|
openSold: boolean;
|
|
10
10
|
bangdreamBorder: boolean;
|
|
11
|
+
record: boolean;
|
|
12
|
+
roll: boolean;
|
|
11
13
|
atNotSay: boolean;
|
|
12
|
-
atNotSayOther: boolean;
|
|
13
14
|
atNotSayProperty: number;
|
|
15
|
+
atNotSayOther: boolean;
|
|
14
16
|
atNotSayOtherProperty: number;
|
|
15
|
-
|
|
17
|
+
iLoveYou: boolean;
|
|
18
|
+
replyBot: string;
|
|
16
19
|
openRepeat: boolean;
|
|
17
20
|
minRepeatTimes: number;
|
|
18
21
|
repeatPossibility: number;
|
|
19
|
-
|
|
20
|
-
replyBot: string;
|
|
21
|
-
iLoveYou: boolean;
|
|
22
|
+
featureControl: string;
|
|
22
23
|
}
|
|
23
24
|
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
24
25
|
openLock: Schema<boolean, boolean>;
|
|
25
26
|
openSold: Schema<boolean, boolean>;
|
|
26
27
|
bangdreamBorder: Schema<boolean, boolean>;
|
|
28
|
+
}> | Schemastery.ObjectS<{
|
|
27
29
|
record: Schema<boolean, boolean>;
|
|
28
|
-
|
|
30
|
+
}> | Schemastery.ObjectS<{
|
|
31
|
+
roll: Schema<boolean, boolean>;
|
|
32
|
+
}> | Schemastery.ObjectS<{
|
|
29
33
|
atNotSay: Schema<boolean, boolean>;
|
|
30
34
|
atNotSayProperty: Schema<number, number>;
|
|
31
35
|
atNotSayOther: Schema<boolean, boolean>;
|
|
32
36
|
atNotSayOtherProperty: Schema<number, number>;
|
|
37
|
+
iLoveYou: Schema<boolean, boolean>;
|
|
38
|
+
replyBot: Schema<"关闭" | "无需at" | "必须at", "关闭" | "无需at" | "必须at">;
|
|
39
|
+
}> | Schemastery.ObjectS<{
|
|
33
40
|
openRepeat: Schema<boolean, boolean>;
|
|
34
41
|
minRepeatTimes: Schema<number, number>;
|
|
35
42
|
repeatPossibility: Schema<number, number>;
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
}> | Schemastery.ObjectS<{
|
|
44
|
+
featureControl: Schema<string, string>;
|
|
38
45
|
}>, {
|
|
39
46
|
openLock: boolean;
|
|
40
47
|
openSold: boolean;
|
|
41
48
|
bangdreamBorder: boolean;
|
|
49
|
+
} & import("cosmokit").Dict & {
|
|
42
50
|
record: boolean;
|
|
43
|
-
|
|
51
|
+
} & {
|
|
52
|
+
roll: boolean;
|
|
53
|
+
} & {
|
|
44
54
|
atNotSay: boolean;
|
|
45
55
|
atNotSayProperty: number;
|
|
46
56
|
atNotSayOther: boolean;
|
|
47
57
|
atNotSayOtherProperty: number;
|
|
58
|
+
iLoveYou: boolean;
|
|
59
|
+
replyBot: "关闭" | "无需at" | "必须at";
|
|
60
|
+
} & {
|
|
48
61
|
openRepeat: boolean;
|
|
49
62
|
minRepeatTimes: number;
|
|
50
63
|
repeatPossibility: number;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
export declare const usage = "<
|
|
64
|
+
} & {
|
|
65
|
+
featureControl: string;
|
|
66
|
+
}>;
|
|
67
|
+
export declare const usage = "<h2>StarFreedomX\u7684\u81EA\u7528\u63D2\u4EF6 \u653E\u4E86\u4E00\u4E9B\u5C0F\u529F\u80FD</h2>\n ";
|
|
55
68
|
export declare function apply(ctx: Context, cfg: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
// src/locales/zh-CN.yml
|
|
34
34
|
var require_zh_CN = __commonJS({
|
|
35
35
|
"src/locales/zh-CN.yml"(exports2, module2) {
|
|
36
|
-
module2.exports = { commands:
|
|
36
|
+
module2.exports = { commands: { roll: { messages: { noParam: "请输入要随机的对象" } } }, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你" } } };
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -350,6 +350,24 @@ async function drawBanGDream(avatar, inputOptions) {
|
|
|
350
350
|
return `data:image/png;base64,${(await image.getBuffer("image/jpeg")).toString("base64")}`;
|
|
351
351
|
}
|
|
352
352
|
__name(drawBanGDream, "drawBanGDream");
|
|
353
|
+
function parseJsonControl(text) {
|
|
354
|
+
try {
|
|
355
|
+
return JSON.parse(text);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
starfxLogger.warn("[功能控制] JSON 解析失败");
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
__name(parseJsonControl, "parseJsonControl");
|
|
362
|
+
function detectControl(controlJson, guildId, funName) {
|
|
363
|
+
const rule = controlJson?.[funName];
|
|
364
|
+
if (!rule || rule.whitelist === void 0 || !Array.isArray(rule.groups)) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
const inList = rule.groups.includes(Number(guildId));
|
|
368
|
+
return rule.whitelist ? inList : !inList;
|
|
369
|
+
}
|
|
370
|
+
__name(detectControl, "detectControl");
|
|
353
371
|
|
|
354
372
|
// src/index.ts
|
|
355
373
|
var name = "starfx-bot";
|
|
@@ -361,93 +379,115 @@ var Config2 = import_koishi2.Schema.intersect([
|
|
|
361
379
|
import_koishi2.Schema.object({
|
|
362
380
|
openLock: import_koishi2.Schema.boolean().default(true).description("开启明日方舟封印功能"),
|
|
363
381
|
openSold: import_koishi2.Schema.boolean().default(true).description('开启闲鱼"卖掉了"功能'),
|
|
364
|
-
bangdreamBorder: import_koishi2.Schema.boolean().default(true).description("开启BanG Dream!边框功能")
|
|
365
|
-
|
|
366
|
-
|
|
382
|
+
bangdreamBorder: import_koishi2.Schema.boolean().default(true).description("开启BanG Dream!边框功能")
|
|
383
|
+
}).description("绘图功能"),
|
|
384
|
+
import_koishi2.Schema.object({
|
|
385
|
+
record: import_koishi2.Schema.boolean().default(true).description("开启群语录功能")
|
|
386
|
+
//saveArchive: Schema.boolean().default(false).description('开启入典功能').hidden(),
|
|
387
|
+
}).description("语录记录功能"),
|
|
388
|
+
import_koishi2.Schema.object({
|
|
389
|
+
roll: import_koishi2.Schema.boolean().default(false).description("开启roll随机数功能").hidden()
|
|
390
|
+
}).description("指令小功能"),
|
|
391
|
+
import_koishi2.Schema.object({
|
|
367
392
|
atNotSay: import_koishi2.Schema.boolean().default(true).description("开启‘艾特我又不说话’功能"),
|
|
368
393
|
atNotSayProperty: import_koishi2.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.5).description("'艾特我又不说话'回复概率"),
|
|
369
394
|
atNotSayOther: import_koishi2.Schema.boolean().default(true).description("开启‘艾特他又不说话’功能"),
|
|
370
395
|
atNotSayOtherProperty: import_koishi2.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.5).description("'艾特他又不说话'回复概率"),
|
|
371
|
-
openRepeat: import_koishi2.Schema.boolean().default(true).description("开启复读功能"),
|
|
372
|
-
minRepeatTimes: import_koishi2.Schema.number().default(2).description("最少重复次数"),
|
|
373
|
-
repeatPossibility: import_koishi2.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.3).description("复读发生概率"),
|
|
374
396
|
iLoveYou: import_koishi2.Schema.boolean().default(true).description("开启‘我喜欢你’功能"),
|
|
375
397
|
replyBot: import_koishi2.Schema.union(["关闭", "无需at", "必须at"]).default("无需at").description("回复‘我才不是机器人!’功能")
|
|
376
|
-
})
|
|
398
|
+
}).description("特定回应功能"),
|
|
399
|
+
import_koishi2.Schema.object({
|
|
400
|
+
openRepeat: import_koishi2.Schema.boolean().default(true).description("开启复读功能"),
|
|
401
|
+
minRepeatTimes: import_koishi2.Schema.number().default(2).description("最少重复次数"),
|
|
402
|
+
repeatPossibility: import_koishi2.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.3).description("复读发生概率")
|
|
403
|
+
}).description("复读功能"),
|
|
404
|
+
import_koishi2.Schema.object({
|
|
405
|
+
featureControl: import_koishi2.Schema.string().role("textarea", { rows: [15] }).default("{\n\n}").description(`黑/白名单配置,语法为JSON格式(可以不缩进),<br>
|
|
406
|
+
可配置功能键及语法详见 [项目地址](https://github.com/StarFreedomX/starfx-bot)或[npm发布页](https://www.npmjs.com/package/koishi-plugin-bangdream-ccg)`)
|
|
407
|
+
}).description("高级配置")
|
|
377
408
|
]);
|
|
378
|
-
var usage = `<
|
|
409
|
+
var usage = `<h2>StarFreedomX的自用插件 放了一些小功能</h2>
|
|
379
410
|
`;
|
|
380
411
|
function apply(ctx, cfg) {
|
|
381
412
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
382
413
|
baseDir = ctx.baseDir;
|
|
383
414
|
assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
|
|
384
415
|
initAssets();
|
|
416
|
+
const controlJson = parseJsonControl(cfg.featureControl);
|
|
385
417
|
if (cfg.openLock) {
|
|
386
418
|
ctx.command("封印 [param]").action(async ({ session }, param) => {
|
|
387
|
-
|
|
419
|
+
if (detectControl(controlJson, session.guildId, "lock"))
|
|
420
|
+
return await drawLock(ctx, await getImageSrc(session, param));
|
|
388
421
|
});
|
|
389
422
|
}
|
|
390
423
|
if (cfg.openSold) {
|
|
391
424
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
392
|
-
|
|
425
|
+
if (detectControl(controlJson, session.guildId, "sold"))
|
|
426
|
+
return await drawSold(ctx, await getImageSrc(session, param));
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
if (cfg.roll) {
|
|
430
|
+
ctx.command("roll <param:text>").action(async ({ session }, param) => {
|
|
431
|
+
if (detectControl(controlJson, session.guildId, "roll")) {
|
|
432
|
+
if (!param) return session.text(".noParam");
|
|
433
|
+
if (param.endsWith("的概率")) {
|
|
434
|
+
}
|
|
435
|
+
const parts = param.split(/(?:\s+|还是)+/).filter(Boolean);
|
|
436
|
+
if (parts.length > 1) {
|
|
437
|
+
} else {
|
|
438
|
+
const items = param.split("r");
|
|
439
|
+
if (items.length === 2) {
|
|
440
|
+
const num = parseInt(items[0]);
|
|
441
|
+
const noodles = parseInt(items[1]);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
393
445
|
});
|
|
394
446
|
}
|
|
395
447
|
if (cfg.bangdreamBorder) {
|
|
396
|
-
ctx.command("
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
448
|
+
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) => {
|
|
449
|
+
if (detectControl(controlJson, session.guildId, "bdbd")) {
|
|
450
|
+
const p = session.send("图片处理中请稍等...");
|
|
451
|
+
console.log(param);
|
|
452
|
+
const drawConfig = await handleBanGDreamConfig(options);
|
|
453
|
+
const imageBase64 = await drawBanGDream(await getImageSrc(session, param), drawConfig);
|
|
454
|
+
await p;
|
|
455
|
+
return import_koishi2.h.image(imageBase64);
|
|
456
|
+
}
|
|
403
457
|
});
|
|
404
458
|
}
|
|
405
459
|
if (cfg.record) {
|
|
406
460
|
ctx.command("投稿 [param]").action(async ({ session }, param) => {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
461
|
+
if (detectControl(controlJson, session.guildId, "record")) {
|
|
462
|
+
const imageSrc = await getImageSrc(
|
|
463
|
+
session,
|
|
464
|
+
param,
|
|
465
|
+
{
|
|
466
|
+
img: true,
|
|
467
|
+
at: false,
|
|
468
|
+
quote: true,
|
|
469
|
+
noParam: false,
|
|
470
|
+
number: false
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
if (!imageSrc) {
|
|
474
|
+
return "请发送带图片的指令消息或引用图片消息进行投稿";
|
|
416
475
|
}
|
|
417
|
-
|
|
418
|
-
if (!imageSrc) {
|
|
419
|
-
return "请发送带图片的指令消息或引用图片消息进行投稿";
|
|
476
|
+
return await addRecord(ctx, session.gid.replace(":", "_"), imageSrc);
|
|
420
477
|
}
|
|
421
|
-
return await addRecord(ctx, session.gid.replace(":", "_"), imageSrc);
|
|
422
478
|
});
|
|
423
479
|
ctx.command("语录").action(async ({ session }) => {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
if (cfg.saveArchive) {
|
|
431
|
-
ctx.command("入典 [param]").action(async ({ session }, param) => {
|
|
432
|
-
const imageSrc = await getImageSrc(
|
|
433
|
-
session,
|
|
434
|
-
param,
|
|
435
|
-
{
|
|
436
|
-
img: true,
|
|
437
|
-
at: false,
|
|
438
|
-
quote: true,
|
|
439
|
-
noParam: false,
|
|
440
|
-
number: false
|
|
441
|
-
}
|
|
442
|
-
);
|
|
443
|
-
if (!imageSrc) {
|
|
444
|
-
return "请发送带图片的指令消息或引用图片消息进行投稿";
|
|
480
|
+
if (detectControl(controlJson, session.guildId, "record")) {
|
|
481
|
+
const filepath = await getRecord(session.gid.replace(":", "_"));
|
|
482
|
+
starfxLogger.info(`send record: ${filepath}`);
|
|
483
|
+
if (!filepath) return "暂无语录呢";
|
|
484
|
+
return import_koishi2.h.image(filepath);
|
|
445
485
|
}
|
|
446
486
|
});
|
|
447
487
|
}
|
|
448
488
|
ctx.middleware(async (session, next) => {
|
|
449
489
|
const elements = session.elements;
|
|
450
|
-
if (cfg.openRepeat) {
|
|
490
|
+
if (cfg.openRepeat && detectControl(controlJson, session.guildId, "repeat")) {
|
|
451
491
|
const content = session.content;
|
|
452
492
|
const ctxArr = repeatContextMap.get(session.gid);
|
|
453
493
|
if (!ctxArr || ctxArr[0] !== content) {
|
|
@@ -459,9 +499,12 @@ function apply(ctx, cfg) {
|
|
|
459
499
|
}
|
|
460
500
|
}
|
|
461
501
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
502
|
+
if (detectControl(controlJson, session.guildId, "atNotSay"))
|
|
503
|
+
await atNotSayReply(cfg, session, elements);
|
|
504
|
+
if (detectControl(controlJson, session.guildId, "replyBot"))
|
|
505
|
+
await replyBot(cfg, session, elements);
|
|
506
|
+
if (detectControl(controlJson, session.guildId, "iLoveYou"))
|
|
507
|
+
await iLoveYou(cfg, session, elements);
|
|
465
508
|
return next();
|
|
466
509
|
});
|
|
467
510
|
function initAssets() {
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Context, h, Session } from "koishi";
|
|
2
2
|
import sharp from "sharp";
|
|
3
3
|
import { Config } from "./index";
|
|
4
|
+
interface FeatureControl {
|
|
5
|
+
[feature: string]: {
|
|
6
|
+
whitelist: boolean;
|
|
7
|
+
groups: number[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* 添加投稿
|
|
6
12
|
* @param ctx Context
|
|
@@ -120,3 +126,6 @@ export declare function drawBanGDream(avatar: string, inputOptions?: {
|
|
|
120
126
|
starNum: number;
|
|
121
127
|
border: string;
|
|
122
128
|
}): Promise<string>;
|
|
129
|
+
export declare function parseJsonControl(text: string): FeatureControl | null;
|
|
130
|
+
export declare function detectControl(controlJson: FeatureControl, guildId: string, funName: string): boolean;
|
|
131
|
+
export {};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
StarFreedomX机器人的小功能,自用
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 已加入的功能列表:
|
|
8
8
|
|
|
9
9
|
* 明日方舟封印功能
|
|
10
10
|
* 闲鱼“卖掉了”功能
|
|
@@ -15,27 +15,68 @@ StarFreedomX机器人的小功能,自用
|
|
|
15
15
|
* 群语录
|
|
16
16
|
* 复读
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## List to Do
|
|
19
19
|
|
|
20
20
|
* 为每种功能添加单独的群聊控制开关
|
|
21
21
|
* 修改BanG Dream!边框的绘制为使用sharp,加快速度
|
|
22
22
|
* 增加入典功能
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
## 🔧 功能权限控制(可选)
|
|
26
|
+
|
|
27
|
+
本插件支持为各个功能设置 **群聊白名单 / 黑名单**,用于控制不同功能在指定群聊中是否启用。
|
|
28
|
+
|
|
29
|
+
配置格式为 JSON
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
- `whitelist: true`:启用白名单模式,仅允许列出的群使用该功能
|
|
33
|
+
- `whitelist: false`:启用黑名单模式,禁止列出的群使用该功能
|
|
34
|
+
- `groups`:群号数组,必须为数字
|
|
35
|
+
|
|
36
|
+
若未配置某功能项,则默认所有群均可使用。
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### 📌 可配置功能键一览
|
|
41
|
+
|
|
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
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 🧪 示例:仅允许特定群使用 `roll`,禁止某群使用 `sold`
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"roll": {
|
|
60
|
+
"whitelist": true,
|
|
61
|
+
"groups": [123456789,114514191]
|
|
62
|
+
},
|
|
63
|
+
"sold": {
|
|
64
|
+
"whitelist": false,
|
|
65
|
+
"groups": [987654321]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 更新日志
|
|
25
71
|
| 版本 | 更新日志 |
|
|
26
72
|
|---------|-------------------------------|
|
|
27
73
|
| `0.0.1` | 加入封印功能 |
|
|
28
74
|
| `0.1.0` | 加入"卖掉了"功能 |
|
|
29
75
|
| `0.2.0` | 加入"艾特我又不说话"回复功能 |
|
|
30
76
|
| `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
|
|
31
|
-
| `0.3.3` | 修订添加"我才不是机器人"是否需要at |
|
|
32
|
-
| `0.3.4` | 分离"艾特我/他又不说话"的两个选项为单独的开关 |
|
|
33
|
-
| `0.3.5` | 修复丢失的assets |
|
|
34
|
-
| `0.3.6` | 添加"艾特我/他又不说话"的概率配置 |
|
|
35
77
|
| `0.4.0` | 更改处理库为sharp |
|
|
36
|
-
| `0.4.1` | 修复sharp处理w>h的图报错的bug |
|
|
37
78
|
| `0.5.0` | 加入BanG Dream!边框功能 |
|
|
38
|
-
| `0.5.1` | 对边框的参数做了限定,修复了异常输入导致的报错 |
|
|
39
79
|
| `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
|
|
40
80
|
| `0.7.0` | 加入复读功能 |
|
|
41
81
|
| `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
|
|
82
|
+
| `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
|