@alemonjs/discord 2.1.0-alpha.2 → 2.1.0-alpha.20
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 +16 -2
- package/lib/config.d.ts +14 -0
- package/lib/config.js +21 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +4 -12
- package/lib/hook.d.ts +27 -0
- package/lib/hook.js +14 -0
- package/lib/index.d.ts +6 -4
- package/lib/index.js +102 -134
- package/lib/sdk/api.d.ts +147 -971
- package/lib/sdk/api.js +336 -1076
- package/lib/sdk/createPicFrom.d.ts +6 -0
- package/lib/sdk/{core/from.js → createPicFrom.js} +8 -13
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +2 -0
- package/lib/sdk/intents.js +0 -121
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +5 -11
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.js +1 -0
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +42 -48
- package/lib/sdk/message/CHANNEL_UPDATE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +23 -28
- package/lib/sdk/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +12 -18
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +27 -33
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +113 -114
- package/lib/sdk/message/INTERACTION_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -59
- package/lib/sdk/message/MESSAGE_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +5 -11
- package/lib/sdk/message/MESSAGE_DELETE.js +1 -0
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +36 -42
- package/lib/sdk/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +50 -56
- package/lib/sdk/message/MESSAGE_UPDATE.js +1 -0
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +56 -68
- package/lib/sdk/message/PRESENCE_UPDATE.js +1 -0
- package/lib/sdk/message/READY.d.ts +7 -9
- package/lib/sdk/message/READY.js +1 -0
- package/lib/sdk/message/TYPING_START.d.ts +29 -35
- package/lib/sdk/message/TYPING_START.js +1 -0
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +5 -10
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.js +1 -0
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +36 -41
- package/lib/sdk/message/VOICE_STATE_UPDATE.js +1 -0
- package/lib/sdk/message.d.ts +93 -101
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/types.d.ts +2 -5
- package/lib/sdk/typings.d.ts +190 -0
- package/lib/sdk/typings.js +1 -0
- package/lib/sdk/wss.d.ts +7 -26
- package/lib/sdk/wss.js +109 -162
- package/lib/sdk/wss.types.d.ts +6 -29
- package/lib/sdk/wss.types.js +1 -0
- package/lib/send.d.ts +11 -0
- package/lib/send.js +168 -92
- package/package.json +16 -8
- package/lib/env.js +0 -1
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
type ComponentButton = {
|
|
2
|
+
type: number;
|
|
3
|
+
style: 2;
|
|
4
|
+
label?: string;
|
|
5
|
+
emoji?: any;
|
|
6
|
+
custom_id?: string;
|
|
7
|
+
sku_id?: any;
|
|
8
|
+
url?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type ComponentButtons = {
|
|
12
|
+
type: 1;
|
|
13
|
+
components: ComponentButton[];
|
|
14
|
+
};
|
|
15
|
+
type ComponentSelectsOption = {
|
|
16
|
+
label: string;
|
|
17
|
+
value: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
emoji?: {
|
|
20
|
+
name?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type ComponentChannelSelect = {
|
|
25
|
+
type: 8;
|
|
26
|
+
custom_id: string;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
channel_types?: number[];
|
|
29
|
+
};
|
|
30
|
+
type ComponentMentionSelect = {
|
|
31
|
+
type: 7;
|
|
32
|
+
custom_id: string;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
};
|
|
35
|
+
type ComponentRuleSelect = {
|
|
36
|
+
type: 6;
|
|
37
|
+
custom_id: string;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
max_values?: number;
|
|
40
|
+
min_values?: number;
|
|
41
|
+
};
|
|
42
|
+
type ComponentUserSelect = {
|
|
43
|
+
type: 5;
|
|
44
|
+
custom_id: string;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
};
|
|
47
|
+
type ComponentSelect = {
|
|
48
|
+
type: 3;
|
|
49
|
+
custom_id: string;
|
|
50
|
+
max_values?: number;
|
|
51
|
+
min_values?: number;
|
|
52
|
+
options: ComponentSelectsOption[];
|
|
53
|
+
};
|
|
54
|
+
type ComponentSelects = {
|
|
55
|
+
type: 1;
|
|
56
|
+
components: (ComponentSelect | ComponentUserSelect | ComponentRuleSelect | ComponentMentionSelect | ComponentChannelSelect)[];
|
|
57
|
+
};
|
|
58
|
+
type ComponentInput = {
|
|
59
|
+
id?: number;
|
|
60
|
+
type: 4;
|
|
61
|
+
custom_id: string;
|
|
62
|
+
label: string;
|
|
63
|
+
style: number;
|
|
64
|
+
min_length?: number;
|
|
65
|
+
max_length?: number;
|
|
66
|
+
placeholder?: string;
|
|
67
|
+
required?: boolean;
|
|
68
|
+
};
|
|
69
|
+
type ComponentModal = {
|
|
70
|
+
title: string;
|
|
71
|
+
custom_id: string;
|
|
72
|
+
components: {
|
|
73
|
+
type: 1;
|
|
74
|
+
components: ComponentInput[];
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
type ComponentText = {
|
|
78
|
+
type: 10;
|
|
79
|
+
content: string;
|
|
80
|
+
};
|
|
81
|
+
type ComponentSection = {
|
|
82
|
+
type: 9;
|
|
83
|
+
components: ComponentText[];
|
|
84
|
+
accessory?: {
|
|
85
|
+
type: 11;
|
|
86
|
+
media: {
|
|
87
|
+
url: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
type ComponentMedia = {
|
|
92
|
+
type: 12;
|
|
93
|
+
items: {
|
|
94
|
+
media: {
|
|
95
|
+
url: string;
|
|
96
|
+
};
|
|
97
|
+
description?: string;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
type ComponentFile = {
|
|
101
|
+
type: 13;
|
|
102
|
+
file: {
|
|
103
|
+
url: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
type ComponentSeparator = {
|
|
107
|
+
type: 14;
|
|
108
|
+
divider: boolean;
|
|
109
|
+
spacing: number;
|
|
110
|
+
};
|
|
111
|
+
type ComponentContainer = {
|
|
112
|
+
type: 17;
|
|
113
|
+
accent_color: number;
|
|
114
|
+
components: (ComponentButtons | ComponentSelects | ComponentMedia | ComponentFile | ComponentText | ComponentSection | ComponentSeparator)[];
|
|
115
|
+
};
|
|
116
|
+
export type MessageData = {
|
|
117
|
+
content?: string;
|
|
118
|
+
tts?: boolean;
|
|
119
|
+
embeds?: {
|
|
120
|
+
title?: string;
|
|
121
|
+
type?: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
url?: string;
|
|
124
|
+
timestamp?: string;
|
|
125
|
+
color?: number;
|
|
126
|
+
footer?: {
|
|
127
|
+
text: string;
|
|
128
|
+
icon_url?: string;
|
|
129
|
+
proxy_icon_url?: string;
|
|
130
|
+
};
|
|
131
|
+
image?: {
|
|
132
|
+
url: string;
|
|
133
|
+
proxy_url?: string;
|
|
134
|
+
height?: number;
|
|
135
|
+
width?: number;
|
|
136
|
+
};
|
|
137
|
+
thumbnail?: {
|
|
138
|
+
url: string;
|
|
139
|
+
proxy_url?: string;
|
|
140
|
+
height?: number;
|
|
141
|
+
width?: number;
|
|
142
|
+
};
|
|
143
|
+
video?: {
|
|
144
|
+
url: string;
|
|
145
|
+
proxy_url?: string;
|
|
146
|
+
height?: number;
|
|
147
|
+
width?: number;
|
|
148
|
+
};
|
|
149
|
+
provider?: {
|
|
150
|
+
name: string;
|
|
151
|
+
url: string;
|
|
152
|
+
};
|
|
153
|
+
author?: {
|
|
154
|
+
name: string;
|
|
155
|
+
url?: string;
|
|
156
|
+
icon_url?: string;
|
|
157
|
+
proxy_icon_url?: string;
|
|
158
|
+
};
|
|
159
|
+
fields?: {
|
|
160
|
+
name: string;
|
|
161
|
+
value: string;
|
|
162
|
+
inline?: boolean;
|
|
163
|
+
}[];
|
|
164
|
+
}[];
|
|
165
|
+
allowed_mentions?: any;
|
|
166
|
+
message_reference?: any;
|
|
167
|
+
components?: (ComponentButtons | ComponentSelects | ComponentModal | ComponentMedia | ComponentFile | ComponentText | ComponentSection | ComponentSeparator | ComponentContainer)[];
|
|
168
|
+
sticker_ids?: any;
|
|
169
|
+
files?: any[];
|
|
170
|
+
payload_json?: string;
|
|
171
|
+
attachments?: {
|
|
172
|
+
id: string;
|
|
173
|
+
filename: string;
|
|
174
|
+
description?: string;
|
|
175
|
+
content_type?: string;
|
|
176
|
+
size: number;
|
|
177
|
+
url: string;
|
|
178
|
+
proxy_url?: string;
|
|
179
|
+
height?: number;
|
|
180
|
+
width?: number;
|
|
181
|
+
ephemeral?: boolean;
|
|
182
|
+
duration_secs?: number;
|
|
183
|
+
waveform?: string;
|
|
184
|
+
flags?: number;
|
|
185
|
+
}[];
|
|
186
|
+
flags?: number;
|
|
187
|
+
enforce_nonce?: boolean;
|
|
188
|
+
poll?: any;
|
|
189
|
+
};
|
|
190
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/sdk/wss.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
import { DCAPI } from './api.js'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* 设置配置
|
|
9
|
-
* @param opstion
|
|
10
|
-
*/
|
|
11
|
-
constructor(opstion: DISOCRDOptions)
|
|
12
|
-
/**
|
|
13
|
-
* 注册事件处理程序
|
|
14
|
-
* @param key 事件名称
|
|
15
|
-
* @param val 事件处理函数
|
|
16
|
-
*/
|
|
17
|
-
on<T extends keyof DCEventMap>(key: T, val: (event: DCEventMap[T]) => any): this
|
|
18
|
-
/**
|
|
19
|
-
* 创建ws监听
|
|
20
|
-
* @param conversation
|
|
21
|
-
* @param shard
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
connect(gatewayURL?: string): Promise<void>
|
|
1
|
+
import { DCAPI } from './api.js';
|
|
2
|
+
import { DCEventMap } from './message.js';
|
|
3
|
+
export declare class DCClient extends DCAPI {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
on<T extends keyof DCEventMap>(key: T, val: (event: DCEventMap[T]) => any): this;
|
|
7
|
+
connect(): Promise<void>;
|
|
25
8
|
}
|
|
26
|
-
|
|
27
|
-
export { DCClient }
|
package/lib/sdk/wss.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
import { DCAPI } from './api.js';
|
|
3
|
-
import { config } from './config.js';
|
|
4
3
|
import { getIntents } from './intents.js';
|
|
4
|
+
import { getDiscordConfig } from '../config.js';
|
|
5
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
6
|
+
import { AvailableIntentsEventsEnum } from './types.js';
|
|
7
|
+
import dayjs from 'dayjs';
|
|
5
8
|
|
|
6
9
|
class DCClient extends DCAPI {
|
|
7
10
|
#heartbeat_interval = 0;
|
|
@@ -10,31 +13,21 @@ class DCClient extends DCAPI {
|
|
|
10
13
|
#timeout_id = null;
|
|
11
14
|
#seq = null;
|
|
12
15
|
#ws;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
constructor(opstion) {
|
|
16
|
+
#count = 0;
|
|
17
|
+
#events = {};
|
|
18
|
+
constructor() {
|
|
18
19
|
super();
|
|
19
|
-
config.set('intent', opstion.intent);
|
|
20
|
-
config.set('shard', opstion.shard);
|
|
21
|
-
config.set('token', opstion.token);
|
|
22
|
-
config.set('gatewayURL', opstion.gatewayURL);
|
|
23
20
|
return this;
|
|
24
21
|
}
|
|
25
|
-
/**
|
|
26
|
-
* 连接确认
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
22
|
#aut() {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
23
|
+
const value = getDiscordConfig();
|
|
24
|
+
const token = value.token;
|
|
25
|
+
const intent = value.intent || AvailableIntentsEventsEnum;
|
|
26
|
+
const shard = value.shard || [0, 1];
|
|
33
27
|
return {
|
|
34
28
|
op: 2,
|
|
35
29
|
d: {
|
|
36
30
|
shard: shard,
|
|
37
|
-
// 验证token
|
|
38
31
|
token: `Bot ${token}`,
|
|
39
32
|
intents: getIntents(intent),
|
|
40
33
|
properties: {
|
|
@@ -45,163 +38,117 @@ class DCClient extends DCAPI {
|
|
|
45
38
|
}
|
|
46
39
|
};
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// op: 6,
|
|
55
|
-
// d: {
|
|
56
|
-
// // 会话token
|
|
57
|
-
// token: token,
|
|
58
|
-
// session_id: this.#session_id,
|
|
59
|
-
// // 收到的最后一个序列号
|
|
60
|
-
// seq: this.#seq
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
63
|
-
// console.log('[ws] c', c)
|
|
64
|
-
// return c
|
|
65
|
-
// }
|
|
66
|
-
#events = {};
|
|
67
|
-
/**
|
|
68
|
-
* 注册事件处理程序
|
|
69
|
-
* @param key 事件名称
|
|
70
|
-
* @param val 事件处理函数
|
|
71
|
-
*/
|
|
41
|
+
#getReConnectTime() {
|
|
42
|
+
const time = this.#count > 3 ? 1000 * 6 : 1000 * 1;
|
|
43
|
+
const curTime = this.#count > 6 ? 1000 * this.#count * 2 : time;
|
|
44
|
+
logger.info(`[ws-discord] 等待 ${dayjs(curTime).format('mm:ss')} 后重新连接`);
|
|
45
|
+
return curTime;
|
|
46
|
+
}
|
|
72
47
|
on(key, val) {
|
|
73
48
|
this.#events[key] = val;
|
|
74
49
|
return this;
|
|
75
50
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
async connect(gatewayURL) {
|
|
83
|
-
// 清除序列号
|
|
51
|
+
async connect() {
|
|
52
|
+
this.#count++;
|
|
53
|
+
const value = getDiscordConfig();
|
|
54
|
+
const gatewayURL = value.gatewayURL;
|
|
84
55
|
this.#seq = null;
|
|
85
|
-
// 清除心跳
|
|
86
56
|
clearTimeout(this.#timeout_id);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
57
|
+
const gateway = async () => {
|
|
58
|
+
if (gatewayURL) {
|
|
59
|
+
return gatewayURL;
|
|
60
|
+
}
|
|
61
|
+
const currentGateway = await this.gateway()
|
|
90
62
|
.then(res => res?.url)
|
|
91
|
-
.catch(
|
|
92
|
-
|
|
93
|
-
this.#events['ERROR'](err?.message ?? err);
|
|
94
|
-
}));
|
|
95
|
-
// 没有网关
|
|
96
|
-
if (!url) {
|
|
97
|
-
console.error('[ws] 无法获取网关');
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* 心跳恢复
|
|
102
|
-
*/
|
|
103
|
-
const call = async () => {
|
|
104
|
-
this.#ws.send(JSON.stringify({
|
|
105
|
-
op: 1, // op = 1
|
|
106
|
-
d: this.#seq // 如果是第一次连接,传null
|
|
107
|
-
}));
|
|
108
|
-
// 确保清除
|
|
109
|
-
clearTimeout(this.#timeout_id);
|
|
110
|
-
// 开始心跳
|
|
111
|
-
this.#timeout_id = setTimeout(call, this.#heartbeat_interval);
|
|
63
|
+
.catch(() => null);
|
|
64
|
+
return currentGateway;
|
|
112
65
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
66
|
+
try {
|
|
67
|
+
const url = gatewayURL ?? (await gateway());
|
|
68
|
+
if (!url) {
|
|
69
|
+
logger.error('[ws-discord] 获取网关失败~');
|
|
70
|
+
const curTime = this.#getReConnectTime();
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
void this.connect();
|
|
73
|
+
}, curTime);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const call = () => {
|
|
77
|
+
this.#ws.send(JSON.stringify({
|
|
78
|
+
op: 1,
|
|
79
|
+
d: this.#seq
|
|
80
|
+
}));
|
|
81
|
+
clearTimeout(this.#timeout_id);
|
|
82
|
+
this.#timeout_id = setTimeout(call, this.#heartbeat_interval);
|
|
83
|
+
};
|
|
84
|
+
const map = {
|
|
85
|
+
0: ({ d, t, s }) => {
|
|
86
|
+
if (s) {
|
|
87
|
+
this.#seq = s;
|
|
132
88
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
await this.#events[t](d);
|
|
89
|
+
if (t === 'READY') {
|
|
90
|
+
if (d?.resume_gateway_url) {
|
|
91
|
+
this.#gateway_url = d?.resume_gateway_url;
|
|
92
|
+
logger.info('[ws-discord] gateway_url', this.#gateway_url);
|
|
93
|
+
}
|
|
94
|
+
if (d?.session_id) {
|
|
95
|
+
this.#session_id = d?.session_id;
|
|
96
|
+
logger.info('[ws-discord] session_id', this.#session_id);
|
|
97
|
+
}
|
|
143
98
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.#events[
|
|
99
|
+
if (this.#events[t]) {
|
|
100
|
+
try {
|
|
101
|
+
this.#events[t](d);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
logger.error('[ws-discord] 事件处理错误', err);
|
|
105
|
+
}
|
|
147
106
|
}
|
|
107
|
+
},
|
|
108
|
+
7: () => {
|
|
109
|
+
logger.info('[ws-discord] 重新连接');
|
|
110
|
+
},
|
|
111
|
+
9: ({ d }) => {
|
|
112
|
+
logger.error('[ws-discord] 无效会话', d);
|
|
113
|
+
},
|
|
114
|
+
10: ({ d }) => {
|
|
115
|
+
this.#heartbeat_interval = d.heartbeat_interval;
|
|
116
|
+
call();
|
|
117
|
+
this.#ws.send(JSON.stringify(this.#aut()));
|
|
118
|
+
},
|
|
119
|
+
11: () => {
|
|
120
|
+
logger.debug('[ws-discord] 心跳确认');
|
|
148
121
|
}
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*/
|
|
154
|
-
7: () => {
|
|
155
|
-
console.info('[ws] 重新连接');
|
|
156
|
-
// this.#ws.send(JSON.stringify(this.#reAut()))
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* 无效会话
|
|
160
|
-
* @param message
|
|
161
|
-
*/
|
|
162
|
-
9: ({ d }) => {
|
|
163
|
-
console.error('[ws] 无效会话 ', d);
|
|
164
|
-
},
|
|
165
|
-
/**
|
|
166
|
-
* 你好
|
|
167
|
-
* @param param0
|
|
168
|
-
*/
|
|
169
|
-
10: ({ d }) => {
|
|
170
|
-
// 得到心跳间隔
|
|
171
|
-
this.#heartbeat_interval = d.heartbeat_interval;
|
|
172
|
-
// 开始心跳
|
|
173
|
-
call();
|
|
174
|
-
// 开启会话
|
|
175
|
-
this.#ws.send(JSON.stringify(this.#aut()));
|
|
176
|
-
},
|
|
177
|
-
/**
|
|
178
|
-
* 心跳确认
|
|
179
|
-
*/
|
|
180
|
-
11: () => {
|
|
181
|
-
console.info('[ws] 心跳确认');
|
|
122
|
+
};
|
|
123
|
+
const ClientOptions = value.websocket_options || {};
|
|
124
|
+
if (value.websocket_proxy) {
|
|
125
|
+
ClientOptions.agent = new HttpsProxyAgent(value.websocket_proxy);
|
|
182
126
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
127
|
+
this.#ws = new WebSocket(`${url}?v=10&encoding=json`, ClientOptions);
|
|
128
|
+
this.#ws.on('open', () => {
|
|
129
|
+
logger.info('[ws-discord] 打开连接');
|
|
130
|
+
this.#count = 0;
|
|
131
|
+
});
|
|
132
|
+
this.#ws.on('message', data => {
|
|
133
|
+
const message = JSON.parse(data.toString());
|
|
134
|
+
if (map[message.op]) {
|
|
135
|
+
map[message.op](message);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.#ws.on('close', err => {
|
|
139
|
+
logger.info('[ws-discord] 连接关闭', err);
|
|
140
|
+
const curTime = this.#getReConnectTime();
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
void this.connect();
|
|
143
|
+
}, curTime);
|
|
144
|
+
});
|
|
145
|
+
this.#ws.on('error', err => {
|
|
146
|
+
logger.error('[ws-discord] 出错', err?.message || err);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
logger.error('[ws-discord] 内部错误', err);
|
|
151
|
+
}
|
|
205
152
|
}
|
|
206
153
|
}
|
|
207
154
|
|
package/lib/sdk/wss.types.d.ts
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import { DCIntentsEnum } from './types.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
interface DISOCRDOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 网关地址
|
|
11
|
-
*/
|
|
12
|
-
gatewayURL?: string
|
|
13
|
-
/**
|
|
14
|
-
* 钥匙
|
|
15
|
-
*/
|
|
16
|
-
token: string
|
|
17
|
-
/**
|
|
18
|
-
* 订阅(有默认值)
|
|
19
|
-
* ******
|
|
20
|
-
*/
|
|
21
|
-
intent?: DCIntentsEnum[]
|
|
22
|
-
/**
|
|
23
|
-
* 分片(有默认值)
|
|
24
|
-
* ******
|
|
25
|
-
* [0, 1]
|
|
26
|
-
*/
|
|
27
|
-
shard?: number[]
|
|
1
|
+
import { DCIntentsEnum } from './types.js';
|
|
2
|
+
export interface DISOCRDOptions {
|
|
3
|
+
gatewayURL?: string;
|
|
4
|
+
token: string;
|
|
5
|
+
intent?: DCIntentsEnum[];
|
|
6
|
+
shard?: number[];
|
|
28
7
|
}
|
|
29
|
-
|
|
30
|
-
export type { DISOCRDOptions }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/send.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataEnums } from 'alemonjs';
|
|
2
|
+
import { DCClient } from './sdk/wss';
|
|
3
|
+
type Client = typeof DCClient.prototype;
|
|
4
|
+
export declare const sendchannel: (client: Client, param: {
|
|
5
|
+
channel_id: string;
|
|
6
|
+
}, val: DataEnums[]) => Promise<import("alemonjs").Result<any>[]>;
|
|
7
|
+
export declare const senduser: (client: Client, param: {
|
|
8
|
+
author_id?: string;
|
|
9
|
+
channel_id?: string;
|
|
10
|
+
}, val: DataEnums[]) => Promise<import("alemonjs").Result<any>[]>;
|
|
11
|
+
export {};
|