@alemonjs/qq-bot 2.1.35 → 2.1.37

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -1981
  3. package/lib/config.d.ts +2 -0
  4. package/lib/format.d.ts +4 -1
  5. package/lib/format.js +68 -4
  6. package/lib/framework-actions.d.ts +75 -0
  7. package/lib/framework-actions.js +620 -0
  8. package/lib/framework-events.d.ts +10 -0
  9. package/lib/framework-events.js +182 -0
  10. package/lib/hook.d.ts +16 -12
  11. package/lib/hook.js +5 -9
  12. package/lib/index.d.ts +5 -1
  13. package/lib/index.websoket.js +6 -2
  14. package/lib/message/AUDIO_EVENT.d.ts +20 -0
  15. package/lib/message/AUDIO_EVENT.js +1 -0
  16. package/lib/message/FORUM_EVENT.d.ts +33 -0
  17. package/lib/message/FORUM_EVENT.js +1 -0
  18. package/lib/message/GUILD_AUDIT.d.ts +14 -0
  19. package/lib/message/GUILD_AUDIT.js +1 -0
  20. package/lib/message/INTERACTION_CREATE.d.ts +13 -20
  21. package/lib/message/MESSAGE_CREATE.d.ts +3 -9
  22. package/lib/message/MESSAGE_DELETE.d.ts +15 -1
  23. package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +3 -13
  24. package/lib/message/group/C2C_MSG_RECEIVE.d.ts +1 -1
  25. package/lib/message/group/C2C_MSG_REJECT.d.ts +1 -1
  26. package/lib/message/group/FRIEND_ADD.d.ts +7 -1
  27. package/lib/message/group/FRIEND_DEL.d.ts +4 -1
  28. package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +6 -27
  29. package/lib/message/group/GROUP_MEMBER_ADD.d.ts +4 -2
  30. package/lib/message/group/GROUP_MEMBER_REMOVE.d.ts +4 -2
  31. package/lib/message/group/GROUP_MESSAGE_CREATE.d.ts +6 -27
  32. package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +1 -1
  33. package/lib/message/group/GROUP_MSG_REJECT.d.ts +1 -1
  34. package/lib/message/group/MESSAGE_AUDIT_PASS.d.ts +2 -0
  35. package/lib/message/group/MESSAGE_AUDIT_REJECT.d.ts +2 -0
  36. package/lib/message/group/SUBSCRIBE_MESSAGE_STATUS.d.ts +17 -0
  37. package/lib/message/group/SUBSCRIBE_MESSAGE_STATUS.js +1 -0
  38. package/lib/register.d.ts +1 -0
  39. package/lib/register.js +279 -115
  40. package/lib/sdk/api.d.ts +93 -14
  41. package/lib/sdk/api.js +241 -45
  42. package/lib/sdk/client.webhook.js +2 -1
  43. package/lib/sdk/client.websoket.js +2 -1
  44. package/lib/sdk/intents.d.ts +1 -0
  45. package/lib/sdk/intents.js +1 -0
  46. package/lib/sdk/message.d.ts +1 -1
  47. package/lib/sdk/message.group.d.ts +4 -2
  48. package/lib/sdk/message.guild.d.ts +19 -0
  49. package/lib/sdk/non-channel-types.d.ts +138 -0
  50. package/lib/sdk/non-channel-types.js +1 -0
  51. package/lib/sdk/registry.js +2 -2
  52. package/lib/sdk/typing.d.ts +13 -1
  53. package/lib/sends.d.ts +3 -3
  54. package/lib/sends.js +57 -71
  55. package/lib/upload.js +13 -37
  56. package/package.json +8 -5
package/lib/config.d.ts CHANGED
@@ -3,6 +3,8 @@ import { Options as Options$1 } from "./sdk/typing.js";
3
3
  declare const platform = "qq-bot";
4
4
  declare const platformFullName = "@alemonjs/qq-bot";
