@karinjs/adapter-qqbot 1.3.1 → 2.0.0

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.
@@ -1,224 +1,173 @@
1
- import {
2
- config_exports,
3
- pkg,
4
- writeConfig
5
- } from "./chunk-PYOUSZ6B.js";
1
+ import { a as pkg, n as config, o as writeConfig } from "./config-H7LrvlNU.js";
2
+ import "./utils-DO4gEkVN.js";
3
+ import { components, defineConfig } from "node-karin";
6
4
 
7
- // src/web.config.ts
8
- import { defineConfig, components } from "node-karin";
5
+ //#region src/web.config.ts
9
6
  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
- }
7
+ info: {
8
+ id: pkg().name,
9
+ name: "QQBot 适配器",
10
+ version: pkg().version,
11
+ description: "为 karin 提供 QQ 官方 Bot 连接能力(2.0)",
12
+ author: [{
13
+ name: "shijin",
14
+ avatar: "https://github.com/sj817.png"
15
+ }]
16
+ },
17
+ components: () => {
18
+ const data = [];
19
+ config().forEach((item) => {
20
+ data.push({
21
+ title: item.name || item.appId,
22
+ subtitle: item.appId,
23
+ name: item.name,
24
+ appId: item.appId,
25
+ secret: item.secret,
26
+ prodApi: item.prodApi,
27
+ sandboxApi: item.sandboxApi,
28
+ tokenApi: item.tokenApi,
29
+ sandbox: item.sandbox,
30
+ qqEnable: item.qqEnable,
31
+ guildEnable: item.guildEnable,
32
+ guildMode: item.guildMode === 1,
33
+ regex: item.regex.map((r) => `${r.reg} ${r.rep}`),
34
+ "keyboard:enable": item.keyboard?.enable !== false,
35
+ "event:type": String(item.event?.type ?? 2)
36
+ });
37
+ });
38
+ return [components.accordionPro.create("qqbot", data, {
39
+ label: "QQBot",
40
+ description: "QQBot 配置",
41
+ children: {
42
+ key: "qqbotConfig",
43
+ children: [
44
+ components.input.create("name", {
45
+ label: "机器人名称",
46
+ description: "机器人名称,扫码登录会自动获取"
47
+ }),
48
+ components.input.create("appId", {
49
+ label: "AppID",
50
+ description: "机器人 AppID",
51
+ isRequired: true
52
+ }),
53
+ components.input.create("secret", {
54
+ label: "Secret",
55
+ description: "机器人 Secret",
56
+ isRequired: true
57
+ }),
58
+ components.input.create("prodApi", {
59
+ label: "正式环境 API",
60
+ defaultValue: "https://api.sgroup.qq.com",
61
+ isRequired: true
62
+ }),
63
+ components.input.create("sandboxApi", {
64
+ label: "沙盒环境 API",
65
+ defaultValue: "https://sandbox.api.sgroup.qq.com",
66
+ isRequired: true
67
+ }),
68
+ components.input.create("tokenApi", {
69
+ label: "AccessToken 接口",
70
+ defaultValue: "https://bots.qq.com/app/getAppAccessToken",
71
+ isRequired: true
72
+ }),
73
+ components.switch.create("sandbox", {
74
+ label: "沙盒环境",
75
+ description: "启用后调用沙盒 API",
76
+ defaultSelected: false
77
+ }),
78
+ components.switch.create("qqEnable", {
79
+ label: "QQ 场景",
80
+ description: "是否处理私聊和群聊消息",
81
+ defaultSelected: true
82
+ }),
83
+ components.switch.create("guildEnable", {
84
+ label: "频道场景",
85
+ description: "是否处理频道消息",
86
+ defaultSelected: true
87
+ }),
88
+ components.switch.create("guildMode", {
89
+ label: "频道私域模式",
90
+ description: "开启 = 私域机器人;关闭 = 公域机器人",
91
+ defaultSelected: false
92
+ }),
93
+ components.input.group("regex", {
94
+ data: [],
95
+ label: "消息正则替换",
96
+ description: "每行格式:正则表达式 替换内容。如:^/ #",
97
+ template: components.input.create("regex", {
98
+ label: "正则规则",
99
+ placeholder: "^/ #"
100
+ })
101
+ }),
102
+ components.switch.create("keyboard:enable", {
103
+ label: "URL 自动按钮",
104
+ description: "将文本中的链接自动转为 keyboard 按钮",
105
+ defaultSelected: true
106
+ }),
107
+ components.radio.group("event:type", {
108
+ label: "事件接收方式",
109
+ description: "选择 QQ 官方推送事件的方式",
110
+ defaultValue: "2",
111
+ radio: [
112
+ components.radio.create("0", {
113
+ label: "关闭",
114
+ value: "0",
115
+ description: "不接收任何事件"
116
+ }),
117
+ components.radio.create("1", {
118
+ label: "Webhook",
119
+ value: "1",
120
+ description: "QQ 官方主动推送事件到本机"
121
+ }),
122
+ components.radio.create("2", {
123
+ label: "WebSocket",
124
+ value: "2",
125
+ description: "主动连接 QQ 官方 WebSocket 网关接收事件(推荐)"
126
+ })
127
+ ]
128
+ })
129
+ ]
130
+ }
131
+ })];
132
+ },
133
+ save: (input) => {
134
+ if (!Array.isArray(input.qqbot)) return {
135
+ success: false,
136
+ message: "保存失败:配置格式错误"
137
+ };
138
+ const data = input.qqbot.map((item) => {
139
+ const guildMode = item.guildMode === true ? 1 : 0;
140
+ const eventType = Number(item["event:type"] ?? 0);
141
+ const regex = (item.regex || []).map((str) => {
142
+ const parts = str.split(" ");
143
+ return {
144
+ reg: parts[0]?.replace(/^<|>$/g, "") || "",
145
+ rep: parts[1]?.replace(/^<|>$/g, "") || ""
146
+ };
147
+ });
148
+ return {
149
+ name: item.name || "",
150
+ appId: item.appId || "",
151
+ secret: item.secret || "",
152
+ prodApi: item.prodApi || "https://api.sgroup.qq.com",
153
+ sandboxApi: item.sandboxApi || "https://sandbox.api.sgroup.qq.com",
154
+ tokenApi: item.tokenApi || "https://bots.qq.com/app/getAppAccessToken",
155
+ sandbox: !!item.sandbox,
156
+ qqEnable: !!item.qqEnable,
157
+ guildEnable: !!item.guildEnable,
158
+ guildMode,
159
+ regex,
160
+ keyboard: { enable: item["keyboard:enable"] !== false },
161
+ event: { type: eventType }
162
+ };
163
+ });
164
+ writeConfig(data);
165
+ return {
166
+ success: true,
167
+ message: "保存成功"
168
+ };
169
+ }
221
170
  });
