@alemonjs/qq-bot 2.1.40 → 2.1.41
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.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/markdown.d.ts +25 -0
- package/lib/markdown.js +47 -0
- package/package.json +10 -4
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { QQBotAPI } from "./sdk/api.js";
|
|
|
6
6
|
import { useClient, useMode, useValue } from "./hook.js";
|
|
7
7
|
import { QQBotGroupEventMap } from "./sdk/message.group.js";
|
|
8
8
|
import { QQBotPublicEventMap } from "./sdk/message.public.js";
|
|
9
|
+
import { QQMarkdown, QQMarkdownMathOptions, QQMarkdownTask } from "./markdown.js";
|
|
9
10
|
//#region src/index.d.ts
|
|
10
11
|
declare const _default: () => any;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { QQBotAPI as API, type ApiRequestData, type ButtonType, type FileType, type GlobalMuteRule, type GroupAction, type JoinApprovalStrategy, type JoinRequest, type KeyboardType, type MarkdownType, type MemberMuteState, type MessageType, type Options, type QQBotArkData, type QQBotAttachment, type QQBotBlacklistUser, type QQBotGroupEventMap, type QQBotGroupMember, type QQBotInteractionResolved, type QQBotMenu, type QQBotMenuItem, type QQBotMessageContent, type QQBotMessageElement, type QQBotMessageResult, type QQBotMessageUser, type QQBotPage, type QQBotPanel, type QQBotPanelCreate, type QQBotPanelRecord, type QQBotPanelScope, type QQBotPublicEventMap, type QQTextSanitizerOptions, type SetMemberMuteState, type StreamMessageData, type StreamMessageResult, type UploadConfig, type UploadPart, type UploadPartFinishData, type UploadPrepareData, type UploadPrepareResult, type VerifyInfo, _default as default, platform, sanitizeQQText, useClient, useMode, useValue };
|
|
13
|
+
export { QQBotAPI as API, type ApiRequestData, type ButtonType, type FileType, type GlobalMuteRule, type GroupAction, type JoinApprovalStrategy, type JoinRequest, type KeyboardType, type MarkdownType, type MemberMuteState, type MessageType, type Options, type QQBotArkData, type QQBotAttachment, type QQBotBlacklistUser, type QQBotGroupEventMap, type QQBotGroupMember, type QQBotInteractionResolved, type QQBotMenu, type QQBotMenuItem, type QQBotMessageContent, type QQBotMessageElement, type QQBotMessageResult, type QQBotMessageUser, type QQBotPage, type QQBotPanel, type QQBotPanelCreate, type QQBotPanelRecord, type QQBotPanelScope, type QQBotPublicEventMap, QQMarkdown, type QQMarkdownMathOptions, type QQMarkdownTask, type QQTextSanitizerOptions, type SetMemberMuteState, type StreamMessageData, type StreamMessageResult, type UploadConfig, type UploadPart, type UploadPartFinishData, type UploadPrepareData, type UploadPrepareResult, type VerifyInfo, _default as default, platform, sanitizeQQText, useClient, useMode, useValue };
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { QQBotAPI } from "./sdk/api.js";
|
|
|
4
4
|
import { start } from "./index.websoket.js";
|
|
5
5
|
import { useClient, useMode, useValue } from "./hook.js";
|
|
6
6
|
import { start as start$1 } from "./index.webhook.js";
|
|
7
|
+
import { QQMarkdown } from "./markdown.js";
|
|
7
8
|
import { definePlatform } from "alemonjs";
|
|
8
9
|
|
|
9
10
|
//#region src/index.ts
|
|
@@ -15,4 +16,4 @@ const main = () => {
|
|
|
15
16
|
var src_default = definePlatform({ main });
|
|
16
17
|
|
|
17
18
|
//#endregion
|
|
18
|
-
export { QQBotAPI as API, src_default as default, platform, sanitizeQQText, useClient, useMode, useValue };
|
|
19
|
+
export { QQBotAPI as API, QQMarkdown, src_default as default, platform, sanitizeQQText, useClient, useMode, useValue };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/markdown.d.ts
|
|
2
|
+
/** QQ Markdown 专用扩展。仅生成字符串,不扩展 alemonjs 的通用节点或渲染协议。 */
|
|
3
|
+
type QQMarkdownMathOptions = {
|
|
4
|
+
block?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type QQMarkdownTask = {
|
|
7
|
+
text: string;
|
|
8
|
+
checked?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const math: (latex: string, options?: QQMarkdownMathOptions) => string;
|
|
11
|
+
/**
|
|
12
|
+
* 仅用于支持这些扩展的 QQ Markdown 消息;通过 addContent() 或原始 Markdown 发送。
|
|
13
|
+
* 不提供跨平台渲染或自动降级,调用方应根据发送平台选择内容。
|
|
14
|
+
*/
|
|
15
|
+
declare const QQMarkdown: {
|
|
16
|
+
math: typeof math;
|
|
17
|
+
taskList(...items: QQMarkdownTask[]): string;
|
|
18
|
+
underline(text: string): string;
|
|
19
|
+
color(text: string, color: string): string;
|
|
20
|
+
ruby(text: string, annotation: string): string;
|
|
21
|
+
boxed(text: string): string;
|
|
22
|
+
cancel(text: string): string;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { QQMarkdown, QQMarkdownMathOptions, QQMarkdownTask };
|
package/lib/markdown.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/markdown.ts
|
|
2
|
+
const latexText = (text) => {
|
|
3
|
+
const escapes = {
|
|
4
|
+
"\\": "\\textbackslash{}",
|
|
5
|
+
"{": "\\{",
|
|
6
|
+
"}": "\\}",
|
|
7
|
+
$: "\\$",
|
|
8
|
+
"&": "\\&",
|
|
9
|
+
"#": "\\#",
|
|
10
|
+
"%": "\\%",
|
|
11
|
+
_: "\\_",
|
|
12
|
+
"^": "\\textasciicircum{}",
|
|
13
|
+
"~": "\\textasciitilde{}"
|
|
14
|
+
};
|
|
15
|
+
return `\\text{${text.replace(/[\\{}$&#%_^~]/g, (character) => escapes[character]).replace(/\r\n?|\n/g, " ")}}`;
|
|
16
|
+
};
|
|
17
|
+
const math = (latex, options) => options?.block ? `\n\n$$\n${latex}\n$$\n\n` : `$${latex}$`;
|
|
18
|
+
/**
|
|
19
|
+
* 仅用于支持这些扩展的 QQ Markdown 消息;通过 addContent() 或原始 Markdown 发送。
|
|
20
|
+
* 不提供跨平台渲染或自动降级,调用方应根据发送平台选择内容。
|
|
21
|
+
*/
|
|
22
|
+
const QQMarkdown = {
|
|
23
|
+
math,
|
|
24
|
+
taskList(...items) {
|
|
25
|
+
if (items.length === 0) return "";
|
|
26
|
+
return "\n\n" + items.map((item) => `- [${item.checked ? "x" : " "}] ${item.text.replace(/\r\n?|\n/g, " ")}`).join("\n") + "\n\n";
|
|
27
|
+
},
|
|
28
|
+
underline(text) {
|
|
29
|
+
return math(`\\underline{${latexText(text)}}`);
|
|
30
|
+
},
|
|
31
|
+
color(text, color) {
|
|
32
|
+
if (!/^(?:[a-zA-Z]+|#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?)$/.test(color)) throw new TypeError("QQ Markdown color must be a color name or #RGB / #RRGGBB");
|
|
33
|
+
return math(`\\color{${color}}{${latexText(text)}}`);
|
|
34
|
+
},
|
|
35
|
+
ruby(text, annotation) {
|
|
36
|
+
return math(`\\overset{${latexText(annotation)}}{${latexText(text)}}`);
|
|
37
|
+
},
|
|
38
|
+
boxed(text) {
|
|
39
|
+
return math(`\\boxed{${latexText(text)}}`);
|
|
40
|
+
},
|
|
41
|
+
cancel(text) {
|
|
42
|
+
return math(`\\cancel{${latexText(text)}}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { QQMarkdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/qq-bot",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.41",
|
|
4
4
|
"description": "QQ官方平台",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
"test:send": "yarn build && node tests/use-send.notice.mjs",
|
|
13
13
|
"test:channel": "yarn --cwd ../alemonjs build && yarn build && node tests/channel.contract.mjs",
|
|
14
14
|
"test:qr": "yarn build && node tests/qr-auth.mjs",
|
|
15
|
-
"test:non-channel": "yarn build && node tests/markdown-buttons.contract.mjs && node tests/non-channel.contract.mjs && node tests/framework.contract.mjs && node tests/non-channel.transport.mjs && node tests/media-upload.contract.mjs && node tests/routing.contract.mjs && node tests/lifecycle.contract.mjs && node tests/http-diagnostics.contract.mjs && node tests/webhook-ingress.contract.mjs && node tests/text-sanitizer.contract.mjs && tsc -p tests/tsconfig.non-channel.json",
|
|
15
|
+
"test:non-channel": "yarn build && node tests/markdown-buttons.contract.mjs && node tests/markdown-extension.contract.mjs && node tests/non-channel.contract.mjs && node tests/framework.contract.mjs && node tests/non-channel.transport.mjs && node tests/media-upload.contract.mjs && node tests/routing.contract.mjs && node tests/lifecycle.contract.mjs && node tests/http-diagnostics.contract.mjs && node tests/webhook-ingress.contract.mjs && node tests/text-sanitizer.contract.mjs && tsc -p tests/tsconfig.non-channel.json",
|
|
16
16
|
"docs:snapshot": "python3 scripts/snapshot-official.py",
|
|
17
17
|
"test:http": "yarn build && node tests/http-diagnostics.contract.mjs && node tests/webhook-ingress.contract.mjs",
|
|
18
18
|
"test:text": "yarn build && node tests/text-sanitizer.contract.mjs",
|
|
19
19
|
"test:materials": "yarn build && node tests/materials.contract.mjs",
|
|
20
20
|
"test:mention": "yarn build && node tests/everyone.contract.mjs",
|
|
21
|
-
"test:buttons": "yarn build && node tests/markdown-buttons.contract.mjs"
|
|
21
|
+
"test:buttons": "yarn build && node tests/markdown-buttons.contract.mjs",
|
|
22
|
+
"test:markdown-extension": "yarn build && node tests/markdown-extension.contract.mjs && node ../../node_modules/typescript/bin/tsc --noEmit --strict --skipLibCheck --module ESNext --moduleResolution Bundler --target ES2022 tests/markdown-extension.types.ts"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@noble/curves": "^1.7.0",
|
|
@@ -45,7 +46,12 @@
|
|
|
45
46
|
"require": "./lib/index.js"
|
|
46
47
|
},
|
|
47
48
|
"./package": "./package.json",
|
|
48
|
-
"./desktop": "./lib/desktop.js"
|
|
49
|
+
"./desktop": "./lib/desktop.js",
|
|
50
|
+
"./markdown": {
|
|
51
|
+
"types": "./lib/markdown.d.ts",
|
|
52
|
+
"import": "./lib/markdown.js",
|
|
53
|
+
"require": "./lib/markdown.js"
|
|
54
|
+
}
|
|
49
55
|
},
|
|
50
56
|
"alemonjs": {
|
|
51
57
|
"config": [
|