@karinjs/adapter-qqbot 1.2.10 → 1.3.1

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 (61) hide show
  1. package/README.md +869 -84
  2. package/dist/chunk-PYOUSZ6B.js +1501 -0
  3. package/dist/index.d.ts +499 -0
  4. package/dist/index.js +100 -0
  5. package/dist/web.config.d.ts +25 -0
  6. package/dist/web.config.js +224 -0
  7. package/package.json +22 -15
  8. package/config/comment/config.json +0 -3
  9. package/config/config/config.yaml +0 -53
  10. package/lib/cli/pr.d.ts +0 -2
  11. package/lib/cli/pr.js +0 -73
  12. package/lib/core/adapter/adapter.d.ts +0 -91
  13. package/lib/core/adapter/adapter.js +0 -144
  14. package/lib/core/adapter/handler.d.ts +0 -49
  15. package/lib/core/adapter/handler.js +0 -140
  16. package/lib/core/adapter/markdown.d.ts +0 -38
  17. package/lib/core/adapter/markdown.js +0 -220
  18. package/lib/core/adapter/normal.d.ts +0 -30
  19. package/lib/core/adapter/normal.js +0 -263
  20. package/lib/core/api/index.d.ts +0 -167
  21. package/lib/core/api/index.js +0 -180
  22. package/lib/core/api/sign.d.ts +0 -22
  23. package/lib/core/api/sign.js +0 -40
  24. package/lib/core/api/types.d.ts +0 -236
  25. package/lib/core/api/types.js +0 -1
  26. package/lib/core/event/conver.d.ts +0 -10
  27. package/lib/core/event/conver.js +0 -57
  28. package/lib/core/event/index.d.ts +0 -9
  29. package/lib/core/event/index.js +0 -98
  30. package/lib/core/event/message.d.ts +0 -27
  31. package/lib/core/event/message.js +0 -95
  32. package/lib/core/event/notice.d.ts +0 -50
  33. package/lib/core/event/notice.js +0 -133
  34. package/lib/core/event/types.d.ts +0 -473
  35. package/lib/core/event/types.js +0 -1
  36. package/lib/core/internal/axios.d.ts +0 -25
  37. package/lib/core/internal/axios.js +0 -46
  38. package/lib/core/internal/sign.d.ts +0 -22
  39. package/lib/core/internal/sign.js +0 -40
  40. package/lib/core/webhook/c2c.d.ts +0 -2
  41. package/lib/core/webhook/c2c.js +0 -14
  42. package/lib/core/webhook/http.d.ts +0 -2
  43. package/lib/core/webhook/http.js +0 -35
  44. package/lib/core/webhook/index.d.ts +0 -17
  45. package/lib/core/webhook/index.js +0 -87
  46. package/lib/core/webhook/ws.d.ts +0 -2
  47. package/lib/core/webhook/ws.js +0 -79
  48. package/lib/index.d.ts +0 -1
  49. package/lib/index.js +0 -5
  50. package/lib/root.d.ts +0 -5
  51. package/lib/root.js +0 -9
  52. package/lib/types/config.d.ts +0 -53
  53. package/lib/types/config.js +0 -1
  54. package/lib/utils/common.d.ts +0 -80
  55. package/lib/utils/common.js +0 -198
  56. package/lib/utils/config.d.ts +0 -9
  57. package/lib/utils/config.js +0 -54
  58. package/lib/utils/dir.d.ts +0 -1
  59. package/lib/utils/dir.js +0 -1
  60. package/lib/utils/index.d.ts +0 -4
  61. package/lib/utils/index.js +0 -4