222
- export {
223
- web_config_default as default
224
- };
171
+
172
+ //#endregion
173
+ export { web_config_default as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@karinjs/adapter-qqbot",
3
- "version": "1.3.1",
4
- "description": "karin plugin adapter for qqbot",
3
+ "version": "2.0.0",
4
+ "description": "karin adapter for QQ Official Bot (2.0)",
5
5
  "homepage": "https://github.com/KarinJS/karin-plugin-adapter-qqbot",
6
6
  "bugs": {
7
7
  "url": "https://github.com/KarinJS/karin-plugin-adapter-qqbot/issues"
@@ -13,41 +13,47 @@
13
13
  "author": "shijin",
14
14
  "type": "module",
15
15
  "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
16
17
  "files": [
17
18
  "dist"
18
19
  ],
19
20
  "scripts": {
20
- "build": "tsc && tsup",
21
- "dev": "tsx src/app.ts",
21
+ "build": "tsc && tsdown",
22
+ "dev": "tsx watch --include \"src/**/*.ts\" src/app.ts",
22
23
  "karin": "karin",
24
+ "lint": "eslint src",
25
+ "lint:fix": "eslint src --fix",
23
26
  "pub": "npm publish --access public",
24
- "pub-beta": "npm publish --tag beta",
25
27
  "sort": "npx sort-package-json"
26
28
  },
27
29
  "dependencies": {
28
30
  "@karinjs/geturls": "^1.0.2",
29
- "form-data": "^4.0.2",
30
- "image-size": "^1.2.0",
31
+ "form-data": "^4.0.5",
32
+ "image-size": "^2.0.2",
31
33
  "qrcode": "^1.5.4",
32
- "silk-wasm": "^3.6.3",
34
+ "silk-wasm": "^3.7.1",
33
35
  "tweetnacl": "^1.0.3"
34
36
  },
35
37
  "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"
38
+ "@types/express": "5.0.6",
39
+ "@types/node": "^24.12.4",
40
+ "@types/qrcode": "^1.5.6",
41
+ "eslint": "^9.39.4",
42
+ "neostandard": "^0.13.0",
43
+ "node-karin": "^1.15.5",
44
+ "tsdown": "^0.22.0",
45
+ "tsx": "^4.22.0",
46
+ "typescript": "^6.0.3"
46
47
  },
47
48
  "publishConfig": {
48
49
  "access": "public",
49
50
  "registry": "https://registry.npmjs.org"
50
51
  },
52
+ "pnpm": {
53
+ "overrides": {
54
+ "yaml@>=2.0.0 <2.8.3": "^2.8.3"
55
+ }
56
+ },
51
57
  "karin": {
52
58
  "main": "src/index.ts",
53
59
  "apps": [