koishi-plugin-starfx-bot 0.17.0 → 0.18.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.
Files changed (3) hide show
  1. package/lib/index.js +33 -15
  2. package/package.json +1 -1
  3. package/readme.md +3 -0
package/lib/index.js CHANGED
@@ -73,11 +73,11 @@ async function addRecord(ctx, gid, avatarUrl) {
73
73
  }
74
74
  __name(addRecord, "addRecord");
75
75
  async function getRecord(cfg, gid, tag) {
76
- const tagConfigPath = import_node_path.default.join(assetsDir, "tagConfig", `${gid}.json`);
77
- const links = cfg.recordLink;
76
+ const links = structuredClone(cfg.recordLink);
78
77
  links[gid] = { linkGroup: gid, linkWeight: 100 };
79
78
  const selectGid = getRandomLinkGroup(links).replaceAll(":", "_");
80
79
  const recordDir = import_node_path.default.join(assetsDir, "record", selectGid);
80
+ const tagConfigPath = import_node_path.default.join(assetsDir, "tagConfig", `${selectGid}.json`);
81
81
  if (!import_fs.default.existsSync(recordDir)) return null;
82
82
  const files = import_fs.default.readdirSync(recordDir).filter((file) => /\.(png|jpe?g|webp|gif)$/i.test(file));
83
83
  if (!files.length) return null;
@@ -308,8 +308,9 @@ async function getImageFromUrl(ctx, url) {
308
308
  }
309
309
  __name(getImageFromUrl, "getImageFromUrl");
310
310
  async function atNotSayReply(cfg, session, elements) {
311
- if ((cfg.atNotSay || cfg.atNotSayOther) && elements.length === 1 && elements[0].type === "at") {
312
- const isAtSelf = elements[0].attrs.id === session.selfId;
311
+ const trimElements = elements.filter((e) => !(e.type === "text" && /^\s*$/.test(e.attrs.content)));
312
+ if ((cfg.atNotSay || cfg.atNotSayOther) && trimElements.length === 1 && trimElements[0].type === "at") {
313
+ const isAtSelf = trimElements[0].attrs.id === session.selfId;
313
314
  if (isAtSelf && cfg.atNotSay && import_koishi.Random.bool(cfg.atNotSayProperty)) {
314
315
  await session.send(session.text("middleware.messages.atNotReply"));
315
316
  } else if (!isAtSelf && cfg.atNotSayOther && import_koishi.Random.bool(cfg.atNotSayOtherProperty)) {
@@ -717,20 +718,33 @@ function apply(ctx, cfg) {
717
718
  });
718
719
  }
719
720
  if (cfg.echo) {
720
- ctx.command("echo <params>").action(async ({ session }, params) => {
721
+ ctx.command("echo <params>").option("time", "-t <time: number> 指定时间(min)").action(async ({ session, options }, params) => {
721
722
  if (detectControl(controlJson, session.guildId, "echo")) {
722
723
  const elements = session.elements;
723
- try {
724
- while (elements[0].type === "at" || elements[0].type === "text" && !elements[0].attrs?.content.trim()) elements.shift();
725
- elements[0].attrs.content = elements[0].attrs?.content.trim().split(" ").slice(1).join(" ");
726
- if (elements.length == 1 && !elements[0].attrs.content?.length) {
727
- if (cfg.echoBanner?.some((banText) => session.quote?.content?.includes(banText))) return "包含屏蔽词,打断echo";
728
- return session.quote?.elements;
724
+ const getEchoMessage = /* @__PURE__ */ __name(() => {
725
+ try {
726
+ while (elements[0].type === "at" || elements[0].type === "text" && !elements[0].attrs?.content.trim()) elements.shift();
727
+ elements[0].attrs.content = elements[0].attrs?.content.trim().split(/\s/).slice(1).join(" ");
728
+ elements.forEach((ele) => {
729
+ ele.attrs.content = ele.attrs?.content.trim().split(/\s/).filter((v, i, a) => v !== "-t" && a[i - 1] !== "-t").join(" ");
730
+ });
731
+ if (elements.length == 1 && !elements[0].attrs.content?.length) {
732
+ if (cfg.echoBanner?.some((banText) => session.quote?.content?.includes(banText))) return "包含屏蔽词,打断echo";
733
+ return session.quote?.elements;
734
+ }
735
+ if (cfg.echoBanner?.some((banText) => session.content?.includes(banText))) return "包含屏蔽词,打断echo";
736
+ return elements;
737
+ } catch (e) {
738
+ return params;
729
739
  }
730
- if (cfg.echoBanner?.some((banText) => session.content?.includes(banText))) return "包含屏蔽词,打断echo";
731
- return elements;
732
- } catch (e) {
733
- return params;
740
+ }, "getEchoMessage");
741
+ const echoMessages = getEchoMessage();
742
+ if (!options?.time && options.time > 0) {
743
+ return echoMessages;
744
+ } else {
745
+ setTimeout(async () => {
746
+ await ctx.broadcast([session.gid], echoMessages);
747
+ }, options.time * 60 * 1e3);
734
748
  }
735
749
  }
736
750
  });
@@ -924,6 +938,10 @@ function apply(ctx, cfg) {
924
938
  });
925
939
  if (process.env.NODE_ENV === "development") {
926
940
  ctx.command("test").action(async ({ session }) => {
941
+ await session.send(" d d ");
942
+ });
943
+ ctx.middleware(async (session, next) => {
944
+ return next();
927
945
  });
928
946
  }
929
947
  function initAssets() {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.17.0",
7
+ "version": "0.18.1",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -105,3 +105,6 @@ StarFreedomX机器人的小功能,自用
105
105
  | `0.16.3` | 发送文件前转为使用base64 |
106
106
  | `0.16.4` | 修复转base64功能的依赖问题 |
107
107
  | `0.17.0` | 语录功能新增链接,可以配置权重 |
108
+ | `0.17.1` | 修复语录链接跨群bug |
109
+ | `0.18.0` | 新增定时echo |
110
+ | `0.18.1` | 修复艾特不说话功能 |