@karinjs/adapter-qqbot 1.3.1 → 2.1.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,189 @@
1
- import {
2
- config_exports,
3
- pkg,
4
- writeConfig
5
- } from "./chunk-PYOUSZ6B.js";
1
+ import { a as writeConfig, n as config, o as pkg } from "./config-DKa7596f.js";
2
+ import "./utils-BPbnNAix.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
+ "messageCache:enable": item.messageCache?.enable === true,
36
+ "messageCache:self": item.messageCache?.self === true,
37
+ "event:type": String(item.event?.type ?? 2)
38
+ });
39
+ });
40
+ return [components.accordionPro.create("qqbot", data, {
41
+ label: "QQBot",
42
+ description: "QQBot 配置",
43
+ children: {
44
+ key: "qqbotConfig",
45
+ children: [
46
+ components.input.create("name", {
47
+ label: "机器人名称",
48
+ description: "机器人名称,扫码登录会自动获取"
49
+ }),
50
+ components.input.create("appId", {
51
+ label: "AppID",
52
+ description: "机器人 AppID",
53
+ isRequired: true
54
+ }),
55
+ components.input.create("secret", {
56
+ label: "Secret",
57
+ description: "机器人 Secret",
58
+ isRequired: true
59
+ }),
60
+ components.input.create("prodApi", {
61
+ label: "正式环境 API",
62
+ defaultValue: "https://api.sgroup.qq.com",
63
+ isRequired: true
64
+ }),
65
+ components.input.create("sandboxApi", {
66
+ label: "沙盒环境 API",
67
+ defaultValue: "https://sandbox.api.sgroup.qq.com",
68
+ isRequired: true
69
+ }),
70
+ components.input.create("tokenApi", {
71
+ label: "AccessToken 接口",
72
+ defaultValue: "https://bots.qq.com/app/getAppAccessToken",
73
+ isRequired: true
74
+ }),
75
+ components.switch.create("sandbox", {
76
+ label: "沙盒环境",
77
+ description: "启用后调用沙盒 API",
78
+ defaultSelected: false
79
+ }),
80
+ components.switch.create("qqEnable", {
81
+ label: "QQ 场景",
82
+ description: "是否处理私聊和群聊消息",
83
+ defaultSelected: true
84
+ }),
85
+ components.switch.create("guildEnable", {
86
+ label: "频道场景",
87
+ description: "是否处理频道消息",
88
+ defaultSelected: true
89
+ }),
90
+ components.switch.create("guildMode", {
91
+ label: "频道私域模式",
92
+ description: "开启 = 私域机器人;关闭 = 公域机器人",
93
+ defaultSelected: false
94
+ }),
95
+ components.input.group("regex", {
96
+ data: [],
97
+ label: "消息正则替换",
98
+ description: "每行格式:正则表达式 替换内容。如:^/ #",
99
+ template: components.input.create("regex", {
100
+ label: "正则规则",
101
+ placeholder: "^/ #"
102
+ })
103
+ }),
104
+ components.switch.create("keyboard:enable", {
105
+ label: "URL 自动按钮",
106
+ description: "将文本中的链接自动转为 keyboard 按钮",
107
+ defaultSelected: true
108
+ }),
109
+ components.switch.create("messageCache:enable", {
110
+ label: "启用数据库缓存消息",
111
+ description: "用于 bot.getMsg 查询最近一天消息。开启后会将收到的消息写入本地数据库,并把接收到的富媒体保存到本地;高并发或富媒体消息量较大时不建议开启,可能快速占用磁盘空间甚至导致磁盘溢出。",
112
+ defaultSelected: false
113
+ }),
114
+ components.switch.create("messageCache:self", {
115
+ label: "缓存自己消息",
116
+ description: "仅在启用数据库缓存消息时生效,发送成功后缓存机器人自己的消息",
117
+ defaultSelected: false
118
+ }),
119
+ components.radio.group("event:type", {
120
+ label: "事件接收方式",
121
+ description: "选择 QQ 官方推送事件的方式",
122
+ defaultValue: "2",
123
+ radio: [
124
+ components.radio.create("0", {
125
+ label: "关闭",
126
+ value: "0",
127
+ description: "不接收任何事件"
128
+ }),
129
+ components.radio.create("1", {
130
+ label: "Webhook",
131
+ value: "1",
132
+ description: "QQ 官方主动推送事件到本机"
133
+ }),
134
+ components.radio.create("2", {
135
+ label: "WebSocket",
136
+ value: "2",
137
+ description: "主动连接 QQ 官方 WebSocket 网关接收事件(推荐)"
138
+ })
139
+ ]
140
+ })
141
+ ]
142
+ }
143
+ })];
144
+ },
145
+ save: (input) => {
146
+ if (!Array.isArray(input.qqbot)) return {
147
+ success: false,
148
+ message: "保存失败:配置格式错误"
149
+ };
150
+ const data = input.qqbot.map((item) => {
151
+ const guildMode = item.guildMode === true ? 1 : 0;
152
+ const eventType = Number(item["event:type"] ?? 0);
153
+ const regex = (item.regex || []).map((str) => {
154
+ const parts = str.split(" ");
155
+ return {
156
+ reg: parts[0]?.replace(/^<|>$/g, "") || "",
157
+ rep: parts[1]?.replace(/^<|>$/g, "") || ""
158
+ };
159
+ });
160
+ return {
161
+ name: item.name || "",
162
+ appId: item.appId || "",
163
+ secret: item.secret || "",
164
+ prodApi: item.prodApi || "https://api.sgroup.qq.com",
165
+ sandboxApi: item.sandboxApi || "https://sandbox.api.sgroup.qq.com",
166
+ tokenApi: item.tokenApi || "https://bots.qq.com/app/getAppAccessToken",
167
+ sandbox: !!item.sandbox,
168
+ qqEnable: !!item.qqEnable,
169
+ guildEnable: !!item.guildEnable,
170
+ guildMode,
171
+ regex,
172
+ keyboard: { enable: item["keyboard:enable"] !== false },
173
+ messageCache: {
174
+ enable: !!item["messageCache:enable"],
175
+ self: !!item["messageCache:self"]
176
+ },
177
+ event: { type: eventType }
178
+ };
179
+ });
180
+ writeConfig(data);
181
+ return {
182
+ success: true,
183
+ message: "保存成功"
184
+ };
185
+ }
221
186
  });
222
- export {
223
- web_config_default as default
224
- };
187
+
188
+ //#endregion
189
+ 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.1.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,36 +13,37 @@
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.6",
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.13.2",
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.3",
45
+ "tsx": "^4.22.4",
46
+ "typescript": "^6.0.3"
46
47
  },
47
48
  "publishConfig": {
48
49
  "access": "public",