5
5
  type Options = {
6
+ /** 按钮/快捷菜单自动 ACK。设为 false 后由应用 useInteraction().ack() 回应。 */
7
+ autoInteractionAck?: boolean;
6
8
  /**
7
9
  * 主人-用户KEY
8
10
  */
package/lib/format.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { DataEnums, DataMarkDown } from "alemonjs";
2
2
  //#region src/format.d.ts
3
+ /** 群聊、私聊和频道共用有序正文;提及等原生文本由发送上下文提供。 */
4
+ declare const formatQQContent: (items: DataEnums[], renderNative: (item: DataEnums) => string, plain?: boolean, hideUnsupported?: boolean | number) => string;
3
5
  /**
4
6
  * 将结构化 Markdown 子元素数组转为可读纯文本
5
7
  */
@@ -22,5 +24,6 @@ declare const markdownRawToText: (raw: string, hideUnsupported?: boolean | numbe
22
24
  * 其余类型降级为文本
23
25
  */
24
26
  declare const dataEnumToText: (item: DataEnums, hideUnsupported?: boolean | number) => string;
27
+ declare const createMarkdownText: (data: DataMarkDown['value']) => string;
25
28
  //#endregion
26
- export { buttonsToText, dataEnumToText, markdownRawToText, markdownToText };
29
+ export { buttonsToText, createMarkdownText, dataEnumToText, formatQQContent, markdownRawToText, markdownToText };
package/lib/format.js CHANGED
@@ -1,10 +1,32 @@
1
+ import { joinMarkdownParts, renderMarkdownBlockquote } from "alemonjs/markdown";
2
+
1
3
  //#region src/format.ts
4
+ /** 群聊、私聊和频道共用有序正文;提及等原生文本由发送上下文提供。 */
5
+ const formatQQContent = (items, renderNative, plain = false, hideUnsupported) => {
6
+ return items.map((item) => {
7
+ if (item.type === "Markdown") return plain ? markdownToText(item.value, hideUnsupported) : createMarkdownText(item.value);
8
+ if (item.type === "MarkdownOriginal") {
9
+ const text = plain ? markdownRawToText(item.value, hideUnsupported) : item.value;
10
+ return text ? `\n\n${text}\n\n` : "";
11
+ }
12
+ if (item.type === "BT.group") {
13
+ if (!plain || Number(hideUnsupported) >= 4) return "";
14
+ const text = item.value.map((row) => row.value.map((button) => {
15
+ if (Number(hideUnsupported) >= 3) return "";
16
+ if (Number(hideUnsupported) >= 2) return button.options?.data || button.value;
17
+ return hideUnsupported ? button.value : `[${button.value}]`;
18
+ }).filter(Boolean).join(" ")).filter(Boolean).join("\n");
19
+ return text ? `\n\n${text}\n\n` : "";
20
+ }
21
+ return renderNative(item);
22
+ }).join("");
23
+ };
2
24
  /**
3
25
  * 将结构化 Markdown 子元素数组转为可读纯文本
4
26
  */
5
27
  const markdownToText = (items, hideUnsupported) => {
6
28
  if (Number(hideUnsupported) >= 4) return "";
7
- return items.map((item) => {
29
+ return joinMarkdownParts(items, items.map((item) => {
8
30
  switch (item.type) {
9
31
  case "MD.text": return item.value;
10
32
  case "MD.title": return hideUnsupported ? `${item.value}\n` : `【${item.value}】\n`;
@@ -16,6 +38,7 @@ const markdownToText = (items, hideUnsupported) => {
16
38
  case "MD.link": {
17
39
  const v = item.value;
18
40
  if (Number(hideUnsupported) >= 3) return "";
41
+ if (!v.url) return v.text;
19
42
  return Number(hideUnsupported) >= 2 ? v.url : `${v.text}( ${v.url} )`;
20
43
  }
21
44
  case "MD.image": return hideUnsupported ? "" : "[图片]";
@@ -23,7 +46,7 @@ const markdownToText = (items, hideUnsupported) => {
23
46
  if (typeof li.value === "object") return `${li.value.index}. ${li.value.text ?? ""}`;
24
47
  return `· ${li.value}`;
25
48
  }).join("\n") + "\n";
26
- case "MD.blockquote": return `> ${item.value}\n`;
49
+ case "MD.blockquote": return renderMarkdownBlockquote(item.value, (children) => markdownToText(children, hideUnsupported));
27
50
  case "MD.divider": return hideUnsupported ? "" : "————————\n";
28
51
  case "MD.newline": return "\n";
29
52
  case "MD.code": return item.value;
@@ -37,7 +60,7 @@ const markdownToText = (items, hideUnsupported) => {
37
60
  return hideUnsupported ? String(item.value) : `[${item.value}]`;
38
61
  default: return String(item?.value ?? "");
39
62
  }
40
- }).join("");
63
+ }));
41
64
  };
42
65
  /**
43
66
  * 将按钮组转为可读纯文本
@@ -88,6 +111,47 @@ const dataEnumToText = (item, hideUnsupported) => {
88
111
  default: return "";
89
112
  }
90
113
  };
114
+ const mdFormatters = {
115
+ "MD.title": (value) => `# ${value} `,
116
+ "MD.subtitle": (value) => `## ${value} `,
117
+ "MD.text": (value) => `${value} `,
118
+ "MD.bold": (value) => `**${value}** `,
119
+ "MD.divider": () => "\n***\n",
120
+ "MD.italic": (value) => `__${value}__ `,
121
+ "MD.italicStar": (value) => `*${value}* `,
122
+ "MD.strikethrough": (value) => `~~${value}~~ `,
123
+ "MD.blockquote": (value) => renderMarkdownBlockquote(value, createMarkdownText),
124
+ "MD.newline": () => "\n",
125
+ "MD.link": (value) => {
126
+ if (!value?.text && !value?.url) return "";
127
+ if (!value?.text || !value?.url) return `<${value?.url ?? value?.text}> `;
128
+ return `[🔗${value?.text}](${value?.url}) `;
129
+ },
130
+ "MD.image": (value, options) => `\n![text #${options?.width || 208}px #${options?.height || 320}px](${value})\n`,
131
+ "MD.mention": (value, options) => {
132
+ const { belong } = options || {};
133
+ if (belong === "channel") return "";
134
+ if (value === "everyone") return "<qqbot-at-everyone />";
135
+ if (belong === "user") return `<qqbot-at-user id="${value}" />`;
136
+ return `<qqbot-at-user id="${value}" />`;
137
+ },
138
+ "MD.content": (value) => `${value}`,
139
+ "MD.button": (title, options) => {
140
+ const { data, autoEnter } = options || {};
141
+ if (autoEnter) return `<qqbot-cmd-enter text="${data}" show="${title}" />`;
142
+ return `<qqbot-cmd-input text="${data}" show="${title}" />`;
143
+ }
144
+ };
145
+ const createMarkdownText = (data) => {
146
+ return joinMarkdownParts(data, data.map((mdItem) => {
147
+ if (mdFormatters[mdItem.type]) return mdFormatters[mdItem.type](mdItem?.value, mdItem?.options);
148
+ if (mdItem.type === "MD.list" && typeof mdItem.value !== "string") return `${mdItem.value.map((listItem) => {
149
+ return typeof listItem.value === "object" ? `\n${listItem.value.index}. ${listItem.value.text}` : `\n- ${listItem.value}`;
150
+ }).join("")}\n`;
151
+ if (mdItem.type === "MD.code") return `\n\`\`\`${mdItem?.options?.language || ""}\n${mdItem.value}\n\`\`\`\n`;
152
+ return String(mdItem["value"] || "");
153
+ }));
154
+ };
91
155
 
92
156
  //#endregion
93
- export { buttonsToText, dataEnumToText, markdownRawToText, markdownToText };
157
+ export { buttonsToText, createMarkdownText, dataEnumToText, formatQQContent, markdownRawToText, markdownToText };
@@ -0,0 +1,75 @@
1
+ import { QQBotAPI } from "./sdk/api.js";
2
+ import { OutgoingMessage } from "alemonjs";
3
+ //#region src/framework-actions.d.ts
4
+ declare const toQQMessage: (content: OutgoingMessage) => {
5
+ msg_type: 0 | 2 | 3 | 7;
6
+ content: string;
7
+ markdown: {
8
+ content: string;
9
+ custom_template_id: string;
10
+ template_id: number;
11
+ params: {
12
+ key: string;
13
+ values: string[];
14
+ }[];
15
+ force_verify_image_resource: boolean;
16
+ };
17
+ media: {
18
+ file_info: string;
19
+ };
20
+ ark: {
21
+ template_id: number;
22
+ kv: {
23
+ key: string;
24
+ value: string;
25
+ obj: {
26
+ obj_kv: {
27
+ key: string;
28
+ value: string;
29
+ }[];
30
+ }[];
31
+ }[];
32
+ };
33
+ keyboard: {
34
+ id: string;
35
+ content: {
36
+ rows: {
37
+ buttons: {
38
+ id: string;
39
+ group_id: string;
40
+ render_data: {
41
+ label: string;
42
+ visited_label: string;
43
+ style: number;
44
+ };
45
+ action: {
46
+ type: number;
47
+ data: string;
48
+ permission: {
49
+ type: number;
50
+ specify_user_ids: string[];
51
+ specify_role_ids: string[];
52
+ };
53
+ enter: boolean;
54
+ reply: boolean;
55
+ unsupport_tips: string;
56
+ anchor: number;
57
+ click_limit: number;
58
+ modal: {
59
+ content: string;
60
+ confirm_text: string;
61
+ cancel_text: string;
62
+ };
63
+ };
64
+ }[];
65
+ }[];
66
+ };
67
+ };
68
+ };
69
+ /** Translate semantic framework actions. Undefined means a legacy/channel action. */
70
+ declare const handleFrameworkAction: (client: QQBotAPI, data: {
71
+ action: string;
72
+ payload: any;
73
+ }, botId: string) => Promise<import("alemonjs/common").Result<any>[]>;
74
+ //#endregion
75
+ export { handleFrameworkAction, toQQMessage };