koishi-plugin-starfx-bot 0.27.2 → 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 +43 -27
  2. package/package.json +1 -1
  3. package/readme.md +1 -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.2",
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);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.27.2",
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
@@ -133,3 +133,4 @@ StarFreedomX机器人的小功能,自用
133
133
  | `0.27.0` | 新增监听车牌修改群名功能 |
134
134
  | `0.27.1` | 车牌监听权限设置 |
135
135
  | `0.27.2` | 车牌检测可以保留其他文字 |
136
+ | `0.27.3` | 修复at机器人bdbd时无法识别参数的bug |