koishi-plugin-starfx-bot 0.27.1 → 0.27.2
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 +48 -8
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -63,7 +63,7 @@ var package_default = {
|
|
|
63
63
|
contributors: [
|
|
64
64
|
"StarFreedomX <starfreedomx@outlook.com>"
|
|
65
65
|
],
|
|
66
|
-
version: "0.27.
|
|
66
|
+
version: "0.27.2",
|
|
67
67
|
main: "lib/index.js",
|
|
68
68
|
typings: "lib/index.d.ts",
|
|
69
69
|
files: [
|
|
@@ -1739,7 +1739,6 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
|
|
|
1739
1739
|
const targetLength = channel.pickupLength;
|
|
1740
1740
|
const content = session.content?.trim();
|
|
1741
1741
|
if (targetLength > 0 && new RegExp(`^\\d{${targetLength}}$`).test(content)) {
|
|
1742
|
-
if (!await canBotManage(session)) return session.text("middleware.messages.notManager");
|
|
1743
1742
|
const setGroupName = /* @__PURE__ */ __name(async (name2) => {
|
|
1744
1743
|
const internal = session.bot.internal;
|
|
1745
1744
|
if (typeof internal?._request === "function" && session.platform === "onebot") {
|
|
@@ -1760,19 +1759,61 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
|
|
|
1760
1759
|
}
|
|
1761
1760
|
throw new Error(session.text("middleware.messages.editFuncNotFound"));
|
|
1762
1761
|
}, "setGroupName");
|
|
1762
|
+
const getCurrentGroupName = /* @__PURE__ */ __name(async () => {
|
|
1763
|
+
const channel2 = await session.bot.getChannel(session.channelId);
|
|
1764
|
+
return channel2?.name;
|
|
1765
|
+
}, "getCurrentGroupName");
|
|
1763
1766
|
try {
|
|
1764
|
-
|
|
1765
|
-
|
|
1767
|
+
const replaceNumberInName = /* @__PURE__ */ __name((name2, digits) => {
|
|
1768
|
+
if (!name2 || !name2.length) return digits;
|
|
1769
|
+
const targetLen = digits.replace(/\s+/g, "").length;
|
|
1770
|
+
const n = name2.length;
|
|
1771
|
+
for (let i = 0; i < n; i++) {
|
|
1772
|
+
for (let j = i + 1; j <= n; j++) {
|
|
1773
|
+
const sub = name2.slice(i, j);
|
|
1774
|
+
const compact = sub.replace(/\s+/g, "");
|
|
1775
|
+
if (compact.length === targetLen && /^\d+$/.test(compact)) {
|
|
1776
|
+
return name2.slice(0, i) + digits + name2.slice(j);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
return digits + " " + name2;
|
|
1781
|
+
}, "replaceNumberInName");
|
|
1782
|
+
const currentName = await getCurrentGroupName();
|
|
1783
|
+
const contentDigits = String(content).replace(/\s+/g, "");
|
|
1784
|
+
let newName;
|
|
1785
|
+
if (currentName) {
|
|
1786
|
+
newName = replaceNumberInName(currentName, contentDigits);
|
|
1787
|
+
} else {
|
|
1788
|
+
newName = contentDigits;
|
|
1789
|
+
}
|
|
1790
|
+
await setGroupName(newName);
|
|
1791
|
+
await session.send(session.text("middleware.messages.editGroupNameSuccess", { content: newName }));
|
|
1766
1792
|
return;
|
|
1767
1793
|
} catch (e) {
|
|
1768
1794
|
starfxLogger.warn(`纯数字修改失败,尝试添加空格重试: ${content}`);
|
|
1769
1795
|
try {
|
|
1770
1796
|
const spacedContent = content.replace(/(\d{3})(?=\d)/g, "$1 ");
|
|
1771
|
-
await
|
|
1772
|
-
|
|
1797
|
+
const currentName = await getCurrentGroupName();
|
|
1798
|
+
const finalName = currentName ? (() => {
|
|
1799
|
+
const targetLen = spacedContent.replace(/\s+/g, "").length;
|
|
1800
|
+
const n = currentName.length;
|
|
1801
|
+
for (let i = 0; i < n; i++) {
|
|
1802
|
+
for (let j = i + 1; j <= n; j++) {
|
|
1803
|
+
const sub = currentName.slice(i, j);
|
|
1804
|
+
const compact = sub.replace(/\s+/g, "");
|
|
1805
|
+
if (compact.length === targetLen && /^\d+$/.test(compact)) {
|
|
1806
|
+
return currentName.slice(0, i) + spacedContent + currentName.slice(j);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
return spacedContent + " " + currentName;
|
|
1811
|
+
})() : spacedContent;
|
|
1812
|
+
await setGroupName(finalName);
|
|
1813
|
+
await session.send(session.text("middleware.messages.editGroupNameRetrySuccess", { content, spacedContent: finalName }));
|
|
1773
1814
|
return;
|
|
1774
1815
|
} catch (retryError) {
|
|
1775
|
-
starfxLogger.error(
|
|
1816
|
+
starfxLogger.error(`尝试添加空格修改群名仍失败: ${retryError}`);
|
|
1776
1817
|
}
|
|
1777
1818
|
}
|
|
1778
1819
|
}
|
|
@@ -1799,7 +1840,6 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
|
|
|
1799
1840
|
});
|
|
1800
1841
|
if (process.env.NODE_ENV === "development") {
|
|
1801
1842
|
ctx.command("test [params]").action(async ({ session }) => {
|
|
1802
|
-
await session.send("test");
|
|
1803
1843
|
});
|
|
1804
1844
|
ctx.middleware(async (session, next) => {
|
|
1805
1845
|
await session.send("");
|
package/package.json
CHANGED
package/readme.md
CHANGED