koishi-plugin-starfx-bot 0.14.3 → 0.15.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 +4 -51
- package/lib/index.js +104 -1
- package/lib/utils.d.ts +6 -0
- package/package.json +6 -1
- package/readme.md +15 -13
package/lib/index.d.ts
CHANGED
|
@@ -23,58 +23,11 @@ export interface Config {
|
|
|
23
23
|
openRepeat: boolean;
|
|
24
24
|
minRepeatTimes: number;
|
|
25
25
|
repeatPossibility: number;
|
|
26
|
+
originImg: boolean;
|
|
27
|
+
originImgRSSUrl: string;
|
|
28
|
+
proxyUrl: string;
|
|
26
29
|
featureControl: string;
|
|
27
30
|
}
|
|
28
|
-
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
29
|
-
openLock: Schema<boolean, boolean>;
|
|
30
|
-
openSold: Schema<boolean, boolean>;
|
|
31
|
-
bangdreamBorder: Schema<boolean, boolean>;
|
|
32
|
-
}> | Schemastery.ObjectS<{
|
|
33
|
-
record: Schema<boolean, boolean>;
|
|
34
|
-
tagWeight: Schema<number, number>;
|
|
35
|
-
saveArchive: Schema<boolean, boolean>;
|
|
36
|
-
}> | Schemastery.ObjectS<{
|
|
37
|
-
roll: Schema<boolean, boolean>;
|
|
38
|
-
undo: Schema<boolean, boolean>;
|
|
39
|
-
echo: Schema<boolean, boolean>;
|
|
40
|
-
}> | Schemastery.ObjectS<{
|
|
41
|
-
atNotSay: Schema<boolean, boolean>;
|
|
42
|
-
atNotSayProperty: Schema<number, number>;
|
|
43
|
-
atNotSayOther: Schema<boolean, boolean>;
|
|
44
|
-
atNotSayOtherProperty: Schema<number, number>;
|
|
45
|
-
iLoveYou: Schema<boolean, boolean>;
|
|
46
|
-
replyBot: Schema<"关闭" | "无需at" | "必须at", "关闭" | "无需at" | "必须at">;
|
|
47
|
-
}> | Schemastery.ObjectS<{
|
|
48
|
-
openRepeat: Schema<boolean, boolean>;
|
|
49
|
-
minRepeatTimes: Schema<number, number>;
|
|
50
|
-
repeatPossibility: Schema<number, number>;
|
|
51
|
-
}> | Schemastery.ObjectS<{
|
|
52
|
-
featureControl: Schema<string, string>;
|
|
53
|
-
}>, {
|
|
54
|
-
openLock: boolean;
|
|
55
|
-
openSold: boolean;
|
|
56
|
-
bangdreamBorder: boolean;
|
|
57
|
-
} & import("cosmokit").Dict & {
|
|
58
|
-
record: boolean;
|
|
59
|
-
tagWeight: number;
|
|
60
|
-
saveArchive: boolean;
|
|
61
|
-
} & {
|
|
62
|
-
roll: boolean;
|
|
63
|
-
undo: boolean;
|
|
64
|
-
echo: boolean;
|
|
65
|
-
} & {
|
|
66
|
-
atNotSay: boolean;
|
|
67
|
-
atNotSayProperty: number;
|
|
68
|
-
atNotSayOther: boolean;
|
|
69
|
-
atNotSayOtherProperty: number;
|
|
70
|
-
iLoveYou: boolean;
|
|
71
|
-
replyBot: "关闭" | "无需at" | "必须at";
|
|
72
|
-
} & {
|
|
73
|
-
openRepeat: boolean;
|
|
74
|
-
minRepeatTimes: number;
|
|
75
|
-
repeatPossibility: number;
|
|
76
|
-
} & {
|
|
77
|
-
featureControl: string;
|
|
78
|
-
}>;
|
|
31
|
+
export declare const Config: Schema<Schemastery.ObjectS<{}>, {} & import("cosmokit").Dict>;
|
|
79
32
|
export declare const usage = "<h2>StarFreedomX\u7684\u81EA\u7528\u63D2\u4EF6 \u653E\u4E86\u4E00\u4E9B\u5C0F\u529F\u80FD</h2>\n ";
|
|
80
33
|
export declare function apply(ctx: Context, cfg: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,11 @@ var import_fs = __toESM(require("fs"));
|
|
|
59
59
|
var import_node_path = __toESM(require("node:path"));
|
|
60
60
|
var import_sharp = __toESM(require("sharp"));
|
|
61
61
|
var import_jimp = require("jimp");
|
|
62
|
+
var import_rss_parser = __toESM(require("rss-parser"));
|
|
63
|
+
var cheerio = __toESM(require("cheerio"));
|
|
64
|
+
var import_http_proxy_agent = require("http-proxy-agent");
|
|
65
|
+
var import_https_proxy_agent = require("https-proxy-agent");
|
|
66
|
+
var import_axios = __toESM(require("axios"));
|
|
62
67
|
async function addRecord(ctx, gid, avatarUrl) {
|
|
63
68
|
const recordDir = `${assetsDir}/record/${gid}`;
|
|
64
69
|
const avatarBuffer = await ctx.http.get(avatarUrl, { responseType: "arraybuffer" });
|
|
@@ -456,6 +461,75 @@ async function undo(cfg, session) {
|
|
|
456
461
|
}
|
|
457
462
|
}
|
|
458
463
|
__name(undo, "undo");
|
|
464
|
+
async function getXUrl(urls) {
|
|
465
|
+
const regex = /https:\/\/x\.com\/([^\/]+)\/status\/(\d+)/g;
|
|
466
|
+
let match;
|
|
467
|
+
const results = [];
|
|
468
|
+
while ((match = regex.exec(urls)) !== null) {
|
|
469
|
+
const [fullUrl] = match;
|
|
470
|
+
results.push(fullUrl);
|
|
471
|
+
}
|
|
472
|
+
return results;
|
|
473
|
+
}
|
|
474
|
+
__name(getXUrl, "getXUrl");
|
|
475
|
+
var parser = new import_rss_parser.default({
|
|
476
|
+
customFields: {
|
|
477
|
+
item: ["description", "link"]
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
async function getXNum(session) {
|
|
481
|
+
const params = session.content.trim().split(" ").slice(1).filter((item) => !isNaN(+item) && item).map((str) => Number(str) - 1);
|
|
482
|
+
return params;
|
|
483
|
+
}
|
|
484
|
+
__name(getXNum, "getXNum");
|
|
485
|
+
async function getXImage(rssUrl, xUrls) {
|
|
486
|
+
const xUrlsArray = Array.isArray(xUrls) ? xUrls : [xUrls];
|
|
487
|
+
const feed = await parser.parseURL(rssUrl);
|
|
488
|
+
const allImageUrls = [];
|
|
489
|
+
for (const xUrl of xUrlsArray) {
|
|
490
|
+
const item = feed.items.find((i) => i.link === xUrl);
|
|
491
|
+
if (item) {
|
|
492
|
+
const $ = cheerio.load(item.description);
|
|
493
|
+
$("img").each((_, el) => {
|
|
494
|
+
const src = $(el).attr("src");
|
|
495
|
+
if (src) allImageUrls.push(src);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return allImageUrls;
|
|
500
|
+
}
|
|
501
|
+
__name(getXImage, "getXImage");
|
|
502
|
+
function chunk(arr, size) {
|
|
503
|
+
const res = [];
|
|
504
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
505
|
+
res.push(arr.slice(i, i + size));
|
|
506
|
+
}
|
|
507
|
+
return res;
|
|
508
|
+
}
|
|
509
|
+
__name(chunk, "chunk");
|
|
510
|
+
async function sendImages(session, cfg, imageUrls) {
|
|
511
|
+
const chunks = chunk(imageUrls, 10);
|
|
512
|
+
for (const group of chunks) {
|
|
513
|
+
const messages = await Promise.all(
|
|
514
|
+
group.map(async (url) => import_koishi.h.image(await getXImageBase64(url, cfg)))
|
|
515
|
+
);
|
|
516
|
+
const message = messages.join("");
|
|
517
|
+
await session.send(message);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
__name(sendImages, "sendImages");
|
|
521
|
+
async function getXImageBase64(url, cfg) {
|
|
522
|
+
const httpAgent = new import_http_proxy_agent.HttpProxyAgent(cfg.proxyUrl);
|
|
523
|
+
const httpsAgent = new import_https_proxy_agent.HttpsProxyAgent(cfg.proxyUrl);
|
|
524
|
+
import_axios.default.defaults.httpAgent = httpAgent;
|
|
525
|
+
import_axios.default.defaults.httpsAgent = httpsAgent;
|
|
526
|
+
const res = await import_axios.default.get(url, { responseType: "arraybuffer" });
|
|
527
|
+
const base64 = Buffer.from(res.data, "binary").toString("base64");
|
|
528
|
+
const dataUrl = `data:image/png;base64,${base64}`;
|
|
529
|
+
console.log("success");
|
|
530
|
+
return dataUrl;
|
|
531
|
+
}
|
|
532
|
+
__name(getXImageBase64, "getXImageBase64");
|
|
459
533
|
|
|
460
534
|
// src/index.ts
|
|
461
535
|
var name = "starfx-bot";
|
|
@@ -492,6 +566,17 @@ var Config2 = import_koishi2.Schema.intersect([
|
|
|
492
566
|
minRepeatTimes: import_koishi2.Schema.number().default(2).description("最少重复次数"),
|
|
493
567
|
repeatPossibility: import_koishi2.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.3).description("复读发生概率")
|
|
494
568
|
}).description("复读功能"),
|
|
569
|
+
import_koishi2.Schema.object({
|
|
570
|
+
originImg: import_koishi2.Schema.boolean().default(false).description("根据链接获取原图开关")
|
|
571
|
+
}).description("自用功能"),
|
|
572
|
+
import_koishi2.Schema.union([
|
|
573
|
+
import_koishi2.Schema.object({
|
|
574
|
+
originImg: import_koishi2.Schema.const(true).required(),
|
|
575
|
+
originImgRSSUrl: import_koishi2.Schema.string().required().description("推特列表rss地址"),
|
|
576
|
+
proxyUrl: import_koishi2.Schema.string().default("http://127.0.0.1:7890").description("代理地址")
|
|
577
|
+
}),
|
|
578
|
+
import_koishi2.Schema.object({})
|
|
579
|
+
]),
|
|
495
580
|
import_koishi2.Schema.object({
|
|
496
581
|
featureControl: import_koishi2.Schema.string().role("textarea", { rows: [15] }).default("{\n\n}").description(`黑/白名单配置,语法为JSON格式(可以不缩进),<br>
|
|
497
582
|
可配置功能键及语法详见 [项目地址](https://github.com/StarFreedomX/starfx-bot)或[npm发布页](https://www.npmjs.com/package/koishi-plugin-bangdream-ccg)`)
|
|
@@ -513,6 +598,7 @@ function apply(ctx, cfg) {
|
|
|
513
598
|
}
|
|
514
599
|
if (cfg.openSold) {
|
|
515
600
|
ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
|
|
601
|
+
console.log("ssssss");
|
|
516
602
|
if (detectControl(controlJson, session.guildId, "sold"))
|
|
517
603
|
await session.send(await drawSold(ctx, await getImageSrc(session, param)));
|
|
518
604
|
});
|
|
@@ -597,6 +683,24 @@ function apply(ctx, cfg) {
|
|
|
597
683
|
await undo(cfg, session);
|
|
598
684
|
});
|
|
599
685
|
}
|
|
686
|
+
if (cfg.originImg) {
|
|
687
|
+
ctx.command("获取原图 <urls>").action(async ({ session }, urls) => {
|
|
688
|
+
if (detectControl(controlJson, session.guildId, "originImg")) {
|
|
689
|
+
let [xUrls, xIndex] = await Promise.all([
|
|
690
|
+
getXUrl(session.quote.content),
|
|
691
|
+
getXNum(session)
|
|
692
|
+
]);
|
|
693
|
+
xIndex = xIndex.length ? xIndex : xUrls.map((_, i) => i);
|
|
694
|
+
console.log(`xIndex:${xIndex}`);
|
|
695
|
+
console.log(`xUrls:${xUrls}`);
|
|
696
|
+
const filteredUrls = xIndex.filter((i) => i >= 0 && i < xUrls.length).map((i) => xUrls[i]);
|
|
697
|
+
console.log(filteredUrls);
|
|
698
|
+
const imageUrls = await getXImage(cfg.originImgRSSUrl, filteredUrls);
|
|
699
|
+
console.log(imageUrls);
|
|
700
|
+
await sendImages(session, cfg, imageUrls);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
600
704
|
ctx.middleware(async (session, next) => {
|
|
601
705
|
const elements = session.elements;
|
|
602
706
|
if (cfg.openRepeat && detectControl(controlJson, session.guildId, "repeat")) {
|
|
@@ -621,7 +725,6 @@ function apply(ctx, cfg) {
|
|
|
621
725
|
});
|
|
622
726
|
if (process.env.NODE_ENV === "development") {
|
|
623
727
|
ctx.command("test").action(async ({ session }) => {
|
|
624
|
-
await session.send(import_koishi2.h.video("https://video.twimg.com/amplify_video/1920672748596043776/vid/avc1/1080x1920/c3BNP3qg4-sT82fR.mp4?tag=21"));
|
|
625
728
|
});
|
|
626
729
|
}
|
|
627
730
|
function initAssets() {
|
package/lib/utils.d.ts
CHANGED
|
@@ -137,4 +137,10 @@ export declare function handleRoll(session: Session): string;
|
|
|
137
137
|
* @param session session
|
|
138
138
|
*/
|
|
139
139
|
export declare function undo(cfg: Config, session: Session): Promise<void>;
|
|
140
|
+
export declare function getXUrl(urls: string): Promise<any[]>;
|
|
141
|
+
export declare function getXNum(session: Session): Promise<number[]>;
|
|
142
|
+
export declare function getXImage(rssUrl: string, xUrls: string | string[]): Promise<string[]>;
|
|
143
|
+
export declare function chunk<T>(arr: T[], size: number): T[][];
|
|
144
|
+
export declare function sendImages(session: Session, cfg: Config, imageUrls: string[]): Promise<void>;
|
|
145
|
+
export declare function test(url: string): Promise<void>;
|
|
140
146
|
export {};
|
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.15.0",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
10
10
|
"files": [
|
|
@@ -36,7 +36,12 @@
|
|
|
36
36
|
"koishi": "^4.18.7"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"axios": "^1.9.0",
|
|
40
|
+
"cheerio": "^1.0.0",
|
|
41
|
+
"http-proxy-agent": "^7.0.2",
|
|
42
|
+
"https-proxy-agent": "^7.0.6",
|
|
39
43
|
"jimp": "^1.6.0",
|
|
44
|
+
"rss-parser": "^3.13.0",
|
|
40
45
|
"sharp": "^0.34.1"
|
|
41
46
|
}
|
|
42
47
|
}
|
package/readme.md
CHANGED
|
@@ -44,19 +44,20 @@ 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`
|
|
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获取推特原图 |
|
|
60
61
|
|
|
61
62
|
---
|
|
62
63
|
|
|
@@ -107,3 +108,4 @@ StarFreedomX机器人的小功能,自用
|
|
|
107
108
|
| `0.13.7` | 修复bdbd无param时出现的异常 |
|
|
108
109
|
| `0.14.0` | echo增加对引用消息的支持,且支持有at触发 |
|
|
109
110
|
| `0.14.3` | echo多at情况支持 |
|
|
111
|
+
| `0.15.0` | 自用rss获取推特原图 |
|