@alemonjs/onebot 2.1.0-alpha.12 → 2.1.0-alpha.14
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/lib/config.js +3 -3
- package/lib/index.js +4 -4
- package/lib/sdk/api.d.ts +99 -7
- package/lib/sdk/api.js +288 -39
- package/lib/sdk/config.d.ts +4 -2
- package/lib/sdk/types.d.ts +2 -2
- package/lib/sdk/typing.d.ts +2 -2
- package/lib/sdk/wss.js +8 -8
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -7,13 +7,13 @@ const getOneBotConfig = () => {
|
|
|
7
7
|
};
|
|
8
8
|
const getMaster = (UserId) => {
|
|
9
9
|
const config = getOneBotConfig();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const masterKey = config.master_key || [];
|
|
11
|
+
const masterId = config.master_id || [];
|
|
12
12
|
const UserKey = useUserHashKey({
|
|
13
13
|
Platform: platform,
|
|
14
14
|
UserId: UserId
|
|
15
15
|
});
|
|
16
|
-
const is =
|
|
16
|
+
const is = masterKey.includes(UserKey) || masterId.includes(UserId);
|
|
17
17
|
return [is, UserKey];
|
|
18
18
|
};
|
|
19
19
|
|
package/lib/index.js
CHANGED
|
@@ -42,7 +42,7 @@ const main = () => {
|
|
|
42
42
|
const UserAvatar = createUserAvatar(UserId);
|
|
43
43
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
44
44
|
const groupId = String(event.group_id);
|
|
45
|
-
const
|
|
45
|
+
const replyId = event.message.find(item => item.type === 'reply')?.data?.id;
|
|
46
46
|
const e = {
|
|
47
47
|
name: 'message.create',
|
|
48
48
|
Platform: platform,
|
|
@@ -58,7 +58,7 @@ const main = () => {
|
|
|
58
58
|
MessageId: String(event.message_id),
|
|
59
59
|
MessageText: msg.trim(),
|
|
60
60
|
OpenId: UserId,
|
|
61
|
-
|
|
61
|
+
replyId,
|
|
62
62
|
CreateAt: Date.now(),
|
|
63
63
|
tag: 'message.create',
|
|
64
64
|
value: event
|
|
@@ -70,7 +70,7 @@ const main = () => {
|
|
|
70
70
|
const UserId = String(event.user_id);
|
|
71
71
|
const UserAvatar = createUserAvatar(UserId);
|
|
72
72
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
73
|
-
const
|
|
73
|
+
const replyId = event.message.find(item => item.type === 'reply')?.data?.id;
|
|
74
74
|
const e = {
|
|
75
75
|
name: 'private.message.create',
|
|
76
76
|
Platform: platform,
|
|
@@ -84,7 +84,7 @@ const main = () => {
|
|
|
84
84
|
MessageText: msg.trim(),
|
|
85
85
|
OpenId: String(event.user_id),
|
|
86
86
|
CreateAt: Date.now(),
|
|
87
|
-
|
|
87
|
+
replyId,
|
|
88
88
|
tag: 'private.message.create',
|
|
89
89
|
value: event
|
|
90
90
|
};
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
export declare const consume: (parsedMessage: any) => void;
|
|
3
3
|
export declare class OneBotAPI {
|
|
4
|
-
|
|
4
|
+
__ws: WebSocket | null;
|
|
5
|
+
send(options: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}): Promise<any>;
|
|
5
8
|
sendPrivateMessage(options: {
|
|
6
9
|
user_id: number;
|
|
7
10
|
message: any[];
|
|
@@ -16,14 +19,68 @@ export declare class OneBotAPI {
|
|
|
16
19
|
user_id?: number;
|
|
17
20
|
message: any[];
|
|
18
21
|
}): Promise<any>;
|
|
19
|
-
|
|
22
|
+
deleteMsg(options: {
|
|
23
|
+
message_id: number;
|
|
24
|
+
}): Promise<any>;
|
|
20
25
|
getMsg(options: {
|
|
21
26
|
message_id: number;
|
|
22
27
|
}): Promise<any>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
getForwardMsg(options: {
|
|
29
|
+
id: string;
|
|
30
|
+
}): Promise<any>;
|
|
31
|
+
sendLike(options: {
|
|
32
|
+
user_id: number;
|
|
33
|
+
times?: number;
|
|
34
|
+
}): Promise<any>;
|
|
35
|
+
setGroupKick(options: {
|
|
36
|
+
group_id: number;
|
|
37
|
+
user_id: number;
|
|
38
|
+
reject_add_request?: boolean;
|
|
39
|
+
}): Promise<any>;
|
|
40
|
+
setGroupBan(options: {
|
|
41
|
+
group_id: number;
|
|
42
|
+
user_id: number;
|
|
43
|
+
duration: number;
|
|
44
|
+
}): Promise<any>;
|
|
45
|
+
setGroupAnonymousBan(options: {
|
|
46
|
+
group_id: number;
|
|
47
|
+
anonymous: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
};
|
|
51
|
+
duration: number;
|
|
52
|
+
}): Promise<any>;
|
|
53
|
+
setGroupWholeBan(options: {
|
|
54
|
+
group_id: number;
|
|
55
|
+
enable: boolean;
|
|
56
|
+
}): Promise<any>;
|
|
57
|
+
setGroupAdmin(options: {
|
|
58
|
+
group_id: number;
|
|
59
|
+
user_id: number;
|
|
60
|
+
enable: boolean;
|
|
61
|
+
}): Promise<any>;
|
|
62
|
+
setGroupAnonymous(options: {
|
|
63
|
+
group_id: number;
|
|
64
|
+
enable: boolean;
|
|
65
|
+
}): Promise<any>;
|
|
66
|
+
setGroupCard(options: {
|
|
67
|
+
group_id: number;
|
|
68
|
+
user_id: number;
|
|
69
|
+
card: string;
|
|
70
|
+
}): Promise<any>;
|
|
71
|
+
setGroupName(options: {
|
|
72
|
+
group_id: number;
|
|
73
|
+
group_name: string;
|
|
74
|
+
}): Promise<any>;
|
|
75
|
+
setGroupLeave(options: {
|
|
26
76
|
group_id: number;
|
|
77
|
+
is_dismiss?: boolean;
|
|
78
|
+
}): Promise<any>;
|
|
79
|
+
setGroupSpecialTitle(options: {
|
|
80
|
+
group_id: number;
|
|
81
|
+
user_id: number;
|
|
82
|
+
special_title: string;
|
|
83
|
+
duration: number;
|
|
27
84
|
}): Promise<any>;
|
|
28
85
|
setFriendAddRequest(options: {
|
|
29
86
|
flag: string;
|
|
@@ -36,9 +93,44 @@ export declare class OneBotAPI {
|
|
|
36
93
|
approve: boolean;
|
|
37
94
|
reason?: string;
|
|
38
95
|
}): Promise<any>;
|
|
39
|
-
|
|
40
|
-
|
|
96
|
+
getLoginInfo(): Promise<any>;
|
|
97
|
+
getStrangerInfo(options: {
|
|
98
|
+
user_id: number;
|
|
99
|
+
no_cache?: boolean;
|
|
100
|
+
}): Promise<any>;
|
|
101
|
+
getFriendList(): Promise<any>;
|
|
102
|
+
getGroupInfo(params?: {
|
|
103
|
+
group_id: number;
|
|
104
|
+
no_cache?: boolean;
|
|
105
|
+
}): Promise<any>;
|
|
106
|
+
getGroupList(): Promise<any>;
|
|
107
|
+
getGroupMemberInfo(options: {
|
|
108
|
+
group_id: number;
|
|
109
|
+
user_id: number;
|
|
110
|
+
no_cache?: boolean;
|
|
111
|
+
}): Promise<any>;
|
|
112
|
+
getGroupMemberList(options: {
|
|
113
|
+
group_id: number;
|
|
114
|
+
}): Promise<any>;
|
|
115
|
+
getGroupHonorInfo(options: {
|
|
116
|
+
group_id: number;
|
|
117
|
+
type: 'talkative' | 'performer' | 'legend' | 'strong_newbie';
|
|
118
|
+
}): Promise<any>;
|
|
119
|
+
getCookies(): Promise<any>;
|
|
120
|
+
getCsrfToken(): Promise<any>;
|
|
121
|
+
getCredentials(): Promise<any>;
|
|
122
|
+
getRecord(options: {
|
|
123
|
+
file: string;
|
|
124
|
+
}): Promise<any>;
|
|
125
|
+
getImage(options: {
|
|
126
|
+
file: string;
|
|
41
127
|
}): Promise<any>;
|
|
128
|
+
canSendImage(): Promise<any>;
|
|
129
|
+
canSendRecord(): Promise<any>;
|
|
130
|
+
getStatus(): Promise<any>;
|
|
131
|
+
getVersionInfo(): Promise<any>;
|
|
132
|
+
setRestart(): Promise<any>;
|
|
133
|
+
cleanCache(): Promise<any>;
|
|
42
134
|
uploadPrivateFile(options: {
|
|
43
135
|
user_id: number;
|
|
44
136
|
file: string;
|
package/lib/sdk/api.js
CHANGED
|
@@ -36,129 +36,378 @@ const consume = (parsedMessage) => {
|
|
|
36
36
|
resolve(parsedMessage?.data);
|
|
37
37
|
};
|
|
38
38
|
class OneBotAPI {
|
|
39
|
-
|
|
39
|
+
__ws = null;
|
|
40
|
+
send(options) {
|
|
41
|
+
if (!this.__ws) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return send(this.__ws, options);
|
|
45
|
+
}
|
|
40
46
|
sendPrivateMessage(options) {
|
|
41
|
-
if (!this.
|
|
47
|
+
if (!this.__ws) {
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
44
|
-
return send(this.
|
|
50
|
+
return send(this.__ws, {
|
|
45
51
|
action: 'send_private_msg',
|
|
46
52
|
params: options
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
55
|
sendGroupMessage(options) {
|
|
50
|
-
if (!this.
|
|
56
|
+
if (!this.__ws) {
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
53
|
-
return send(this.
|
|
59
|
+
return send(this.__ws, {
|
|
54
60
|
action: 'send_group_msg',
|
|
55
61
|
params: options
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
sendMessage(options) {
|
|
59
|
-
if (!this.
|
|
65
|
+
if (!this.__ws) {
|
|
60
66
|
return;
|
|
61
67
|
}
|
|
62
|
-
return send(this.
|
|
68
|
+
return send(this.__ws, {
|
|
63
69
|
action: 'send_msg',
|
|
64
70
|
params: options
|
|
65
71
|
});
|
|
66
72
|
}
|
|
73
|
+
deleteMsg(options) {
|
|
74
|
+
if (!this.__ws) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return send(this.__ws, {
|
|
78
|
+
action: 'delete_msg',
|
|
79
|
+
params: options
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getMsg(options) {
|
|
83
|
+
if (!this.__ws) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return send(this.__ws, {
|
|
87
|
+
action: 'get_msg',
|
|
88
|
+
params: options
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getForwardMsg(options) {
|
|
92
|
+
if (!this.__ws) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
return send(this.__ws, {
|
|
96
|
+
action: 'get_forward_msg',
|
|
97
|
+
params: options
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
sendLike(options) {
|
|
101
|
+
if (!this.__ws) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return send(this.__ws, {
|
|
105
|
+
action: 'send_like',
|
|
106
|
+
params: options
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
setGroupKick(options) {
|
|
110
|
+
if (!this.__ws) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
return send(this.__ws, {
|
|
114
|
+
action: 'set_group_kick',
|
|
115
|
+
params: options
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
setGroupBan(options) {
|
|
119
|
+
if (!this.__ws) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return send(this.__ws, {
|
|
123
|
+
action: 'set_group_ban',
|
|
124
|
+
params: options
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
setGroupAnonymousBan(options) {
|
|
128
|
+
if (!this.__ws) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
return send(this.__ws, {
|
|
132
|
+
action: 'set_group_anonymous_ban',
|
|
133
|
+
params: options
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
setGroupWholeBan(options) {
|
|
137
|
+
if (!this.__ws) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return send(this.__ws, {
|
|
141
|
+
action: 'set_group_whole_ban',
|
|
142
|
+
params: options
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
setGroupAdmin(options) {
|
|
146
|
+
if (!this.__ws) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
return send(this.__ws, {
|
|
150
|
+
action: 'set_group_admin',
|
|
151
|
+
params: options
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
setGroupAnonymous(options) {
|
|
155
|
+
if (!this.__ws) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
return send(this.__ws, {
|
|
159
|
+
action: 'set_group_anonymous',
|
|
160
|
+
params: options
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
setGroupCard(options) {
|
|
164
|
+
if (!this.__ws) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
return send(this.__ws, {
|
|
168
|
+
action: 'set_group_card',
|
|
169
|
+
params: options
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
setGroupName(options) {
|
|
173
|
+
if (!this.__ws) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
return send(this.__ws, {
|
|
177
|
+
action: 'set_group_name',
|
|
178
|
+
params: options
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
setGroupLeave(options) {
|
|
182
|
+
if (!this.__ws) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
return send(this.__ws, {
|
|
186
|
+
action: 'set_group_leave',
|
|
187
|
+
params: options
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
setGroupSpecialTitle(options) {
|
|
191
|
+
if (!this.__ws) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
return send(this.__ws, {
|
|
195
|
+
action: 'set_group_special_title',
|
|
196
|
+
params: options
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
setFriendAddRequest(options) {
|
|
200
|
+
if (!this.__ws) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
return send(this.__ws, {
|
|
204
|
+
action: 'set_friend_add_request',
|
|
205
|
+
params: options
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
setGroupAddRequest(options) {
|
|
209
|
+
if (!this.__ws) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
return send(this.__ws, {
|
|
213
|
+
action: 'set_group_add_request',
|
|
214
|
+
params: options
|
|
215
|
+
});
|
|
216
|
+
}
|
|
67
217
|
getLoginInfo() {
|
|
68
|
-
if (!this.
|
|
218
|
+
if (!this.__ws) {
|
|
69
219
|
return;
|
|
70
220
|
}
|
|
71
|
-
return send(this.
|
|
221
|
+
return send(this.__ws, {
|
|
72
222
|
action: 'get_login_info',
|
|
73
223
|
params: {}
|
|
74
224
|
});
|
|
75
225
|
}
|
|
76
|
-
|
|
77
|
-
if (!this.
|
|
226
|
+
getStrangerInfo(options) {
|
|
227
|
+
if (!this.__ws) {
|
|
78
228
|
return;
|
|
79
229
|
}
|
|
80
|
-
return send(this.
|
|
81
|
-
action: '
|
|
230
|
+
return send(this.__ws, {
|
|
231
|
+
action: 'get_stranger_info',
|
|
82
232
|
params: options
|
|
83
233
|
});
|
|
84
234
|
}
|
|
85
235
|
getFriendList() {
|
|
86
|
-
if (!this.
|
|
236
|
+
if (!this.__ws) {
|
|
87
237
|
return;
|
|
88
238
|
}
|
|
89
|
-
return send(this.
|
|
239
|
+
return send(this.__ws, {
|
|
90
240
|
action: 'get_friend_list',
|
|
91
241
|
params: {}
|
|
92
242
|
});
|
|
93
243
|
}
|
|
244
|
+
getGroupInfo(params) {
|
|
245
|
+
if (!this.__ws) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
return send(this.__ws, {
|
|
249
|
+
action: 'get_group_info',
|
|
250
|
+
params: params
|
|
251
|
+
});
|
|
252
|
+
}
|
|
94
253
|
getGroupList() {
|
|
95
|
-
if (!this.
|
|
254
|
+
if (!this.__ws) {
|
|
96
255
|
return;
|
|
97
256
|
}
|
|
98
|
-
return send(this.
|
|
257
|
+
return send(this.__ws, {
|
|
99
258
|
action: 'get_group_list',
|
|
100
259
|
params: {}
|
|
101
260
|
});
|
|
102
261
|
}
|
|
262
|
+
getGroupMemberInfo(options) {
|
|
263
|
+
if (!this.__ws) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
return send(this.__ws, {
|
|
267
|
+
action: 'get_group_member_info',
|
|
268
|
+
params: options
|
|
269
|
+
});
|
|
270
|
+
}
|
|
103
271
|
getGroupMemberList(options) {
|
|
104
|
-
if (!this.
|
|
272
|
+
if (!this.__ws) {
|
|
105
273
|
return;
|
|
106
274
|
}
|
|
107
|
-
return send(this.
|
|
275
|
+
return send(this.__ws, {
|
|
108
276
|
action: 'get_group_member_list',
|
|
109
277
|
params: options
|
|
110
278
|
});
|
|
111
279
|
}
|
|
112
|
-
|
|
113
|
-
if (!this.
|
|
280
|
+
getGroupHonorInfo(options) {
|
|
281
|
+
if (!this.__ws) {
|
|
114
282
|
return;
|
|
115
283
|
}
|
|
116
|
-
return send(this.
|
|
117
|
-
action: '
|
|
284
|
+
return send(this.__ws, {
|
|
285
|
+
action: 'get_group_honor_info',
|
|
118
286
|
params: options
|
|
119
287
|
});
|
|
120
288
|
}
|
|
121
|
-
|
|
122
|
-
if (!this.
|
|
289
|
+
getCookies() {
|
|
290
|
+
if (!this.__ws) {
|
|
123
291
|
return;
|
|
124
292
|
}
|
|
125
|
-
return send(this.
|
|
126
|
-
action: '
|
|
293
|
+
return send(this.__ws, {
|
|
294
|
+
action: 'get_cookies',
|
|
295
|
+
params: {}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
getCsrfToken() {
|
|
299
|
+
if (!this.__ws) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
return send(this.__ws, {
|
|
303
|
+
action: 'get_csrf_token',
|
|
304
|
+
params: {}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
getCredentials() {
|
|
308
|
+
if (!this.__ws) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
return send(this.__ws, {
|
|
312
|
+
action: 'get_credentials',
|
|
313
|
+
params: {}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
getRecord(options) {
|
|
317
|
+
if (!this.__ws) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
return send(this.__ws, {
|
|
321
|
+
action: 'get_record',
|
|
127
322
|
params: options
|
|
128
323
|
});
|
|
129
324
|
}
|
|
130
|
-
|
|
131
|
-
if (!this.
|
|
325
|
+
getImage(options) {
|
|
326
|
+
if (!this.__ws) {
|
|
132
327
|
return;
|
|
133
328
|
}
|
|
134
|
-
return send(this.
|
|
135
|
-
action: '
|
|
329
|
+
return send(this.__ws, {
|
|
330
|
+
action: 'get_image',
|
|
136
331
|
params: options
|
|
137
332
|
});
|
|
138
333
|
}
|
|
334
|
+
canSendImage() {
|
|
335
|
+
if (!this.__ws) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
return send(this.__ws, {
|
|
339
|
+
action: 'can_send_image',
|
|
340
|
+
params: {}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
canSendRecord() {
|
|
344
|
+
if (!this.__ws) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
return send(this.__ws, {
|
|
348
|
+
action: 'can_send_record',
|
|
349
|
+
params: {}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
getStatus() {
|
|
353
|
+
if (!this.__ws) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
return send(this.__ws, {
|
|
357
|
+
action: 'get_status',
|
|
358
|
+
params: {}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
getVersionInfo() {
|
|
362
|
+
if (!this.__ws) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
return send(this.__ws, {
|
|
366
|
+
action: 'get_version_info',
|
|
367
|
+
params: {}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
setRestart() {
|
|
371
|
+
if (!this.__ws) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
return send(this.__ws, {
|
|
375
|
+
action: 'set_restart',
|
|
376
|
+
params: {}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
cleanCache() {
|
|
380
|
+
if (!this.__ws) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
return send(this.__ws, {
|
|
384
|
+
action: 'clean_cache',
|
|
385
|
+
params: {}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
139
388
|
uploadPrivateFile(options) {
|
|
140
|
-
if (!this.
|
|
389
|
+
if (!this.__ws) {
|
|
141
390
|
return;
|
|
142
391
|
}
|
|
143
|
-
return send(this.
|
|
392
|
+
return send(this.__ws, {
|
|
144
393
|
action: 'upload_private_file',
|
|
145
394
|
params: options
|
|
146
395
|
});
|
|
147
396
|
}
|
|
148
397
|
uploadGroupFile(options) {
|
|
149
|
-
if (!this.
|
|
398
|
+
if (!this.__ws) {
|
|
150
399
|
return;
|
|
151
400
|
}
|
|
152
|
-
return send(this.
|
|
401
|
+
return send(this.__ws, {
|
|
153
402
|
action: 'upload_group_file',
|
|
154
403
|
params: options
|
|
155
404
|
});
|
|
156
405
|
}
|
|
157
406
|
sendPrivateForward(options) {
|
|
158
|
-
if (!this.
|
|
407
|
+
if (!this.__ws) {
|
|
159
408
|
return;
|
|
160
409
|
}
|
|
161
|
-
return send(this.
|
|
410
|
+
return send(this.__ws, {
|
|
162
411
|
action: 'send_private_forward_msg',
|
|
163
412
|
params: {
|
|
164
413
|
user_id: 80000000,
|
|
@@ -169,10 +418,10 @@ class OneBotAPI {
|
|
|
169
418
|
});
|
|
170
419
|
}
|
|
171
420
|
sendGroupForward(options) {
|
|
172
|
-
if (!this.
|
|
421
|
+
if (!this.__ws) {
|
|
173
422
|
return;
|
|
174
423
|
}
|
|
175
|
-
return send(this.
|
|
424
|
+
return send(this.__ws, {
|
|
176
425
|
action: 'send_group_forward_msg',
|
|
177
426
|
params: {
|
|
178
427
|
user_id: 80000000,
|
package/lib/sdk/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
type PromiseHandlers = {
|
|
2
2
|
resolve: (value: any) => void;
|
|
3
3
|
reject: (reason?: any) => void;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
export declare const actionResolves: Map<string, PromiseHandlers>;
|
|
5
6
|
export declare const actionTimeouts: Map<string, NodeJS.Timeout>;
|
|
6
7
|
export declare const generateUniqueId: () => string;
|
|
7
8
|
export declare const timeoutTime: number;
|
|
9
|
+
export {};
|
package/lib/sdk/types.d.ts
CHANGED
|
@@ -73,14 +73,14 @@ export interface DIRECT_MESSAGE_TYPE {
|
|
|
73
73
|
group_id: number;
|
|
74
74
|
temp_source: number;
|
|
75
75
|
}
|
|
76
|
-
export interface
|
|
76
|
+
export interface META_EVENT_LIFECYCLE {
|
|
77
77
|
time: number;
|
|
78
78
|
self_id: number;
|
|
79
79
|
post_type: 'meta_event';
|
|
80
80
|
meta_event_type: 'lifecycle';
|
|
81
81
|
sub_type: 'connect';
|
|
82
82
|
}
|
|
83
|
-
export interface
|
|
83
|
+
export interface META_EVENT_HEARTBEAT {
|
|
84
84
|
time: number;
|
|
85
85
|
self_id: number;
|
|
86
86
|
post_type: 'meta_event';
|
package/lib/sdk/typing.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE,
|
|
1
|
+
import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE, META_EVENT_LIFECYCLE, META_EVENT_HEARTBEAT } from './types';
|
|
2
2
|
export type OneBotEventMap = {
|
|
3
3
|
DIRECT_MESSAGE: DIRECT_MESSAGE_TYPE;
|
|
4
4
|
MESSAGES: MESSAGES_TYPE;
|
|
5
|
-
META:
|
|
5
|
+
META: META_EVENT_LIFECYCLE | META_EVENT_HEARTBEAT;
|
|
6
6
|
REQUEST_ADD_FRIEND: any;
|
|
7
7
|
REQUEST_ADD_GROUP: any;
|
|
8
8
|
NOTICE_GROUP_MEMBER_INCREASE: any;
|
package/lib/sdk/wss.js
CHANGED
|
@@ -105,24 +105,24 @@ class OneBotClient extends OneBotAPI {
|
|
|
105
105
|
this.connect();
|
|
106
106
|
}, curTime);
|
|
107
107
|
};
|
|
108
|
-
if (!this.
|
|
108
|
+
if (!this.__ws) {
|
|
109
109
|
if (reverse_enable) {
|
|
110
110
|
const server = new WebSocketServer({ port: reverse_port ?? 17158 });
|
|
111
111
|
server.on('connection', ws => {
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
112
|
+
this.__ws = ws;
|
|
113
|
+
this.__ws.on('message', onMessage);
|
|
114
|
+
this.__ws.on('close', onClose);
|
|
115
115
|
logger.info(`[OneBot] connected: ws://127.0.0.1:${reverse_port}`);
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
119
|
+
this.__ws = new WebSocket(url, c);
|
|
120
|
+
this.__ws.on('open', () => {
|
|
121
121
|
logger.info(`[OneBot] connected: ${url}`);
|
|
122
122
|
this.#count = 0;
|
|
123
123
|
});
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
124
|
+
this.__ws.on('message', onMessage);
|
|
125
|
+
this.__ws.on('close', onClose);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|