@@ -14,6 +14,7 @@ import {
14
14
CompressTypes ,
15
15
EncodingTypes ,
16
16
GatewayDispatchEvents ,
17
+ GatewayIntents ,
17
18
GatewayOpCodes ,
18
19
GatewayPresenceStatuses ,
19
20
Package ,
@@ -75,6 +76,7 @@ export interface SocketOptions {
75
76
encoding ?: string ,
76
77
guildSubscriptions ?: boolean ,
77
78
identifyProperties ?: IdentifyDataProperties ,
79
+ intents ?: Array < number > | Array < string > | string | number ,
78
80
largeThreshold ?: number ,
79
81
presence ?: PresenceOptions ,
80
82
reconnectDelay ?: number ,
@@ -101,13 +103,14 @@ export class Socket extends EventSpewer {
101
103
} ;
102
104
autoReconnect : boolean ;
103
105
bucket : Bucket ;
104
- compress : string ;
106
+ compress : CompressTypes ;
105
107
disabledEvents : Array < string > ;
106
108
discordTrace : Array < any > = [ ] ;
107
109
decompressor : Decompressor | null ;
108
- encoding : string ;
110
+ encoding : EncodingTypes ;
109
111
guildSubscriptions : boolean ;
110
112
identifyProperties : IdentifyDataProperties = Object . assign ( { } , IdentifyProperties ) ;
113
+ intents ?: number ;
111
114
killed : boolean = false ;
112
115
largeThreshold : number ;
113
116
mediaGateways = new BaseCollection < string , MediaSocket > ( ) ;
@@ -141,10 +144,10 @@ export class Socket extends EventSpewer {
141
144
options . compress = CompressTypes . NONE ;
142
145
}
143
146
}
144
-
147
+
145
148
this . autoReconnect = ! ! options . autoReconnect ;
146
- this . compress = ( < string > options . compress ) . toLowerCase ( ) ;
147
- this . encoding = ( < string > options . encoding ) . toLowerCase ( ) ;
149
+ this . compress = < CompressTypes > ( < string > options . compress ) . toLowerCase ( ) ;
150
+ this . encoding = < EncodingTypes > ( < string > options . encoding ) . toLowerCase ( ) ;
148
151
this . disabledEvents = < Array < string > > options . disabledEvents ;
149
152
this . guildSubscriptions = ! ! options . guildSubscriptions ;
150
153
this . largeThreshold = < number > options . largeThreshold ;
@@ -198,6 +201,24 @@ export class Socket extends EventSpewer {
198
201
} ;
199
202
}
200
203
204
+ if ( options . intents !== undefined ) {
205
+ this . intents = 0 ;
206
+
207
+ const intents = ( Array . isArray ( options . intents ) ) ? options . intents : [ options . intents ] ;
208
+ for ( let intent of intents ) {
209
+ if ( typeof ( intent ) === 'string' ) {
210
+ intent = intent . toUpperCase ( ) ;
211
+ if ( intent in GatewayIntents ) {
212
+ this . intents |= ( < any > GatewayIntents ) [ intent ] ;
213
+ }
214
+ } else if ( typeof ( intent ) === 'number' ) {
215
+ this . intents |= intent ;
216
+ } else {
217
+ throw new Error ( `Invalid intent received: ${ intent } ` ) ;
218
+ }
219
+ }
220
+ }
221
+
201
222
Object . defineProperties ( this , {
202
223
_heartbeat : { enumerable : false , writable : false } ,
203
224
identifyProperties : { enumerable : false } ,
@@ -259,6 +280,7 @@ export class Socket extends EventSpewer {
259
280
metadata : activity . metadata ,
260
281
name : activity . name ,
261
282
party : undefined ,
283
+ platform : activity . platform ,
262
284
secrets : undefined ,
263
285
session_id : activity . sessionId ,
264
286
state : activity . state ,
@@ -313,6 +335,7 @@ export class Socket extends EventSpewer {
313
335
/* payload compression, rather use transport compression, using the get params overrides this */
314
336
compress : ( this . compress === CompressTypes . PAYLOAD ) ,
315
337
guild_subscriptions : this . guildSubscriptions ,
338
+ intents : this . intents ,
316
339
large_threshold : this . largeThreshold ,
317
340
properties : this . identifyProperties ,
318
341
token : this . token ,
@@ -440,13 +463,8 @@ export class Socket extends EventSpewer {
440
463
) : void {
441
464
const packet = this . decode ( data , uncompressed ) ;
442
465
if ( ! packet ) { return ; }
443
- if ( packet . s ) {
444
- const oldSequence = this . sequence ;
445
- const newSequence = packet . s ;
446
- if ( oldSequence + 1 < newSequence && ! this . resuming ) {
447
- return this . resume ( ) ;
448
- }
449
- this . sequence = newSequence ;
466
+ if ( packet . s !== null ) {
467
+ this . sequence = packet . s ;
450
468
}
451
469
452
470
switch ( packet . op ) {
@@ -726,15 +744,6 @@ export class Socket extends EventSpewer {
726
744
} , callback ) ;
727
745
}
728
746
729
- flushLfgSubscriptions (
730
- subscriptions : any ,
731
- callback ?: Function ,
732
- ) : void {
733
- this . send ( GatewayOpCodes . FLUSH_LFG_SUBSCRIPTIONS , {
734
- subscriptions,
735
- } , callback ) ;
736
- }
737
-
738
747
guildStreamCreate (
739
748
guildId : string ,
740
749
channelId : string ,
@@ -876,6 +885,7 @@ export class Socket extends EventSpewer {
876
885
guildId : null | string = null ,
877
886
channelId : null | string = null ,
878
887
options : {
888
+ preferredRegion ?: string ,
879
889
selfDeaf ?: boolean ,
880
890
selfMute ?: boolean ,
881
891
selfVideo ?: boolean ,
@@ -885,6 +895,7 @@ export class Socket extends EventSpewer {
885
895
this . send ( GatewayOpCodes . VOICE_STATE_UPDATE , {
886
896
channel_id : channelId ,
887
897
guild_id : guildId ,
898
+ preferred_region : options . preferredRegion ,
888
899
self_deaf : options . selfDeaf ,
889
900
self_mute : options . selfMute ,
890
901
self_video : options . selfVideo ,
@@ -990,6 +1001,7 @@ export interface GatewayPacket {
990
1001
export interface IdentifyData {
991
1002
compress ?: boolean ,
992
1003
guild_subscriptions ?: boolean ,
1004
+ intents ?: number ,
993
1005
large_threshold ?: number ,
994
1006
presence ?: RawPresence ,
995
1007
properties : IdentifyDataProperties ,
@@ -1038,6 +1050,7 @@ export interface RawPresenceActivity {
1038
1050
id ?: string ,
1039
1051
size ?: Array < [ number , number ] > ,
1040
1052
} ,
1053
+ platform ?: string ,
1041
1054
secrets ?: {
1042
1055
join ?: string ,
1043
1056
match ?: string ,
@@ -1089,6 +1102,7 @@ export interface PresenceActivityOptions {
1089
1102
id ?: string ,
1090
1103
size ?: Array < [ number , number ] > ,
1091
1104
} ,
1105
+ platform ?: string ,
1092
1106
secrets ?: {
1093
1107
join ?: string ,
1094
1108
match ?: string ,
0 commit comments