koishi-plugin-starfx-bot 0.15.0 → 0.16.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 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
- const params = session.content.trim().split(" ").slice(1).filter((item) => !isNaN(+item) && item).map((str) => Number(str) - 1);
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
- const message = messages.join("");
517
- await session.send(message);
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,13 @@ 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
+ white: import_koishi2.Schema.string(),
586
+ black: import_koishi2.Schema.string(),
587
+ imgPath: import_koishi2.Schema.string()
588
+ })).role("table").description("特定指令发送本地图片功能,其中键是指令名称,black/white是黑白名单(直接输入群号用半角逗号分隔,两个都不输入默认全量),imgPath是图片文件的绝对路径")
589
+ }),
564
590
  import_koishi2.Schema.object({
565
591
  openRepeat: import_koishi2.Schema.boolean().default(true).description("开启复读功能"),
566
592
  minRepeatTimes: import_koishi2.Schema.number().default(2).description("最少重复次数"),
@@ -598,7 +624,6 @@ function apply(ctx, cfg) {
598
624
  }
599
625
  if (cfg.openSold) {
600
626
  ctx.command("卖掉了 [param]").action(async ({ session }, param) => {
601
- console.log("ssssss");
602
627
  if (detectControl(controlJson, session.guildId, "sold"))
603
628
  await session.send(await drawSold(ctx, await getImageSrc(session, param)));
604
629
  });
@@ -615,12 +640,13 @@ function apply(ctx, cfg) {
615
640
  if (detectControl(controlJson, session.guildId, "echo")) {
616
641
  const elements = session.elements;
617
642
  try {
618
- console.log(elements);
619
643
  while (elements[0].type === "at" || elements[0].type === "text" && !elements[0].attrs?.content.trim()) elements.shift();
620
644
  elements[0].attrs.content = elements[0].attrs?.content.trim().split(" ").slice(1).join(" ");
621
645
  if (elements.length == 1 && !elements[0].attrs.content?.length) {
646
+ if (cfg.echoBanner?.some((banText) => session.quote?.content?.includes(banText))) return "包含屏蔽词,打断echo";
622
647
  return session.quote?.elements;
623
648
  }
649
+ if (cfg.echoBanner?.some((banText) => session.content?.includes(banText))) return "包含屏蔽词,打断echo";
624
650
  return elements;
625
651
  } catch (e) {
626
652
  return params;
@@ -631,14 +657,11 @@ function apply(ctx, cfg) {
631
657
  if (cfg.bangdreamBorder) {
632
658
  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
659
  if (detectControl(controlJson, session.guildId, "bdbd")) {
634
- const p = session.send("图片处理中请稍等...");
635
- console.log(param?.slice(0, 1e3));
636
660
  const drawConfig = await handleBanGDreamConfig(options);
637
661
  const imgSrc = await getImageSrc(session, param);
638
662
  if (!imgSrc?.length) return "输入无效";
639
663
  const imageBase64 = await drawBanGDream(imgSrc, drawConfig);
640
- if (!imageBase64?.length) return "输入无效...";
641
- await p;
664
+ if (!imageBase64?.length) return "输入无效";
642
665
  await session.send(import_koishi2.h.image(imageBase64));
643
666
  }
644
667
  });
@@ -672,6 +695,12 @@ function apply(ctx, cfg) {
672
695
  }
673
696
  });
674
697
  }
698
+ for (const key in cfg.sendLocalImage) {
699
+ ctx.command(key).action(async ({ session }) => {
700
+ if (detectControl(controlJson, session.guildId, "sendLocalImage") && detectControl(controlJson, session.guildId, key))
701
+ return import_koishi2.h.image(safeQuote(cfg.sendLocalImage[key].imgPath, false));
702
+ });
703
+ }
675
704
  if (cfg.saveArchive) {
676
705
  ctx.command("入典").action(async ({ session }) => {
677
706
  if (!session.quote) return "请引用合并转发聊天记录进行入典";
@@ -684,19 +713,15 @@ function apply(ctx, cfg) {
684
713
  });
685
714
  }
686
715
  if (cfg.originImg) {
687
- ctx.command("获取原图 <urls>").action(async ({ session }, urls) => {
716
+ ctx.command("获取X原图 <urls>").alias("推特原图").action(async ({ session }, urls) => {
688
717
  if (detectControl(controlJson, session.guildId, "originImg")) {
689
718
  let [xUrls, xIndex] = await Promise.all([
690
- getXUrl(session.quote.content),
719
+ getXUrl(session?.quote?.content),
691
720
  getXNum(session)
692
721
  ]);
693
722
  xIndex = xIndex.length ? xIndex : xUrls.map((_, i) => i);
694
- console.log(`xIndex:${xIndex}`);
695
- console.log(`xUrls:${xUrls}`);
696
723
  const filteredUrls = xIndex.filter((i) => i >= 0 && i < xUrls.length).map((i) => xUrls[i]);
697
- console.log(filteredUrls);
698
724
  const imageUrls = await getXImage(cfg.originImgRSSUrl, filteredUrls);
699
- console.log(imageUrls);
700
725
  await sendImages(session, cfg, imageUrls);
701
726
  }
702
727
  });
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
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.15.0",
7
+ "version": "0.16.0",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -44,20 +44,21 @@ StarFreedomX机器人的小功能,自用
44
44
  ### 📌 可配置功能键一览
45
45
 
46
46
 
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获取推特原图 |
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
 
@@ -109,3 +110,5 @@ StarFreedomX机器人的小功能,自用
109
110
  | `0.14.0` | echo增加对引用消息的支持,且支持有at触发 |
110
111
  | `0.14.3` | echo多at情况支持 |
111
112
  | `0.15.0` | 自用rss获取推特原图 |
113
+ | `0.15.1` | 优化指令名称,防止冲突 |
114
+ | `0.16.0` | 新增自定义指令发送本地图片功能(其实网络图片也行) |