koishi-plugin-starfx-bot 0.27.1 → 0.27.3

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 +90 -34
  2. package/package.json +1 -1
  3. package/readme.md +2 -0
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  // src/locales/zh-CN.yml
34
34
  var require_zh_CN = __commonJS({
35
35
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { roll: { messages: { noParam: "你问啥?", invalid: "你要不看看你说的是啥", "too-many": "太、太多了啦!", noodles: "扔出了{num}个{noodles}面的骰子,点数如下:{points}", possibility: "{param}是{possibility}%", choose: "当然是{option}啦!" } }, "room-number": { messages: { roomNumber: "当前的房间号是: {room}", changeRoom: "已将当前房间号 {oldRoom} 修改为 {newRoom}", newRoom: "已添加房间号: {room}", noRoom: "当前没有保存的房间", delRoom: "已删除房间: {room}", invalid: "无效输入" } }, forward: { messages: { delete: "已删除转发群聊: {gid}", noTarget: "未配置转发群组", success: "已转发消息到: {target}", noMessage: "请引用要转发的消息", setOK: "已配置转发: {target}", forwardContent: "[转发消息]<br/> {content}" } }, "waiting-play": { messages: { addReady: "已添加,当前待机{num}人: <br/>{list}", delReady: "已删除,当前待机{num}人: <br/>{list}", delFailed: "未删除,当前待机{num}人: <br/>{list}", clearReady: "待机列表已清空", listReady: "当前待机{num}人: <br/>{list}", invalid: "输入无效" } }, 开启车牌检测: { messages: { success: "车牌检测:已打开\n当前车牌位数: {length}", noPermission: "你没有权限开启车牌检测", noGuild: "请在群聊中使用该指令", invalidLength: "位数设定不合理,请输入 1-20 之间的数字" } }, 关闭车牌检测: { messages: { success: "已关闭车牌检测", noPermission: "你没有权限关闭车牌检测", noGuild: "请在群聊中使用该指令" } }, 车牌检测状态: { messages: { enabled: "车牌检测: 已打开\n当前车牌位数: {length}", disabled: "车牌检测: 已关闭", managerEnabled: "管理员权限正常", managerDisabled: "无管理员权限,无法修改群名", noPermission: "你没有权限查看车牌检测状态", noGuild: "请在群聊中使用该指令" } }, 车牌检测权限: { messages: { status: { enabled: "普通群员开关车牌检测: 允许", disabled: "普通群员开关车牌检测: 禁止" }, enabled: "已允许普通群员开关车牌检测", disabled: "已禁止普通群员开关车牌检测", invalid: "无效输入,请输入 开 / 关", noPermission: "你没有权限设置车牌检测权限", noGuild: "请在群聊中使用该指令" } } }, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你", notManager: "当前bot没有管理员权限,无法修改群名", editFuncNotFound: "无法找到设置群名的底层方法", editGroupNameSuccess: "检测到车牌 {content},群名修改成功!", editGroupNameRetrySuccess: '检测到车牌 {content},由于限制已修改为 "{spacedContent}"' } } };
36
+ module2.exports = { commands: { roll: { messages: { noParam: "你问啥?", invalid: "你要不看看你说的是啥", "too-many": "太、太多了啦!", noodles: "扔出了{num}个{noodles}面的骰子,点数如下:{points}", possibility: "{param}是{possibility}%", choose: "当然是{option}啦!" } }, "room-number": { messages: { roomNumber: "当前的房间号是: {room}", changeRoom: "已将当前房间号 {oldRoom} 修改为 {newRoom}", newRoom: "已添加房间号: {room}", noRoom: "当前没有保存的房间", delRoom: "已删除房间: {room}", invalid: "无效输入" } }, forward: { messages: { delete: "已删除转发群聊: {gid}", noTarget: "未配置转发群组", success: "已转发消息到: {target}", noMessage: "请引用要转发的消息", setOK: "已配置转发: {target}", forwardContent: "[转发消息]<br/> {content}" } }, "waiting-play": { messages: { addReady: "已添加,当前待机{num}人: <br/>{list}", delReady: "已删除,当前待机{num}人: <br/>{list}", delFailed: "未删除,当前待机{num}人: <br/>{list}", clearReady: "待机列表已清空", listReady: "当前待机{num}人: <br/>{list}", invalid: "输入无效" } }, 开启车牌检测: { messages: { success: "车牌检测:已打开\n当前车牌位数: {length}", noPermission: "你没有权限开启车牌检测", noGuild: "请在群聊中使用该指令", invalidLength: "位数设定不合理,请输入 1-20 之间的数字" } }, 关闭车牌检测: { messages: { success: "已关闭车牌检测", noPermission: "你没有权限关闭车牌检测", noGuild: "请在群聊中使用该指令" } }, 车牌检测状态: { messages: { enabled: "车牌检测: 已打开\n当前车牌位数: {length}", disabled: "车牌检测: 已关闭", managerEnabled: "管理员权限正常", managerDisabled: "无管理员权限,无法修改群名", noPermission: "你没有权限查看车牌检测状态", noGuild: "请在群聊中使用该指令" } }, 车牌检测权限: { messages: { status: { enabled: "普通群员开关车牌检测: 允许", disabled: "普通群员开关车牌检测: 禁止" }, enabled: "已允许普通群员开关车牌检测", disabled: "已禁止普通群员开关车牌检测", invalid: "无效输入,请输入 开 / 关", noPermission: "你没有权限设置车牌检测权限", noGuild: "请在群聊中使用该指令" } } }, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你", notManager: "当前bot没有管理员权限,无法修改群名", editFuncNotFound: "无法找到设置群名的底层方法", editGroupNameSuccess: "已修改群名: {content}", editGroupNameRetrySuccess: '修改群名: "{content}"失败,由于限制已修改为: "{spacedContent}"' } } };
37
37
  }
38
38
  });
