koishi-plugin-starfx-bot 0.15.1 → 0.16.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 +9 -0
- package/lib/index.js +40 -17
- package/lib/utils.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +35 -45
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export declare let baseDir: string;
|
|
|
4
4
|
export declare let assetsDir: string;
|
|
5
5
|
export declare const starfxLogger: Logger;
|
|
6
6
|
export declare const repeatContextMap: Map<string, [string, number]>;
|
|
7
|
+
interface sendLocalImageConfigItem {
|
|
8
|
+
imgPath: string;
|
|
9
|
+
}
|
|
10
|
+
interface sendLocalImageConfigDict {
|
|
11
|
+
[key: string]: sendLocalImageConfigItem;
|
|
12
|
+
}
|
|
7
13
|
export interface Config {
|
|
8
14
|
openLock: boolean;
|
|
9
15
|
openSold: boolean;
|
|
@@ -14,12 +20,14 @@ export interface Config {
|
|
|
14
20
|
roll: boolean;
|
|
15
21
|
undo: boolean;
|
|
16
22
|
echo: boolean;
|
|
23
|
+
echoBanner: string[];
|
|
17
24
|
atNotSay: boolean;
|
|
18
25
|
atNotSayProperty: number;
|
|
19
26
|
atNotSayOther: boolean;
|
|
20
27
|
atNotSayOtherProperty: number;
|
|
21
28
|
iLoveYou: boolean;
|
|
22
29
|
replyBot: string;
|
|
30
|
+
sendLocalImage: sendLocalImageConfigDict;
|
|
23
31
|
openRepeat: boolean;
|
|
24
32
|
minRepeatTimes: number;
|
|
25
33
|
repeatPossibility: number;
|
|
@@ -31,3 +39,4 @@ export interface Config {
|
|
|
31
39
|
export declare const Config: Schema<Schemastery.ObjectS<{}>, {} & import("cosmokit").Dict>;
|
|
32
40
|
export declare const usage = "<h2>StarFreedomX\u7684\u81EA\u7528\u63D2\u4EF6 \u653E\u4E86\u4E00\u4E9B\u5C0F\u529F\u80FD</h2>\n ";
|
|
33
41
|
export declare function apply(ctx: Context, cfg: Config): void;
|
|
42
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -478,8 +478,7 @@ var parser = new import_rss_parser.default({
|
|
|
478
478
|
}
|
|
479
479
|
});
|
|
480
480
|
async function getXNum(session) {
|
|
481
|
-
|
|
482
|
-
return params;
|
|
481
|
+
return session.content.trim().split(" ").slice(1).filter((item) => !isNaN(+item) && item).map((str) => Number(str) - 1);
|
|
483
482
|
}
|
|
484
483
|
__name(getXNum, "getXNum");
|
|
485
484
|
async function getXImage(rssUrl, xUrls) {
|
|
@@ -513,8 +512,12 @@ async function sendImages(session, cfg, imageUrls) {
|
|
|
513
512
|
const messages = await Promise.all(
|
|
514
513
|
group.map(async (url) => import_koishi.h.image(await getXImageBase64(url, cfg)))
|
|
515
514
|
);
|
|
516
|
-
|
|
517
|
-
|
|
515
|
+
if (messages.length > 0) {
|
|
516
|
+
const message = messages.join("");
|
|
517
|
+
await session.send(message);
|
|
518
|
+
} else {
|
|
519
|
+
await session.send("未找到图片,请引用包含图片且处于RSS列表中的的推特链接");
|
|
520
|
+
}
|
|
518
521
|
}
|
|
519
522
|
}
|
|
520
523
|
__name(sendImages, "sendImages");
|
|
@@ -530,6 +533,21 @@ async function getXImageBase64(url, cfg) {
|
|
|
530
533
|
return dataUrl;
|
|
531
534
|
}
|
|
532
535
|
__name(getXImageBase64, "getXImageBase64");
|
|
536
|
+
function safeQuote(str, useQuote) {
|
|
537
|
+
let unquoted = str.trim();
|
|
538
|
+
if (unquoted.startsWith('"')) {
|
|
539
|
+
unquoted = unquoted.slice(1);
|
|
540
|
+
}
|
|
541
|
+
if (unquoted.endsWith('"')) {
|
|
542
|
+
unquoted = unquoted.slice(0, -1);
|
|
543
|
+
}
|
|
544
|
+
if (useQuote) {
|
|
545
|
+
return `"${unquoted}"`;
|
|
546
|
+
} else {
|
|
547
|
+
return unquoted;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
__name(safeQuote, "safeQuote");
|
|
533
551
|
|
|
534
552
|
// src/index.ts
|
|
535
553
|
var name = "starfx-bot";
|
|
@@ -550,8 +568,9 @@ var Config2 = import_koishi2.Schema.intersect([
|
|
|
550
568
|
}).description("语录记录功能"),
|
|
551
569
|
import_koishi2.Schema.object({
|
|
552
570
|
roll: import_koishi2.Schema.boolean().default(true).description("开启roll随机数功能"),
|
|
553
|
-
undo: import_koishi2.Schema.boolean().default(true).description("机器人撤回消息功能"),
|
|
554
|
-
echo: import_koishi2.Schema.boolean().default(true).description("echo回声洞功能")
|
|
571
|
+
undo: import_koishi2.Schema.boolean().default(true).description("机器人撤回消息功能(只测试了qq的onebot适配器)"),
|
|
572
|
+
echo: import_koishi2.Schema.boolean().default(true).description("echo回声洞功能"),
|
|
573
|
+
echoBanner: import_koishi2.Schema.array(String).role("table").description("echo屏蔽词,对文本生效")
|
|
555
574
|
}).description("指令小功能"),
|
|
556
575
|
import_koishi2.Schema.object({
|
|
557
576
|
atNotSay: import_koishi2.Schema.boolean().default(true).description("开启‘艾特我又不说话’功能"),
|
|
@@ -561,6 +580,11 @@ var Config2 = import_koishi2.Schema.intersect([
|
|
|
561
580
|
iLoveYou: import_koishi2.Schema.boolean().default(true).description("开启‘我喜欢你’功能"),
|
|
562
581
|
replyBot: import_koishi2.Schema.union(["关闭", "无需at", "必须at"]).default("无需at").description("回复‘我才不是机器人!’功能")
|
|
563
582
|
}).description("特定回应功能"),
|
|
583
|
+
import_koishi2.Schema.object({
|
|
584
|
+
sendLocalImage: import_koishi2.Schema.dict(import_koishi2.Schema.object({
|
|
585
|
+
imgPath: import_koishi2.Schema.string()
|
|
586
|
+
})).role("table").description("特定指令发送本地图片功能,其中键是指令名称,imgPath是图片文件的绝对路径")
|
|
587
|
+
}),
|
|
564
588
|
import_koishi2.Schema.object({
|
|
565
589
|
openRepeat: import_koishi2.Schema.boolean().default(true).description("开启复读功能"),
|
|
566
590
|
minRepeatTimes: import_koishi2.Schema.number().default(2).description("最少重复次数"),
|
|
@@ -598,7 +622,6 @@ function apply(ctx, cfg) {
|
|
|
598
622
|
}
|
|
599
623
|
if (cfg.openSold) {
|
|
600
624
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
601
|
-
console.log("ssssss");
|
|
602
625
|
if (detectControl(controlJson, session.guildId, "sold"))
|
|
603
626
|
await session.send(await drawSold(ctx, await getImageSrc(session, param)));
|
|
604
627
|
});
|
|
@@ -615,12 +638,13 @@ function apply(ctx, cfg) {
|
|
|
615
638
|
if (detectControl(controlJson, session.guildId, "echo")) {
|
|
616
639
|
const elements = session.elements;
|
|
617
640
|
try {
|
|
618
|
-
console.log(elements);
|
|
619
641
|
while (elements[0].type === "at" || elements[0].type === "text" && !elements[0].attrs?.content.trim()) elements.shift();
|
|
620
642
|
elements[0].attrs.content = elements[0].attrs?.content.trim().split(" ").slice(1).join(" ");
|
|
621
643
|
if (elements.length == 1 && !elements[0].attrs.content?.length) {
|
|
644
|
+
if (cfg.echoBanner?.some((banText) => session.quote?.content?.includes(banText))) return "包含屏蔽词,打断echo";
|
|
622
645
|
return session.quote?.elements;
|
|
623
646
|
}
|
|
647
|
+
if (cfg.echoBanner?.some((banText) => session.content?.includes(banText))) return "包含屏蔽词,打断echo";
|
|
624
648
|
return elements;
|
|
625
649
|
} catch (e) {
|
|
626
650
|
return params;
|
|
@@ -631,14 +655,11 @@ function apply(ctx, cfg) {
|
|
|
631
655
|
if (cfg.bangdreamBorder) {
|
|
632
656
|
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) => {
|
|
633
657
|
if (detectControl(controlJson, session.guildId, "bdbd")) {
|
|
634
|
-
const p = session.send("图片处理中请稍等...");
|
|
635
|
-
console.log(param?.slice(0, 1e3));
|
|
636
658
|
const drawConfig = await handleBanGDreamConfig(options);
|
|
637
659
|
const imgSrc = await getImageSrc(session, param);
|
|
638
660
|
if (!imgSrc?.length) return "输入无效";
|
|
639
661
|
const imageBase64 = await drawBanGDream(imgSrc, drawConfig);
|
|
640
|
-
if (!imageBase64?.length) return "
|
|
641
|
-
await p;
|
|
662
|
+
if (!imageBase64?.length) return "输入无效";
|
|
642
663
|
await session.send(import_koishi2.h.image(imageBase64));
|
|
643
664
|
}
|
|
644
665
|
});
|
|
@@ -672,6 +693,12 @@ function apply(ctx, cfg) {
|
|
|
672
693
|
}
|
|
673
694
|
});
|
|
674
695
|
}
|
|
696
|
+
for (const key in cfg.sendLocalImage) {
|
|
697
|
+
ctx.command(key).action(async ({ session }) => {
|
|
698
|
+
if (detectControl(controlJson, session.guildId, "sendLocalImage") && detectControl(controlJson, session.guildId, key))
|
|
699
|
+
return import_koishi2.h.image(safeQuote(cfg.sendLocalImage[key].imgPath, false));
|
|
700
|
+
});
|
|
701
|
+
}
|
|
675
702
|
if (cfg.saveArchive) {
|
|
676
703
|
ctx.command("入典").action(async ({ session }) => {
|
|
677
704
|
if (!session.quote) return "请引用合并转发聊天记录进行入典";
|
|
@@ -687,16 +714,12 @@ function apply(ctx, cfg) {
|
|
|
687
714
|
ctx.command("获取X原图 <urls>").alias("推特原图").action(async ({ session }, urls) => {
|
|
688
715
|
if (detectControl(controlJson, session.guildId, "originImg")) {
|
|
689
716
|
let [xUrls, xIndex] = await Promise.all([
|
|
690
|
-
getXUrl(session
|
|
717
|
+
getXUrl(session?.quote?.content),
|
|
691
718
|
getXNum(session)
|
|
692
719
|
]);
|
|
693
720
|
xIndex = xIndex.length ? xIndex : xUrls.map((_, i) => i);
|
|
694
|
-
console.log(`xIndex:${xIndex}`);
|
|
695
|
-
console.log(`xUrls:${xUrls}`);
|
|
696
721
|
const filteredUrls = xIndex.filter((i) => i >= 0 && i < xUrls.length).map((i) => xUrls[i]);
|
|
697
|
-
console.log(filteredUrls);
|
|
698
722
|
const imageUrls = await getXImage(cfg.originImgRSSUrl, filteredUrls);
|
|
699
|
-
console.log(imageUrls);
|
|
700
723
|
await sendImages(session, cfg, imageUrls);
|
|
701
724
|
}
|
|
702
725
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -142,5 +142,6 @@ export declare function getXNum(session: Session): Promise<number[]>;
|
|
|
142
142
|
export declare function getXImage(rssUrl: string, xUrls: string | string[]): Promise<string[]>;
|
|
143
143
|
export declare function chunk<T>(arr: T[], size: number): T[][];
|
|
144
144
|
export declare function sendImages(session: Session, cfg: Config, imageUrls: string[]): Promise<void>;
|
|
145
|
+
export declare function safeQuote(str: string, useQuote: boolean): string;
|
|
145
146
|
export declare function test(url: string): Promise<void>;
|
|
146
147
|
export {};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -44,20 +44,21 @@ StarFreedomX机器人的小功能,自用
|
|
|
44
44
|
### 📌 可配置功能键一览
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
| 键名
|
|
48
|
-
|
|
49
|
-
| `lock`
|
|
50
|
-
| `sold`
|
|
51
|
-
| `repeat`
|
|
52
|
-
| `record`
|
|
53
|
-
| `atNotSay`
|
|
54
|
-
| `replyBot`
|
|
55
|
-
| `iLoveYou`
|
|
56
|
-
| `bdbd`
|
|
57
|
-
| `roll`
|
|
58
|
-
| `undo`
|
|
59
|
-
| `echo`
|
|
60
|
-
| `originImg`
|
|
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功能 |
|
|
60
|
+
| `originImg` | rss获取推特原图 |
|
|
61
|
+
| `sendLocalImage` | 自定义指令发送图片功能(自定义指令也可配置,键为自定义的指令名称) |
|
|
61
62
|
|
|
62
63
|
---
|
|
63
64
|
|
|
@@ -79,34 +80,23 @@ StarFreedomX机器人的小功能,自用
|
|
|
79
80
|
## 更新日志
|
|
80
81
|
|
|
81
82
|
|
|
82
|
-
| 版本 | 更新日志
|
|
83
|
-
|
|
84
|
-
| `0.0.1` | 加入封印功能
|
|
85
|
-
| `0.1.0` | 加入"卖掉了"功能
|
|
86
|
-
| `0.2.0` | 加入"艾特我又不说话"回复功能
|
|
87
|
-
| `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能
|
|
88
|
-
| `0.4.0` | 更改处理库为sharp
|
|
89
|
-
| `0.5.0` | 加入BanG Dream!边框功能
|
|
90
|
-
| `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug
|
|
91
|
-
| `0.7.0` | 加入复读功能
|
|
92
|
-
| `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式
|
|
93
|
-
| `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤
|
|
94
|
-
| `0.10.0` | 添加随机数功能
|
|
95
|
-
| `0.
|
|
96
|
-
| `0.
|
|
97
|
-
| `0.
|
|
98
|
-
| `0.
|
|
99
|
-
| `0.
|
|
100
|
-
| `0.
|
|
101
|
-
| `0.
|
|
102
|
-
| `0.13.1` | 修复pure类型绘图名称错误 |
|
|
103
|
-
| `0.13.2` | 优化了tag在权重很大情况下的筛选效率 |
|
|
104
|
-
| `0.13.3` | 不再return图片对象,防止$()可能导致的参数溢出 |
|
|
105
|
-
| `0.13.4` | Re修订:不再return图片对象,防止$()可能导致的参数溢出 |
|
|
106
|
-
| `0.13.5` | Re再修订:bdbd新增检测异常机制,防止$()可能导致的问题 |
|
|
107
|
-
| `0.13.6` | 恢复误注释内容 |
|
|
108
|
-
| `0.13.7` | 修复bdbd无param时出现的异常 |
|
|
109
|
-
| `0.14.0` | echo增加对引用消息的支持,且支持有at触发 |
|
|
110
|
-
| `0.14.3` | echo多at情况支持 |
|
|
111
|
-
| `0.15.0` | 自用rss获取推特原图 |
|
|
112
|
-
| `0.15.1` | 优化指令名称,防止冲突 |
|
|
83
|
+
| 版本 | 更新日志 |
|
|
84
|
+
|----------|-------------------------------|
|
|
85
|
+
| `0.0.1` | 加入封印功能 |
|
|
86
|
+
| `0.1.0` | 加入"卖掉了"功能 |
|
|
87
|
+
| `0.2.0` | 加入"艾特我又不说话"回复功能 |
|
|
88
|
+
| `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
|
|
89
|
+
| `0.4.0` | 更改处理库为sharp |
|
|
90
|
+
| `0.5.0` | 加入BanG Dream!边框功能 |
|
|
91
|
+
| `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
|
|
92
|
+
| `0.7.0` | 加入复读功能 |
|
|
93
|
+
| `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
|
|
94
|
+
| `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
|
|
95
|
+
| `0.10.0` | 添加随机数功能 |
|
|
96
|
+
| `0.11.0` | 增加适配于onebot(主要是qq)的撤回功能 |
|
|
97
|
+
| `0.12.0` | 加入echo功能 |
|
|
98
|
+
| `0.13.0` | 语录支持tag以及调整权重 |
|
|
99
|
+
| `0.14.0` | echo增加对引用消息的支持,且支持有at触发 |
|
|
100
|
+
| `0.15.0` | 自用rss获取推特原图 |
|
|
101
|
+
| `0.16.0` | 新增自定义指令发送本地图片功能(其实网络图片也行) |
|
|
102
|
+
| `0.16.1` | 删除无用的配置构型 |
|