@@ -0,0 +1,224 @@
1
+ import {
2
+ config_exports,
3
+ pkg,
4
+ writeConfig
5
+ } from "./chunk-PYOUSZ6B.js";
6
+
7
+ // src/web.config.ts
8
+ import { defineConfig, components } from "node-karin";
9
+ var web_config_default = defineConfig({
10
+ info: {
11
+ id: pkg().name,
12
+ name: "QQBot\u9002\u914D\u5668",
13
+ version: pkg().version,
14
+ description: "\u4E3Akarin\u63D0\u4F9BQQ\u5B98\u65B9Bot\u8FDE\u63A5\u80FD\u529B",
15
+ author: [
16
+ {
17
+ name: "shijin",
18
+ avatar: "https://github.com/sj817.png"
19
+ }
20
+ ]
21
+ },
22
+ components: () => {
23
+ const data = [];
24
+ const cfg = config_exports.config();
25
+ cfg.forEach((item) => {
26
+ data.push({
27
+ title: item.appId,
28
+ subtitle: "",
29
+ appId: item.appId,
30
+ secret: item.secret,
31
+ prodApi: item.prodApi,
32
+ sandboxApi: item.sandboxApi,
33
+ tokenApi: item.tokenApi,
34
+ sandbox: item.sandbox,
35
+ qqEnable: item.qqEnable,
36
+ guildEnable: item.guildEnable,
37
+ guildMode: item.guildMode,
38
+ exclude: item.exclude,
39
+ regex: item.regex.map((item2) => `<${item2.reg}> <${item2.rep}>`)
40
+ });
41
+ });
42
+ return [
43
+ components.accordionPro.create(
44
+ "qqbot",
45
+ data,
46
+ {
47
+ label: "QQBot",
48
+ description: "QQBot\u914D\u7F6E",
49
+ children: {
50
+ key: "qqbotConfig",
51
+ children: [
52
+ components.input.create("appId", {
53
+ label: "AppID",
54
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684AppID",
55
+ isRequired: true
56
+ }),
57
+ components.input.create("secret", {
58
+ label: "Secret",
59
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684Secret",
60
+ isRequired: true
61
+ }),
62
+ components.input.create("prodApi", {
63
+ label: "\u6B63\u5F0F\u73AF\u5883Api",
64
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684\u6B63\u5F0F\u73AF\u5883Api",
65
+ defaultValue: "https://api.sgroup.qq.com",
66
+ isRequired: true
67
+ }),
68
+ components.input.create("sandboxApi", {
69
+ label: "\u6C99\u76D2\u73AF\u5883Api",
70
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684\u6C99\u76D2\u73AF\u5883Api",
71
+ defaultValue: "https://sandbox.api.sgroup.qq.com",
72
+ isRequired: true
73
+ }),
74
+ components.input.create("tokenApi", {
75
+ label: "\u8C03\u7528\u51ED\u8BC1\u7684Api",
76
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684\u8C03\u7528\u51ED\u8BC1\u7684Api",
77
+ defaultValue: "https://bots.qq.com/app/getAppAccessToken",
78
+ isRequired: true
79
+ }),
80
+ components.switch.create("sandbox", {
81
+ label: "\u6C99\u76D2\u73AF\u5883",
82
+ description: "\u662F\u5426\u542F\u7528\u6C99\u76D2\u73AF\u5883",
83
+ defaultSelected: false
84
+ }),
85
+ components.switch.create("qqEnable", {
86
+ label: "QQ\u573A\u666F",
87
+ description: "\u662F\u5426\u542F\u7528QQ\u573A\u666F",
88
+ defaultSelected: true
89
+ }),
90
+ components.switch.create("guildEnable", {
91
+ label: "\u9891\u9053\u573A\u666F",
92
+ description: "\u662F\u5426\u542F\u7528\u9891\u9053\u573A\u666F",
93
+ defaultSelected: true
94
+ }),
95
+ components.switch.create("guildMode", {
96
+ label: "\u9891\u9053\u573A\u666F\u6A21\u5F0F",
97
+ description: "\u9891\u9053\u573A\u666F\u6A21\u5F0F \u6253\u5F00\u4E3A\u516C\u57DF \u5173\u95ED\u4E3A\u79C1\u57DF",
98
+ defaultSelected: true
99
+ }),
100
+ components.input.group("exclude", {
101
+ data: [],
102
+ label: "\u6587\u672C\u4E2D\u7684url\u8F6C\u4E8C\u7EF4\u7801\u767D\u540D\u5355",
103
+ description: "\u6587\u672C\u4E2D\u7684url\u8F6C\u4E8C\u7EF4\u7801\u767D\u540D\u5355 \u914D\u7F6E\u540E\u5C06\u4E0D\u8F6C\u6362\u8FD9\u4E9Burl\u4E3A\u4E8C\u7EF4\u7801",
104
+ template: components.input.create("exclude_url", {
105
+ label: "\u767D\u540D\u5355"
106
+ })
107
+ }),
108
+ components.input.group("regex", {
109
+ data: [],
110
+ label: "\u63A5\u53D7\u5230\u6D88\u606F\u540E\u5BF9\u6587\u672C\u8FDB\u884C\u8868\u8FBE\u5F0F\u5904\u7406",
111
+ description: "\u683C\u5F0F\u6BD4\u8F83\u590D\u6742: <reg> <rep> \u5206\u522B\u8868\u793A\u6B63\u5219\u548C\u66FF\u6362\u5185\u5BB9\uFF0C\u8BF7\u6B63\u786E\u586B\u5199",
112
+ template: components.input.create("regex", {
113
+ label: "\u6B63\u5219"
114
+ })
115
+ }),
116
+ components.radio.group("markdown:mode", {
117
+ label: "markdown\u53D1\u9001\u6A21\u5F0F",
118
+ description: "\u673A\u5668\u4EBA\u53D1\u9001\u6A21\u5F0F 0-\u76F4\u63A5\u53D1\u9001 1-\u539F\u751FMarkdown 3-\u65E7\u56FE\u6587\u6A21\u677FMarkdown 4-\u7EAF\u6587\u6A21\u677FMarkdown 5-\u81EA\u5B9A\u4E49\u5904\u7406",
119
+ defaultValue: "0",
120
+ radio: [
121
+ components.radio.create("0", {
122
+ label: "\u76F4\u63A5\u53D1\u9001",
123
+ value: "0"
124
+ }),
125
+ components.radio.create("1", {
126
+ label: "\u539F\u751FMarkdown",
127
+ value: "1"
128
+ }),
129
+ components.radio.create("3", {
130
+ label: "\u65E7\u56FE\u6587\u6A21\u677FMarkdown",
131
+ value: "3"
132
+ }),
133
+ components.radio.create("4", {
134
+ label: "\u7EAF\u6587\u6A21\u677FMarkdown",
135
+ value: "4"
136
+ })
137
+ // components.radio.create('5', {
138
+ // label: '自定义处理',
139
+ // value: '5',
140
+ // }),
141
+ ]
142
+ }),
143
+ components.input.create("markdown:id", {
144
+ label: "markdown\u6A21\u677FID",
145
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684markdown\u6A21\u677FID"
146
+ }),
147
+ components.input.group("markdown:kv", {
148
+ data: [],
149
+ label: "markdown\u6A21\u677F\u53D8\u91CF",
150
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684markdown\u6A21\u677F\u53D8\u91CF",
151
+ template: components.input.create("markdown:kv:key", {
152
+ label: "\u53D8\u91CF"
153
+ })
154
+ }),
155
+ components.radio.group("event:type", {
156
+ label: "\u4E8B\u4EF6\u63A5\u6536\u65B9\u5F0F",
157
+ defaultValue: "0",
158
+ radio: [
159
+ components.radio.create("0", {
160
+ label: "\u5173\u95ED",
161
+ value: "0",
162
+ description: "\u5173\u95ED\u4E8B\u4EF6\u63A5\u6536 \u4E34\u65F6\u7981\u7528"
163
+ }),
164
+ components.radio.create("1", {
165
+ label: "webhook",
166
+ value: "1",
167
+ description: "\u4F7F\u7528webhook\u63A5\u6536\u4E8B\u4EF6 \u9700\u8981\u81EA\u884C\u914D\u7F6ENginx"
168
+ }),
169
+ components.radio.create("2", {
170
+ label: "ws",
171
+ value: "2",
172
+ description: "\u4F7F\u7528ws\u63A5\u6536\u4E8B\u4EF6 \u9700\u8981\u81EA\u884C\u914D\u7F6Ews"
173
+ })
174
+ ]
175
+ }),
176
+ components.input.create("event:wsUrl", {
177
+ label: "ws\u5730\u5740",
178
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684ws\u5730\u5740"
179
+ }),
180
+ components.input.create("event:wsToken", {
181
+ label: "wsToken",
182
+ description: "\u8BF7\u8F93\u5165\u4F60\u7684wsToken"
183
+ })
184
+ ]
185
+ }
186
+ }
187
+ )
188
+ ];
189
+ },
190
+ /** 前端点击保存之后调用的方法 */
191
+ save: (config) => {
192
+ const data = [];
193
+ config.qqbot.forEach((item) => {
194
+ data.push({
195
+ ...item,
196
+ regex: item.regex.map((item2) => {
197
+ const [reg, rep] = item2.split(" ");
198
+ return {
199
+ reg: reg.replace(/^<|>$|$/g, ""),
200
+ rep: rep.replace(/^<|>$|$/g, "")
201
+ };
202
+ }),
203
+ markdown: {
204
+ mode: item["markdown:mode"] ?? 0,
205
+ id: item["markdown:id"] ?? "",
206
+ kv: item["markdown:kv"] ?? []
207
+ },
208
+ event: {
209
+ type: item["event:type"] ?? 0,
210
+ wsUrl: item["event:wsUrl"] ?? "",
211
+ wsToken: item["event:wsToken"] ?? ""
212
+ }
213
+ });
214
+ });
215
+ writeConfig(data);
216
+ return {
217
+ success: true,
218
+ message: "\u4FDD\u5B58\u6210\u529F"
219
+ };
220
+ }
221
+ });
222
+ export {
223
+ web_config_default as default
224
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karinjs/adapter-qqbot",
3
- "version": "1.2.10",
3
+ "version": "1.3.1",
4
4
  "description": "karin plugin adapter for qqbot",
5
5
  "homepage": "https://github.com/KarinJS/karin-plugin-adapter-qqbot",
6
6
  "bugs": {
@@ -12,24 +12,17 @@
12
12
  },
13
13
  "author": "shijin",
14
14
  "type": "module",
15
- "main": "lib/index.js",
15
+ "main": "dist/index.js",
16
16
  "files": [
17
- "/lib/**/*.js",
18
- "/lib/**/*.d.ts",
19
- "config",
20
- "resources",
21
- "LICENSE",
22
- "package.json",
23
- "README.md"
17
+ "dist"
24
18
  ],
25
19
  "scripts": {
26
20
  "build": "tsc && tsup",
27
- "pr": "node lib/cli/pr.js",
21
+ "dev": "tsx src/app.ts",
22
+ "karin": "karin",
28
23
  "pub": "npm publish --access public",
29
24
  "pub-beta": "npm publish --tag beta",
30
- "sort": "npx sort-package-json",
31
- "dev": "tsx src/index.ts",
32
- "karin": "karin"
25
+ "sort": "npx sort-package-json"
33
26
  },
34
27
  "dependencies": {
35
28
  "@karinjs/geturls": "^1.0.2",
@@ -39,6 +32,18 @@
39
32
  "silk-wasm": "^3.6.3",
40
33
  "tweetnacl": "^1.0.3"
41
34
  },
35
+ "devDependencies": {
36
+ "@types/express": "5.0.5",
37
+ "@types/form-data": "^2.5.2",
38
+ "@types/node": "^20.17.19",
39
+ "@types/qrcode": "^1.5.5",
40
+ "eslint": "^9.21.0",
41
+ "neostandard": "^0.12.1",
42
+ "node-karin": "^1.12.2",
43
+ "tsup": "^8.3.6",
44
+ "tsx": "^4.19.3",
45
+ "typescript": "^5.7.3"
46
+ },
42
47
  "publishConfig": {
43
48
  "access": "public",
44
49
  "registry": "https://registry.npmjs.org"
@@ -46,7 +51,7 @@
46
51
  "karin": {
47
52
  "main": "src/index.ts",
48
53
  "apps": [
49
- "lib/apps"
54
+ "dist/apps"
50
55
  ],
51
56
  "ts-apps": [
52
57
  "src/apps"
@@ -58,6 +63,8 @@
58
63
  "config",
59
64
  "data",
60
65
  "resources"
61
- ]
66
+ ],
67
+ "ts-web": "src/web.config.ts",
68
+ "web": "dist/web.config.js"
62
69
  }
63
70
  }
