@karinjs/adapter-qqbot 1.2.9 → 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.
@@ -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,9 +1,7 @@
1
1
  {
2
2
  "name": "@karinjs/adapter-qqbot",
3
- "version": "1.2.9",
4
- "author": "shijin",
5
- "type": "module",
6
- "description": "karin plugin template",
3
+ "version": "1.3.1",
4
+ "description": "karin plugin adapter for qqbot",
7
5
  "homepage": "https://github.com/KarinJS/karin-plugin-adapter-qqbot",
8
6
  "bugs": {
9
7
  "url": "https://github.com/KarinJS/karin-plugin-adapter-qqbot/issues"
@@ -12,34 +10,61 @@
12
10
  "type": "git",
13
11
  "url": "git+https://github.com/KarinJS/karin-plugin-adapter-qqbot.git"
14
12
  },
15
- "main": "lib/index.js",
16
- "types": "lib/index.d.ts",
13
+ "author": "shijin",
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "files": [
17
+ "dist"
18
+ ],
17
19
  "scripts": {
18
- "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
19
- "pub": "npm publish --access public"
20
+ "build": "tsc && tsup",
21
+ "dev": "tsx src/app.ts",
22
+ "karin": "karin",
23
+ "pub": "npm publish --access public",
24
+ "pub-beta": "npm publish --tag beta",
25
+ "sort": "npx sort-package-json"
20
26
  },
21
27
  "dependencies": {
22
28
  "@karinjs/geturls": "^1.0.2",
23
- "got": "^14.4.1",
24
- "jimp": "^0.22.12",
25
- "qrcode": "^1.5.3",
26
- "silk-wasm": "^3.6.1"
29
+ "form-data": "^4.0.2",
30
+ "image-size": "^1.2.0",
31
+ "qrcode": "^1.5.4",
32
+ "silk-wasm": "^3.6.3",
33
+ "tweetnacl": "^1.0.3"
27
34
  },
28
- "karin": {
29
- "apps": [],
30
- "outDir": "lib",
31
- "rootDir": "src"
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"
32
46
  },
33
- "files": [
34
- "/lib/**/*.js",
35
- "/lib/**/*.d.ts",
36
- "/config/*.yaml",
37
- "LICENSE",
38
- "package.json",
39
- "README.md"
40
- ],
41
47
  "publishConfig": {
42
48
  "access": "public",
43
49
  "registry": "https://registry.npmjs.org"
50
+ },
51
+ "karin": {
52
+ "main": "src/index.ts",
53
+ "apps": [
54
+ "dist/apps"
55
+ ],
56
+ "ts-apps": [
57
+ "src/apps"
58
+ ],
59
+ "static": [
60
+ "resources"
61
+ ],
62
+ "files": [
63
+ "config",
64
+ "data",
65
+ "resources"
66
+ ],
67
+ "ts-web": "src/web.config.ts",
68
+ "web": "dist/web.config.js"
44
69
  }
45
- }
70
+ }
@@ -1,69 +0,0 @@
1
- # 全局默认配置 以下所有配置均可在账号配置中单独配置
2
- default:
3
- # 获取调用凭证的api
4
- accessTokenApi: https://bots.qq.com/app/getAppAccessToken
5
- # 沙盒api
6
- sandBoxApi: https://sandbox.api.sgroup.qq.com
7
- # 正式环境api
8
- qqBotApi: https://api.sgroup.qq.com
9
- # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
10
- sendMode: 0
11
- # 是否开启沙盒环境
12
- sandBox: false
13
- # 是否启用频道机器人
14
- guild: false
15
- # 频道机器人模式 0-公域机器人 1-私域机器人
16
- guildMode: 0
17
-
18
- # 机器人Markdown模板ID 只有在sendMode为3或4时有效
19
- templateId: ""
20
-
21
- # 机器人旧图文模板Markdown配置
22
- oldTemplate:
23
- # 开头文字
24
- textStartKey: text_start
25
- # 图片描述
26
- imgDescKey: img_dec
27
- # 图片地址
28
- imgUrlKey: img_url
29
- # 结尾文字
30
- textEndKey: text_end
31
-
32
- # 机器人纯文模板Markdown配置
33
- textTemplate:
34
- - text_0
35
- - text_1
36
- - text_2
37
- - text_3
38
- - text_4
39
- - text_5
40
- - text_6
41
- - text_7
42
- - text_8
43
- - text_9
44
-
45
- # 文本中的url转二维码白名单 配置后将不转换这些url为二维码
46
- exclude: []
47
- # 接受到消息后对文本进行表达式处理
48
- regex: [
49
- {
50
- # 表达式
51
- reg: "^#",
52
- # 替换为
53
- rep: "",
54
- },
55
- ]
56
-
57
- # 账号配置列表
58
- accounts:
59
- default:
60
- # 机器人ID 必须为字符串
61
- appId: "123456789"
62
- # 机器人密钥
63
- secret: "123456789"
64
- # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
65
- sendMode: 0
66
- # 文本中的url转二维码白名单 配置后将不转换这些url为二维码 优先级高于全局配置
67
- exclude: []
68
- # 接受到消息后对文本进行表达式处理 优先级高于全局配置
69
- regex: []
package/lib/core/api.d.ts DELETED
@@ -1,180 +0,0 @@
1
- import WebSocket from 'ws';
2
- import EventEmitter from 'events';
3
- import { AccountCfgType } from '../utils/index.js';
4
- import { LoggerLevel } from 'node-karin';
5
- import { IdType, FileType, PathType, V2ApiType, UploadMediaOptions, SendMessageOptions, UploadMediaResponse, SubEvent } from '../types/index.js';
6
- export interface SendMessageResponse {
7
- /** 消息唯一ID */
8
- id: string;
9
- /** 发送时间 */
10
- timestamp: number;
11
- }
12
- /**
13
- * {key: xxx, values: xxx},模版内变量与填充值的kv映射
14
- */
15
- export type Params = Array<{
16
- key: string;
17
- values: string[];
18
- }>;
19
- export declare class QQBotApi extends EventEmitter {
20
- #private;
21
- /** 开发者的appId */
22
- appId: string;
23
- /** Bot头像 */
24
- avatar: string;
25
- /** Bot的昵称 */
26
- nick: string;
27
- /** wss地址 */
28
- wssUrl: string;
29
- /** wss连接 */
30
- wss: WebSocket;
31
- /** wss连接唯一值 */
32
- seq: number;
33
- /** 心跳内容 */
34
- heartbeat: {
35
- op: 1;
36
- d: null | number;
37
- session_id: string;
38
- };
39
- /** 心跳生命周期 单位:毫秒 */
40
- heartbeat_interval: number;
41
- /** 请求头 用于鉴权 */
42
- headers: {
43
- [key: string]: string;
44
- };
45
- /** 基本请求接口 */
46
- host: string;
47
- constructor(config: AccountCfgType);
48
- logger(level: LoggerLevel, ...args: any[]): void;
49
- /**
50
- * post请求
51
- * @param url 请求地址
52
- * @param options 请求参数
53
- */
54
- post(url: string, options: any): Promise<import("got").Response<string> | undefined>;
55
- /**
56
- * delete请求
57
- * @param url 请求地址
58
- * @param options 请求参数
59
- */
60
- delete(url: string): Promise<import("got").Response<string> | undefined>;
61
- /**
62
- * 获取调用凭证
63
- * @param clientSecret 开发者的Secret
64
- * @param isRefresh 是否是刷新凭证
65
- */
66
- getAccessToken(isRefresh?: boolean): Promise<{
67
- /** 凭证有效时间,单位:秒 需要在倒计时50秒内刷新凭证 */
68
- expires_in: string;
69
- /** 调用凭证 */
70
- access_token: string;
71
- }>;
72
- /**
73
- * wss鉴权
74
- * @param isAuth 是否鉴权
75
- */
76
- wssAuth(isAuth: boolean): Promise<void>;
77
- /**
78
- * 获取wss地址
79
- */
80
- getWssUrl(): Promise<void>;
81
- /**
82
- * 获取当前Bot信息
83
- */
84
- getBotInfo(): Promise<{
85
- /** Bot id */
86
- id: string;
87
- /** Bot昵称 */
88
- username: string;
89
- /** Bot头像 */
90
- avatar: string;
91
- /** Bot分享链接 */
92
- share_url: string;
93
- /** 欢迎信息 */
94
- welcome_msg: string;
95
- }>;
96
- /**
97
- * 创建wss连接
98
- */
99
- createWss(isAuth?: boolean): void;
100
- payload(payload: string): void;
101
- /**
102
- * 事件处理
103
- */
104
- intents(data: SubEvent): Promise<void>;
105
- /**
106
- * 发送消息
107
- * @param openid 用户、群openid
108
- * @param type 请求路径类型
109
- * @param options 请求参数
110
- */
111
- sendMessage(openid: string, type: PathType, options: SendMessageOptions): Promise<SendMessageResponse>;
112
- /**
113
- * 撤回消息
114
- * @param openid 用户、群openid
115
- * @param type 请求路径类型
116
- * @param message_id 消息id
117
- */
118
- recallMessage(openid: string, type: PathType, message_id: string): Promise<boolean>;
119
- /**
120
- * 构建发送文本消息请求参数
121
- */
122
- buildText(content: string, id?: string, seq?: number): SendMessageOptions;
123
- /**
124
- * 上传富媒体文件
125
- * @param openid 用户、群openid
126
- * @param type 请求类型
127
- * @param file 文件内容 http、base64、file://
128
- * @param file_type 文件类型
129
- */
130
- uploadMedia(openid: string, type: PathType, file: string, file_type: FileType): Promise<UploadMediaResponse>;
131
- /**
132
- * 构建v2接口请求地址
133
- * @param openid 用户、群openid
134
- * @param type 请求类型
135
- * @param apiType v2接口类型
136
- */
137
- buildUrl(openid: string, type: PathType, apiType: V2ApiType): string;
138
- /**
139
- * 传入一个msg_id或者event_id 返回其对应的key和value
140
- * @param id 消息id或者事件id
141
- */
142
- buildId(id: string): {
143
- key: IdType;
144
- value: string;
145
- };
146
- /**
147
- * 构建发送富媒体请求参数
148
- * 富媒体消息只能单独发送 并且必须进行上传
149
- * @param content 附带的文字信息,仅在file_type为1时有效,其余情况请传空字符串
150
- * @param file_info 富媒体接口返回的file_info
151
- * @param id 消息id或者事件id
152
- */
153
- buildMedia(content: string, file_info: string, id?: string, seq?: number): SendMessageOptions;
154
- /**
155
- * 构建发送Markdown模板请求参数
156
- * @param custom_template_id 模板id
157
- * @param params 模板参数
158
- * @param id 消息id或者事件id
159
- * @param seq 消息序号
160
- */
161
- buildTplMarkdown(custom_template_id: string, params: Params, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
162
- /**
163
- * 构建发送原生Markdown请求参数
164
- * @param content markdown文本
165
- * @param id 消息id或者事件id
166
- * @param seq 消息序号
167
- */
168
- buildRawMarkdown(content: string, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
169
- /**
170
- * 构建上传富媒体请求参数
171
- * @param file 文件内容 http、base64、file://
172
- * @param file_type 文件类型
173
- */
174
- buildUploadMedia(file: string, file_type: FileType): Promise<{
175
- json: UploadMediaOptions;
176
- headers: {
177
- [key: string]: string;
178
- };
179
- }>;
180
- }