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.
- package/lib/index.js +33 -15
- package/package.json +1 -1
- 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
|
|
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
|
-
|
|
312
|
-
|
|
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
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
return
|
|
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