@@ -1,3 +0,0 @@
1
- {
2
- "screenshotUrl": "网页截图测试地址"
3
- }
@@ -1,53 +0,0 @@
1
- # 全局默认配置 以下所有配置均可在账号配置中单独配置
2
- default:
3
- # 机器人ID
4
- appId: string
5
- # 机器人密钥
6
- secret: string
7
- # 正式环境api
8
- prodApi: https://api.sgroup.qq.com
9
- # 沙盒api
10
- sandboxApi: https://sandbox.api.sgroup.qq.com
11
- # 调用凭证的Api
12
- tokenApi: https://bots.qq.com/app/getAppAccessToken
13
- # 是否开启沙盒环境
14
- sandbox: false
15
- # 开启QQ场景能力
16
- qqEnable: true
17
- # 开启频道场景能力
18
- guildEnable: true
19
- # 频道场景模式 0-公域 1-私域
20
- guildMode: 0
21
- # 文本中的url转二维码白名单 配置后将不转换这些url为二维码
22
- exclude: []
23
- # 接受到消息后对文本进行表达式处理
24
- regex: [
25
- {
26
- # 表达式
27
- reg: "^#",
28
- # 替换为
29
- rep: "",
30
- },
31
- ]
32
- # markdown配置
33
- markdown:
34
- # 发送模式 0-关闭MD 1-原生MD 3-旧图文模板MD 4-纯文模板MD 5-自定义处理
35
- mode: 0
36
- # 模板ID
37
- id: ""
38
- kv:
39
- - text_start
40
- - img_dec
41
- - img_url
42
- - text_end
43
-
44
- # 事件接收配置
45
- event:
46
- # 接收方式 0-关闭 1-webhook 2-http 3-ws
47
- type: 0
48
- # ws服务器地址
49
- wsUrl: ws://example.com/webhook
50
- # ws服务器token
51
- wsToken: your_token
52
- # http鉴权token
53
- httpToken: your_token
package/lib/cli/pr.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/lib/cli/pr.js DELETED
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs';
3
- /**
4
- * @description 获取package.json路径
5
- */
6
- const getPkgPath = () => process.cwd() + '/package.json';
7
- /**
8
- * @description 读取package.json
9
- */
10
- const readPkg = () => JSON.parse(fs.readFileSync(getPkgPath(), 'utf-8'));
11
- /**
12
- * @description 写入package.json
13
- * @param pkg package.json
14
- */
15
- const writePkg = (pkg) => fs.writeFileSync(getPkgPath(), JSON.stringify(pkg, null, 2));
16
- /**
17
- * @description 构建pr版本号 <主版本号>.<次版本号>.<修订号>-<预发布标识>.<PR标识>.<PR编号>.<工作流唯一编号>-<时间戳>
18
-
19
- * @param pkg package.json
20
- */
21
- const updateVersion = (pkg) => {
22
- const list = pkg.version.split('.');
23
- // 1.0.0 => 1.0.1-beta.pr.pr编号.工作流唯一编号-时间戳 => 1.0.1-beta.pr.184-1631537630
24
- const timestamp = Math.floor(Date.now() / 1000);
25
- list[2] = `${Number(list[2]) + 1}-beta.pr.${process.env.PR_NUMBER}.${process.env.GITHUB_RUN_ATTEMPT || 1}-${timestamp}`;
26
- pkg.version = list.join('.');
27
- };
28
- /**
29
- * @description 设置环境变量
30
- * @param pkg package.json
31
- */
32
- const setEnvVariables = (pkg) => {
33
- fs.appendFileSync(process.env.GITHUB_ENV, `PKG_NAME=${pkg.name}\nPKG_VERSION=${pkg.version}\n`);
34
- };
35
- /**
36
- * @description 更新版本号并设置环境变量
37
- */
38
- const version = () => {
39
- const pkg = readPkg();
40
- updateVersion(pkg);
41
- writePkg(pkg);
42
- setEnvVariables(pkg);
43
- };
44
- /**
45
- * @description 删除devDependencies和peerDependencies
46
- */
47
- const clean = () => {
48
- const pkg = readPkg();
49
- delete pkg.devDependencies;
50
- delete pkg.peerDependencies;
51
- writePkg(pkg);
52
- };
53
- /**
54
- * @description 执行所有操作
55
- */
56
- const all = () => {
57
- const pkg = readPkg();
58
- updateVersion(pkg);
59
- delete pkg.devDependencies;
60
- delete pkg.peerDependencies;
61
- writePkg(pkg);
62
- setEnvVariables(pkg);
63
- };
64
- const cmd = process.argv[2];
65
- if (cmd === 'version') {
66
- version();
67
- }
68
- else if (cmd === 'clean') {
69
- clean();
70
- }
71
- else if (cmd === 'all') {
72
- all();
73
- }
@@ -1,91 +0,0 @@
1
- import FormData from 'form-data';
2
- import { QQBotApi } from '@/core/api';
3
- import { AdapterBase } from 'node-karin';
4
- import type { SendGuildMsg, SendGuildResponse, SendQQMsg, SendQQMsgResponse } from '@/core/api/types';
5
- import type { LoggerLevel, ButtonElement, KeyboardElement, MarkdownElement, MarkdownTplElement, SendMsgResults, Contact } from 'node-karin';
6
- /** 发送函数所需参数 */
7
- export type Options<T extends 'qq' | 'guild'> = T extends 'qq' ? SendQQMsg : SendGuildMsg | FormData;
8
- /** QQ发送消息函数类型 */
9
- export type QQSend = (peer: string, item: SendQQMsg) => Promise<SendQQMsgResponse>;
10
- /** 频道发送消息函数类型 */
11
- export type GuildSend = (peer: string, subPeer: string, item: SendGuildMsg | FormData) => Promise<SendGuildResponse>;
12
- export type Pasmsg<T extends 'qq' | 'guild'> = {
13
- type: 'msg' | 'event';
14
- msg_id: string;
15
- msg_seq: T extends 'qq' ? number : never;
16
- };
17
- export interface Grouping<T extends 'qq' | 'guild'> {
18
- /** 文本 */
19
- content: string[];
20
- /** 图片 QQ专属 */
21
- image: string[];
22
- /** 单行按钮 */
23
- button: ButtonElement[];
24
- /** 多行按钮 */
25
- keyboard: KeyboardElement[];
26
- /** markdown */
27
- markdown: MarkdownElement[];
28
- /** markdown模板 */
29
- markdownTpl: MarkdownTplElement[];
30
- /** 频道专属 图片url */
31
- imageUrls: string[];
32
- /** 频道专属 图片file */
33
- imageFiles: string[];
34
- /** 引用回复 频道专属 */
35
- reply: {
36
- message_id: string;
37
- };
38
- /** pasmsg */
39
- pasmsg: Pasmsg<T>;
40
- /** 代发送列表 */
41
- list: Array<Options<T>>;
42
- /**
43
- * 处理按钮、markdown
44
- * 统一格式后推入待发送消息列表
45
- * @param type 构建类型
46
- * @param list 分类列表
47
- * @returns
48
- */
49
- markdownToButton: (type: T, list: Grouping<T>) => void;
50
- }
51
- export declare abstract class AdapterQQBot extends AdapterBase {
52
- super: QQBotApi;
53
- constructor(QQBot: QQBotApi);
54
- logger(level: LoggerLevel, ...args: any[]): void;
55
- /**
56
- * 被动消息结构
57
- * @param type 消息类型
58
- */
59
- pasmsg<T extends 'qq' | 'guild'>(type: T): Pasmsg<T>;
60
- /**
61
- * 撤回消息
62
- * @param contact 联系人
63
- * @param messageId 消息id
64
- * @returns 撤回结果
65
- */
66
- recallMsg(contact: Contact, messageId: string): Promise<boolean>;
67
- /**
68
- * 初始化消息分类对象
69
- */
70
- initList<T extends 'qq' | 'guild'>(type: T): Grouping<T>;
71
- /**
72
- * 初始化发送消息返回值
73
- */
74
- initSendMsgResults(): SendMsgResults;
75
- /**
76
- * 处理返回值
77
- * @param data 返回值
78
- */
79
- handleResponse(data: SendMsgResults): SendMsgResults;
80
- /**
81
- * - 处理按钮、markdown
82
- * - 统一格式后推入待发送消息列表
83
- * @param type 消息类型
84
- * @param button 按钮
85
- * @param keyboard 键盘
86
- * @param markdown markdown
87
- * @param markdownTpl markdown模板
88
- * @returns 消息列表
89
- */
90
- markdownToButton<T extends 'qq' | 'guild'>(type: T, list: Grouping<T>): void;
91
- }
@@ -1,144 +0,0 @@
1
- import { random } from '@/utils/common';
2
- import { AdapterBase, logger, karinToQQBot } from 'node-karin';
3
- export class AdapterQQBot extends AdapterBase {
4
- super;
5
- constructor(QQBot) {
6
- super();
7
- this.super = QQBot;
8
- this.adapter.name = '@karinjs/qqbot';
9
- this.adapter.protocol = 'qqbot';
10
- this.adapter.platform = 'qq';
11
- this.adapter.standard = 'other';
12
- }
13
- logger(level, ...args) {
14
- logger.bot(level, this.selfId, ...args);
15
- }
16
- /**
17
- * 被动消息结构
18
- * @param type 消息类型
19
- */
20
- pasmsg(type) {
21
- if (type === 'qq') {
22
- return { type: 'msg', msg_id: '', msg_seq: random(1, 9999999) };
23
- }
24
- return { type: 'msg', msg_id: '' };
25
- }
26
- /**
27
- * 撤回消息
28
- * @param contact 联系人
29
- * @param messageId 消息id
30
- * @returns 撤回结果
31
- */
32
- async recallMsg(contact, messageId) {
33
- try {
34
- if (contact.scene === 'friend') {
35
- await this.super.recallMsg('user', contact.peer, messageId);
36
- return true;
37
- }
38
- if (contact.scene === 'group') {
39
- await this.super.recallMsg('group', contact.peer, messageId);
40
- return true;
41
- }
42
- if (contact.scene === 'direct') {
43
- await this.super.recallMsg('dms', contact.peer, messageId);
44
- return true;
45
- }
46
- if (contact.scene === 'guild') {
47
- await this.super.recallMsg('channels', contact.peer, messageId);
48
- return true;
49
- }
50
- return true;
51
- }
52
- catch {
53
- return false;
54
- }
55
- }
56
- /**
57
- * 初始化消息分类对象
58
- */
59
- initList(type) {
60
- const list = {
61
- content: [],
62
- image: [],
63
- button: [],
64
- keyboard: [],
65
- markdown: [],
66
- markdownTpl: [],
67
- imageUrls: [],
68
- imageFiles: [],
69
- reply: { message_id: '' },
70
- pasmsg: this.pasmsg(type),
71
- list: [],
72
- markdownToButton: (type, list) => this.markdownToButton(type, list)
73
- };
74
- return list;
75
- }
76
- /**
77
- * 初始化发送消息返回值
78
- */
79
- initSendMsgResults() {
80
- return {
81
- messageId: '',
82
- message_id: '',
83
- time: 0,
84
- messageTime: 0,
85
- rawData: []
86
- };
87
- }
88
- /**
89
- * 处理返回值
90
- * @param data 返回值
91
- */
92
- handleResponse(data) {
93
- const { id, timestamp } = data.rawData[0];
94
- data.messageId = id;
95
- data.message_id = id;
96
- data.messageTime = timestamp;
97
- data.messageTime = typeof timestamp === 'string' ? new Date(timestamp).getTime() : timestamp;
98
- return data;
99
- }
100
- /**
101
- * - 处理按钮、markdown
102
- * - 统一格式后推入待发送消息列表
103
- * @param type 消息类型
104
- * @param button 按钮
105
- * @param keyboard 键盘
106
- * @param markdown markdown
107
- * @param markdownTpl markdown模板
108
- * @returns 消息列表
109
- */
110
- markdownToButton(type, list) {
111
- /** 统一按钮 */
112
- const rows = [];
113
- if (list.button.length) {
114
- list.button.forEach((v) => {
115
- rows.push(...karinToQQBot(v));
116
- });
117
- }
118
- if (list.keyboard.length) {
119
- list.keyboard.forEach((v) => {
120
- rows.push(...karinToQQBot(v));
121
- });
122
- }
123
- list.markdown.forEach((v) => {
124
- const item = type === 'guild' ? this.super.GuildMsgOptions('markdown', { content: v.markdown }) : this.super.QQdMsgOptions('markdown', { content: v.markdown });
125
- if (rows.length)
126
- item.keyboard = { content: { rows } };
127
- list.list.push(item);
128
- });
129
- list.markdownTpl.forEach((v) => {
130
- const item = type === 'guild'
131
- ? this.super.GuildMsgOptions('markdown', {
132
- custom_template_id: v.templateId,
133
- params: v.params
134
- })
135
- : this.super.QQdMsgOptions('markdown', {
136
- custom_template_id: v.templateId,
137
- params: v.params
138
- });
139
- if (rows.length)
140
- item.keyboard = { content: { rows } };
141
- list.list.push(item);
142
- });
143
- }
144
- }