@alemonjs/qq-bot 2.1.0-alpha.30 → 2.1.0-alpha.32
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/README.md +13 -22
- package/lib/hook.d.ts +2 -2
- package/lib/index.websoket.js +6 -17
- package/lib/sdk/api.d.ts +2 -2
- package/lib/sdk/api.js +27 -48
- package/lib/sdk/typing.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,33 +24,24 @@ qq-bot:
|
|
|
24
24
|
secret: ''
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
>
|
|
27
|
+
> 1、默认 websocket 模式,配置 route/port 可选择 webhook 模式
|
|
28
28
|
|
|
29
|
-
>
|
|
29
|
+
> 2、webhook 模式,需 ip/域名,一旦生效官方将禁用 websocket 模式
|
|
30
|
+
|
|
31
|
+
> 3、gatewayURL 直连模式,
|
|
32
|
+
|
|
33
|
+
> 4、域名代理模式
|
|
30
34
|
|
|
31
35
|
```sh
|
|
32
36
|
qq-bot:
|
|
33
37
|
# 频道沙盒,默认false
|
|
34
|
-
sandbox: false
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
# 2)webhook 模式
|
|
39
|
-
# 推荐nginx进行代理 http://localhost:17157/webhook
|
|
40
|
-
# 填写将启动 webhook模式
|
|
41
|
-
port: 17157
|
|
42
|
-
route: '/webhook'
|
|
43
|
-
# 当配置ws的时候,会连接另一台webhook机器人的消息。不会再启动本地端口。
|
|
44
|
-
# 假设代理后的地址为 https://qqbotjs.com
|
|
45
|
-
# ws: 'wss://qqbotjs.com/websocket'
|
|
46
|
-
# ws: 'ws://[your ip]:17157/websocket'
|
|
38
|
+
# sandbox: false
|
|
39
|
+
# 2)填写将启动 webhook模式
|
|
40
|
+
# port: 17157
|
|
41
|
+
# route: '/webhook'
|
|
47
42
|
# 3) 自定义模式 (用于连接类官网连接方式的指定服务端)
|
|
48
43
|
# gatewayURL: 'ws://[your ip]:8080'
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
- 'xxx'
|
|
53
|
-
# 使用 user_id
|
|
54
|
-
master_id:
|
|
55
|
-
- 'yyy'
|
|
44
|
+
# 4) 域名代理模式
|
|
45
|
+
# base_url_gateway: https://[your addr]
|
|
46
|
+
# base_url_app_access_token: https://[your addr]
|
|
56
47
|
```
|
package/lib/hook.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare const useValue: <T extends EventKeys>(event: Events[T]) => readon
|
|
|
28
28
|
export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
29
29
|
getAuthentication: () => Promise<import("alemonjs").Result<any>>;
|
|
30
30
|
groupService: (options: import("axios").AxiosRequestConfig<any>) => Promise<import("alemonjs").Result<any>>;
|
|
31
|
-
guildServer: (
|
|
31
|
+
guildServer: (options: import("axios").AxiosRequestConfig<any>) => Promise<import("alemonjs").Result<any>>;
|
|
32
32
|
gateway: () => Promise<import("alemonjs").Result<any>>;
|
|
33
33
|
usersOpenMessages: (openid: string, data: import("./sdk/typing").ApiRequestData) => Promise<import("alemonjs").Result<{
|
|
34
34
|
id: string;
|
|
@@ -215,7 +215,7 @@ export declare const useClient: <T extends EventKeys>(event: Events[T]) => reado
|
|
|
215
215
|
}) => Promise<import("alemonjs").Result<any>>;
|
|
216
216
|
channelsThreadsDelete: (channel_id: string, thread_id: string) => Promise<import("alemonjs").Result<any>>;
|
|
217
217
|
guildApiPermission: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
|
|
218
|
-
interactionResponse: (
|
|
218
|
+
interactionResponse: (_mode: "group" | "guild", interaction_id: string, code?: number) => Promise<import("alemonjs").Result<any>>;
|
|
219
219
|
}, MAP[T]];
|
|
220
220
|
export declare const useMode: <T extends EventKeys>(event: Events[T]) => (mode: "guild" | "group" | "c2c") => boolean;
|
|
221
221
|
export {};
|
package/lib/index.websoket.js
CHANGED
|
@@ -22,24 +22,11 @@ const start = () => {
|
|
|
22
22
|
const isGroupIntents = ['GROUP_AND_C2C_EVENT'];
|
|
23
23
|
const pubIntents = ['INTERACTION'];
|
|
24
24
|
const intents = [];
|
|
25
|
-
if (config?.
|
|
26
|
-
|
|
27
|
-
intents.push(...isPrivateIntents, ...pubIntents);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
intents.push(...notPrivateIntents, ...pubIntents);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else if (config?.mode === 'group') {
|
|
34
|
-
intents.push(...isGroupIntents, ...pubIntents);
|
|
25
|
+
if (config?.is_private) {
|
|
26
|
+
intents.push(...isPrivateIntents, ...pubIntents);
|
|
35
27
|
}
|
|
36
28
|
else {
|
|
37
|
-
|
|
38
|
-
intents.push(...isPrivateIntents, ...pubIntents);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
intents.push(...notPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
42
|
-
}
|
|
29
|
+
intents.push(...notPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
43
30
|
}
|
|
44
31
|
const client = new QQBotClients({
|
|
45
32
|
...config,
|
|
@@ -47,7 +34,9 @@ const start = () => {
|
|
|
47
34
|
is_private: config?.is_private ?? false,
|
|
48
35
|
sandbox: config?.sandbox ?? false,
|
|
49
36
|
shard: config?.shard ?? [0, 1],
|
|
50
|
-
|
|
37
|
+
gatewayURL: config?.gatewayURL,
|
|
38
|
+
base_url_gateway: config?.base_url_gateway,
|
|
39
|
+
base_url_app_access_token: config?.base_url_app_access_token
|
|
51
40
|
});
|
|
52
41
|
void client.connect(config?.gatewayURL);
|
|
53
42
|
register(client);
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const API_URL = "https://api.sgroup.qq.com";
|
|
|
6
6
|
export declare class QQBotAPI {
|
|
7
7
|
getAuthentication(): Promise<any>;
|
|
8
8
|
groupService(options: AxiosRequestConfig): Promise<any>;
|
|
9
|
-
guildServer(
|
|
9
|
+
guildServer(options: AxiosRequestConfig): Promise<any>;
|
|
10
10
|
gateway(): Promise<any>;
|
|
11
11
|
usersOpenMessages(openid: string, data: ApiRequestData): Promise<{
|
|
12
12
|
id: string;
|
|
@@ -193,5 +193,5 @@ export declare class QQBotAPI {
|
|
|
193
193
|
}): Promise<any>;
|
|
194
194
|
channelsThreadsDelete(channel_id: string, thread_id: string): Promise<any>;
|
|
195
195
|
guildApiPermission(guild_id: string): Promise<any>;
|
|
196
|
-
interactionResponse(
|
|
196
|
+
interactionResponse(_mode: 'group' | 'guild', interaction_id: string, code?: number): Promise<any>;
|
|
197
197
|
}
|
package/lib/sdk/api.js
CHANGED
|
@@ -12,12 +12,19 @@ class QQBotAPI {
|
|
|
12
12
|
getAuthentication() {
|
|
13
13
|
const app_id = config.get('app_id');
|
|
14
14
|
const secret = config.get('secret');
|
|
15
|
+
const baseUrlAppAccessToken = config.get('base_url_app_access_token');
|
|
16
|
+
const params = {
|
|
17
|
+
url: '/app/getAppAccessToken'
|
|
18
|
+
};
|
|
19
|
+
if (baseUrlAppAccessToken) {
|
|
20
|
+
params.baseURL = baseUrlAppAccessToken;
|
|
21
|
+
}
|
|
15
22
|
const service = axios.create({
|
|
16
23
|
baseURL: BOTS_API_RUL,
|
|
17
24
|
timeout: 20000
|
|
18
25
|
});
|
|
19
26
|
return createAxiosInstance(service, {
|
|
20
|
-
|
|
27
|
+
...params,
|
|
21
28
|
method: 'post',
|
|
22
29
|
data: {
|
|
23
30
|
appId: `${app_id}`,
|
|
@@ -28,8 +35,9 @@ class QQBotAPI {
|
|
|
28
35
|
groupService(options) {
|
|
29
36
|
const app_id = config.get('app_id');
|
|
30
37
|
const token = config.get('access_token');
|
|
38
|
+
const sandbox = config.get('sandbox');
|
|
31
39
|
const service = axios.create({
|
|
32
|
-
baseURL: API_URL,
|
|
40
|
+
baseURL: sandbox ? API_URL_SANDBOX : API_URL,
|
|
33
41
|
timeout: 20000,
|
|
34
42
|
headers: {
|
|
35
43
|
'X-Union-Appid': app_id,
|
|
@@ -38,36 +46,18 @@ class QQBotAPI {
|
|
|
38
46
|
});
|
|
39
47
|
return createAxiosInstance(service, options);
|
|
40
48
|
}
|
|
41
|
-
guildServer(
|
|
42
|
-
|
|
43
|
-
const token = config.get('token');
|
|
44
|
-
const sandbox = config.get('sandbox');
|
|
45
|
-
const service = axios.create({
|
|
46
|
-
baseURL: sandbox ? API_URL_SANDBOX : API_URL,
|
|
47
|
-
timeout: 20000,
|
|
48
|
-
headers: {
|
|
49
|
-
Authorization: `Bot ${app_id}.${token}`
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return createAxiosInstance(service, opstion);
|
|
49
|
+
guildServer(options) {
|
|
50
|
+
return this.groupService(options);
|
|
53
51
|
}
|
|
54
52
|
gateway() {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
else if (mode === 'guild') {
|
|
62
|
-
return this.guildServer({
|
|
63
|
-
url: '/gateway'
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return this.groupService({
|
|
68
|
-
url: '/gateway'
|
|
69
|
-
});
|
|
53
|
+
const baseUrlGateway = config.get('base_url_gateway');
|
|
54
|
+
const params = {
|
|
55
|
+
url: '/gateway'
|
|
56
|
+
};
|
|
57
|
+
if (baseUrlGateway) {
|
|
58
|
+
params.baseURL = baseUrlGateway;
|
|
70
59
|
}
|
|
60
|
+
return this.groupService(params);
|
|
71
61
|
}
|
|
72
62
|
usersOpenMessages(openid, data) {
|
|
73
63
|
const db = {
|
|
@@ -518,25 +508,14 @@ class QQBotAPI {
|
|
|
518
508
|
url: `/guilds/${guild_id}/api_permission`
|
|
519
509
|
});
|
|
520
510
|
}
|
|
521
|
-
interactionResponse(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
return this.guildServer({
|
|
533
|
-
method: 'PUT',
|
|
534
|
-
url: `/interactions/${interaction_id}`,
|
|
535
|
-
data: {
|
|
536
|
-
code: code || 0
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
}
|
|
511
|
+
interactionResponse(_mode, interaction_id, code) {
|
|
512
|
+
return this.groupService({
|
|
513
|
+
method: 'PUT',
|
|
514
|
+
url: `/interactions/${interaction_id}`,
|
|
515
|
+
data: {
|
|
516
|
+
code: code || 0
|
|
517
|
+
}
|
|
518
|
+
});
|
|
540
519
|
}
|
|
541
520
|
}
|
|
542
521
|
|
package/lib/sdk/typing.d.ts
CHANGED
|
@@ -63,9 +63,10 @@ export interface Options {
|
|
|
63
63
|
intents?: IntentsEnum[];
|
|
64
64
|
is_private?: boolean;
|
|
65
65
|
sandbox?: boolean;
|
|
66
|
-
mode?: 'guild' | 'group' | '';
|
|
67
66
|
route?: string;
|
|
68
67
|
port?: string;
|
|
69
68
|
ws?: string;
|
|
70
69
|
gatewayURL?: string;
|
|
70
|
+
base_url_gateway?: string;
|
|
71
|
+
base_url_app_access_token?: string;
|
|
71
72
|
}
|