Beispiel #1
0
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, GatewayIntents?gatewayIntents = null, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var props = new Dictionary <string, string>
            {
                ["$device"] = "Discord.Net"
            };
            var msg = new IdentifyParams()
            {
                Token          = AuthToken,
                Properties     = props,
                LargeThreshold = largeThreshold
            };

            if (totalShards > 1)
            {
                msg.ShardingParams = new int[] { shardID, totalShards }
            }
            ;

            options.BucketId = GatewayBucket.Get(GatewayBucketType.Identify).Id;

            if (gatewayIntents.HasValue)
            {
                msg.Intents = (int)gatewayIntents.Value;
            }
            else
            {
                msg.GuildSubscriptions = guildSubscriptions;
            }

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options : options).ConfigureAwait(false);
        }
Beispiel #2
0
        private async Task SendGatewayInternalAsync(GatewayOpCode opCode, object payload, RequestOptions options)
        {
            CheckState();

            //TODO: Add ETF
            byte[] bytes = null;
            payload = new SocketFrame {
                Operation = (int)opCode, Payload = payload
            };
            if (payload != null)
            {
                bytes = Encoding.UTF8.GetBytes(SerializeJson(payload));
            }

            options.IsGatewayBucket = true;
            if (options.BucketId == null)
            {
                options.BucketId = GatewayBucket.Get(GatewayBucketType.Unbucketed).Id;
            }
            await RequestQueue.SendAsync(new WebSocketRequest(WebSocketClient, bytes, true, opCode == GatewayOpCode.Heartbeat, options)).ConfigureAwait(false);

            await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false);

#if DEBUG_PACKETS
            Console.WriteLine($"-> {opCode}:\n{SerializeJson(payload)}");
#endif
        }
Beispiel #3
0
        public async Task SendStatusUpdateAsync(UserStatus status, bool isAFK, long?since, Game game, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var args = new StatusUpdateParams
            {
                Status    = status,
                IdleSince = since,
                IsAFK     = isAFK,
                Game      = game
            };

            options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id;
            await SendGatewayAsync(GatewayOpCode.StatusUpdate, args, options : options).ConfigureAwait(false);
        }