39
39
 
@@ -63,7 +63,7 @@ var package_default = {
63
63
  contributors: [
64
64
  "StarFreedomX <starfreedomx@outlook.com>"
65
65
  ],
66
- version: "0.27.1",
66
+ version: "0.27.3",
67
67
  main: "lib/index.js",
68
68
  typings: "lib/index.d.ts",
69
69
  files: [
@@ -599,35 +599,51 @@ function saveImage(arrayBuffer, directory, filename) {
599
599
  }
600
600
  __name(saveImage, "saveImage");
601
601
  async function getImageSrc(session, param, option) {
602
- const number = option?.number ?? true, img = option?.img ?? true, at = option?.at ?? true, noParam = option?.noParam ?? true, quote = option?.quote ?? true;
603
- if (number && param?.length && /^\d+$/.test(param)) {
604
- return `https://q1.qlogo.cn/g?b=qq&nk=${param}&s=640`;
605
- } else if (noParam && !param?.length) {
606
- return `https://q1.qlogo.cn/g?b=qq&nk=${session.userId}&s=640`;
607
- }
608
- if (quote) {
609
- const quoteElementArray = session?.quote?.elements;
610
- if (quoteElementArray?.length) {
611
- for (const element of quoteElementArray) {
612
- if (img && element?.type === "img") {
613
- return element?.attrs?.src;
614
- } else if (at && element?.type === "at" && element?.attrs?.id && element.attrs.id !== session.selfId) {
615
- return `https://q1.qlogo.cn/g?b=qq&nk=${element?.attrs?.id}&s=640`;
616
- }
617
- }
602
+ const { number = true, img = true, at = true, noParam = true, quote = true } = option ?? {};
603
+ if (number && /^\d+$/.test(param)) {
604
+ const avatar = await getHeadUrlById(session, param);
605
+ if (avatar) return avatar;
606
+ }
607
+ if (noParam && !param?.length) {
608
+ const avatar = await getHeadUrlById(session, session.userId);
609
+ if (avatar) return avatar;
610
+ }
611
+ const findSrcInElements = /* @__PURE__ */ __name(async (elements, skipSelfAt = false) => {
612
+ if (!elements?.length) return null;
613
+ let list = elements;
614
+ if (skipSelfAt) {
615
+ const startIdx = list.findIndex((el) => !(el?.type === "at" && el?.attrs?.id === session.selfId));
616
+ list = startIdx === -1 ? [] : list.slice(startIdx);
618
617
  }
619
- }
620
- const elementArray = session.elements;
621
- for (const element of elementArray) {
622
- if (img && element?.type === "img") {
623
- return element?.attrs?.src;
624
- } else if (at && element?.type === "at" && element?.attrs?.id) {
625
- return `https://q1.qlogo.cn/g?b=qq&nk=${element.attrs.id}&s=640`;
618
+ for (const el of list) {
619
+ if (img && el?.type === "img" && el?.attrs?.src) {
620
+ return el.attrs.src;
621
+ }
622
+ if (at && el?.type === "at" && el?.attrs?.id && el.attrs.id !== session.selfId) {
623
+ const avatar = await getHeadUrlById(session, el.attrs.id);
624
+ if (avatar) return avatar;
625
+ }
626
626
  }
627
+ return null;
628
+ }, "findSrcInElements");
629
+ if (quote) {
630
+ const avatar = await findSrcInElements(session?.quote?.elements);
631
+ if (avatar) return avatar;
627
632
  }
628
- return "";
633
+ return await findSrcInElements(session?.elements, true) ?? "";
629
634
  }
630
635
  __name(getImageSrc, "getImageSrc");
636
+ async function getHeadUrlById(session, id) {
637
+ switch (session.platform) {
638
+ case "onebot":
639
+ return `https://q1.qlogo.cn/g?b=qq&nk=${id}&s=640`;
640
+ case "qq":
641
+ return `https://thirdqq.qlogo.cn/qqapp/${session.selfId}/${id}/640`;
642
+ default:
643
+ return (await session.bot.getUser(id)).avatar || "";
644
+ }
645
+ }
646
+ __name(getHeadUrlById, "getHeadUrlById");
631
647
  async function getImageFromUrl(ctx, url) {
632
648
  if (!url) throw new Error("URL must be provided");
633
649
  const sharp = getSharpConstructor(ctx);
@@ -1432,7 +1448,7 @@ function apply(ctx, cfg) {
1432
1448
  });
1433
1449
  }
1434
1450
  if (cfg.bangdreamBorder) {
1435
- 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) => {
1451
+ ctx.command("bdbd [param:text]").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) => {
1436
1452
  if (ctx.QhzySharp && detectControl(featureControl, session.guildId, "bdbd")) {
1437
1453
  const drawConfig = await handleBanGDreamConfig(options);
1438
1454
  const imgSrc = await getImageSrc(session, param);
@@ -1739,7 +1755,6 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
1739
1755
  const targetLength = channel.pickupLength;
1740
1756
  const content = session.content?.trim();
1741
1757
  if (targetLength > 0 && new RegExp(`^\\d{${targetLength}}$`).test(content)) {
1742
- if (!await canBotManage(session)) return session.text("middleware.messages.notManager");
1743
1758
  const setGroupName = /* @__PURE__ */ __name(async (name2) => {
1744
1759
  const internal = session.bot.internal;
1745
1760
  if (typeof internal?._request === "function" && session.platform === "onebot") {
@@ -1760,19 +1775,61 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
1760
1775
  }
1761
1776
  throw new Error(session.text("middleware.messages.editFuncNotFound"));
1762
1777
  }, "setGroupName");
1778
+ const getCurrentGroupName = /* @__PURE__ */ __name(async () => {
1779
+ const channel2 = await session.bot.getChannel(session.channelId);
1780
+ return channel2?.name;
1781
+ }, "getCurrentGroupName");
1763
1782
  try {
1764
- await setGroupName(content);
1765
- await session.send(session.text("middleware.messages.editGroupNameSuccess", { content }));
1783
+ const replaceNumberInName = /* @__PURE__ */ __name((name2, digits) => {
1784
+ if (!name2 || !name2.length) return digits;
1785
+ const targetLen = digits.replace(/\s+/g, "").length;
1786
+ const n = name2.length;
1787
+ for (let i = 0; i < n; i++) {
1788
+ for (let j = i + 1; j <= n; j++) {
1789
+ const sub = name2.slice(i, j);
1790
+ const compact = sub.replace(/\s+/g, "");
1791
+ if (compact.length === targetLen && /^\d+$/.test(compact)) {
1792
+ return name2.slice(0, i) + digits + name2.slice(j);
1793
+ }
1794
+ }
1795
+ }
1796
+ return digits + " " + name2;
1797
+ }, "replaceNumberInName");
1798
+ const currentName = await getCurrentGroupName();
1799
+ const contentDigits = String(content).replace(/\s+/g, "");
1800
+ let newName;
1801
+ if (currentName) {
1802
+ newName = replaceNumberInName(currentName, contentDigits);
1803
+ } else {
1804
+ newName = contentDigits;
1805
+ }
1806
+ await setGroupName(newName);
1807
+ await session.send(session.text("middleware.messages.editGroupNameSuccess", { content: newName }));
1766
1808
  return;
1767
1809
  } catch (e) {
1768
1810
  starfxLogger.warn(`纯数字修改失败,尝试添加空格重试: ${content}`);
1769
1811
  try {
1770
1812
  const spacedContent = content.replace(/(\d{3})(?=\d)/g, "$1 ");
1771
- await setGroupName(spacedContent);
1772
- await session.send(session.text("middleware.messages.editGroupNameRetrySuccess", { content, spacedContent }));
1813
+ const currentName = await getCurrentGroupName();
1814
+ const finalName = currentName ? (() => {
1815
+ const targetLen = spacedContent.replace(/\s+/g, "").length;
1816
+ const n = currentName.length;
1817
+ for (let i = 0; i < n; i++) {
1818
+ for (let j = i + 1; j <= n; j++) {
1819
+ const sub = currentName.slice(i, j);
1820
+ const compact = sub.replace(/\s+/g, "");
1821
+ if (compact.length === targetLen && /^\d+$/.test(compact)) {
1822
+ return currentName.slice(0, i) + spacedContent + currentName.slice(j);
1823
+ }
1824
+ }
1825
+ }
1826
+ return spacedContent + " " + currentName;
1827
+ })() : spacedContent;
1828
+ await setGroupName(finalName);
1829
+ await session.send(session.text("middleware.messages.editGroupNameRetrySuccess", { content, spacedContent: finalName }));
1773
1830
  return;
1774
1831
  } catch (retryError) {
1775
- starfxLogger.error(`尝试添加空格修改群名依然失败: ${retryError}`);
1832
+ starfxLogger.error(`尝试添加空格修改群名仍失败: ${retryError}`);
1776
1833
  }
1777
1834
  }
1778
1835
  }
@@ -1799,7 +1856,6 @@ ${!!await canBotManage(session) ? session.text(".managerEnabled") : session.text
1799
1856
  });
1800
1857
  if (process.env.NODE_ENV === "development") {
1801
1858
  ctx.command("test [params]").action(async ({ session }) => {
1802
- await session.send("test");
1803
1859
  });
1804
1860
  ctx.middleware(async (session, next) => {
1805
1861
  await session.send("");
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.27.1",
7
+ "version": "0.27.3",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -132,3 +132,5 @@ StarFreedomX机器人的小功能,自用
132
132
  | `0.26.8` | 修复sharp库传回参数改为对象的错误 |
133
133
  | `0.27.0` | 新增监听车牌修改群名功能 |
134
134
  | `0.27.1` | 车牌监听权限设置 |
135
+ | `0.27.2` | 车牌检测可以保留其他文字 |
136
+ | `0.27.3` | 修复at机器人bdbd时无法识别参数的bug |