public async Task <Subscription> GetUserSubscriptionAsync(ulong userId, ulong channelId, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Subscription>("GET", $"users/{userId}/subscriptions/{channelId}", options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         return(null);
     }
 }
 // Teams
 public async Task <Team> GetTeamAsync(string name, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Team>("GET", $"teams/{name}", options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         return(null);
     }
 }
 // Streams
 public async Task <StreamCollection> GetStreamAsync(ulong channelId, StreamType type, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <StreamCollection>(new GetStreamRequest(channelId, type), options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         return(null);
     }
 }
 public async Task <Stream> GetStreamSummaryAsync(string game, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Stream>(new GetStreamSummaryRequest(game), options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         return(null);
     }
 }
 public async Task <Channel> GetChannelAsync(ulong channelId, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Channel>("GET", $"channels/{channelId}", options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == (HttpStatusCode)422)
     {
         return(null);
     }
 }
 // Communities
 public async Task <Community> GetCommunityAsync(string communityId, bool isName, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Community>(new GetCommunityRequest(communityId, isName), options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         return(null);
     }
 }
示例#7
0
        public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var msg = new ResumeParams()
            {
                Token     = AuthToken,
                SessionId = sessionId,
                Sequence  = lastSeq
            };

            await SendGatewayAsync(GatewayOpCode.Resume, msg, options : options).ConfigureAwait(false);
        }
 // Channels
 public async Task <Channel> GetMyChannelAsync(RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     try
     {
         return(await SendAsync <Channel>("GET", "channel", options).ConfigureAwait(false));
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.Unauthorized)
     {
         return(null);
     }
 }
 public async Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null)
 {
     options = RequestOptions.CreateOrClone(options);
     var payload = new VoiceStateUpdateParams
     {
         GuildId = guildId,
         ChannelId = channelId,
         SelfDeaf = selfDeaf,
         SelfMute = selfMute
     };
     await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false);
 }
 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
     };
     await SendGatewayAsync(GatewayOpCode.StatusUpdate, args, options: options).ConfigureAwait(false);
 }
        public async Task SendStatusUpdateAsync(UserStatus status, bool isAFK, long?since, GameJson game, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            StatusUpdateParams 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);
        }
        public async Task <AuthorizeResponse> SendAuthorizeAsync(IReadOnlyCollection <string> scopes, string rpcToken = null, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var msg = new AuthorizeParams
            {
                ClientId = _clientId,
                Scopes   = scopes,
                RpcToken = rpcToken != null ? rpcToken : Optional.Create <string>()
            };

            if (options.Timeout == null)
            {
                options.Timeout = 60000; //This requires manual input on the user's end, lets give them more time
            }
            options.IgnoreState = true;
            return(await SendRpcAsync <AuthorizeResponse>("AUTHORIZE", msg, options : options).ConfigureAwait(false));
        }
示例#13
0
        internal async Task EnterGlobalAsync(int id, WebSocketRequest request)
        {
            //If this is a global request (unbucketed), it'll be dealt in EnterAsync
            var requestBucket = GatewayBucket.Get(request.Options.BucketId);

            if (requestBucket.Type == GatewayBucketType.Unbucketed)
            {
                return;
            }

            //It's not a global request, so need to remove one from global (per-session)
            var globalBucketType = GatewayBucket.Get(GatewayBucketType.Unbucketed);
            var options          = RequestOptions.CreateOrClone(request.Options);

            options.BucketId = globalBucketType.Id;
            var globalRequest = new WebSocketRequest(null, null, false, false, options);
            var globalBucket  = GetOrCreateBucket(options, globalRequest);
            await globalBucket.TriggerAsync(id, globalRequest);
        }
示例#14
0
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, 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 }
            }
            ;

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options : options).ConfigureAwait(false);
        }
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, GatewayIntents?gatewayIntents = null, Optional <StatusUpdateParams> presence = default, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            Dictionary <string, string> props = new Dictionary <string, string>
            {
                ["$device"] = "Discord.Net"
            };
            IdentifyParams 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;
            }
            if (presence.IsSpecified)
            {
                msg.Presence = presence;
            }

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options : options).ConfigureAwait(false);
        }
示例#16
0
 public async Task <TeamCollection> GetTeamsAsync(PageOptions paging, RequestOptions options)
 {
     paging  = PageOptions.CreateOrClone(paging);
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <TeamCollection>(new GetTeamsRequest(paging), options).ConfigureAwait(false));
 }
示例#17
0
 public async Task <ClipCollection> GetFollowedClipsAsync(bool istrending, PageOptions paging, RequestOptions options)
 {
     paging  = PageOptions.CreateOrClone(paging);
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <ClipCollection>(new GetFollowedClipsRequest(istrending, paging), options));
 }
示例#18
0
 public async Task DeleteVideoAsync(string videoId, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     await SendAsync("DELETE", $"videos/{videoId}").ConfigureAwait(false);
 }
示例#19
0
 public async Task <ClipCollection> GetTopClipsAsync(TopClipsParams parameters, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <ClipCollection>(new GetTopClipsRequest(parameters), options));
 }
示例#20
0
 public async Task <VideoCollection> GetFollowedVideosAsync(string broadcastType, string language, string sort, PageOptions paging, RequestOptions options)
 {
     paging  = PageOptions.CreateOrClone(paging);
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <VideoCollection>(new GetFollowedVideosRequest(broadcastType, language, sort, paging), options).ConfigureAwait(false));
 }
示例#21
0
 public async Task <Video> ModifyVideoAsync(string videoId, ModifyVideoParams modify, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendJsonAsync <Video>("PUT", $"videos/{videoId}", options).ConfigureAwait(false));
 }
示例#22
0
 public async Task <VideoCollection> GetChannelVideosAsync(ulong channelId, PageOptions paging, RequestOptions options)
 {
     paging  = PageOptions.CreateOrClone(paging);
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <VideoCollection>("GET", $"channels/{channelId}/videos", options).ConfigureAwait(false));
 }
示例#23
0
 public async Task <BlockCollection> GetUserBlocksAsync(ulong userId, PageOptions paging, RequestOptions options)  // Paging is unused
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <BlockCollection>("GET", $"users/{userId}/blocks", options).ConfigureAwait(false));
 }
示例#24
0
 public async Task <BlockedUser> BlockUserAsync(ulong userId, ulong victimId, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <BlockedUser>("DELETE", $"users/{userId}/blocks/{victimId}", options).ConfigureAwait(false));
 }
 public async Task <GetBotGatewayResponse> GetBotGatewayAsync(RequestOptions options = null)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <GetBotGatewayResponse>("GET", () => "gateway/bot", new BucketIds(), options : options).ConfigureAwait(false));
 }
 public async Task SendRequestMembersAsync(IEnumerable <ulong> guildIds, RequestOptions options = null)
 {
     options = RequestOptions.CreateOrClone(options);
     await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options : options).ConfigureAwait(false);
 }
 public async Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null)
 {
     options = RequestOptions.CreateOrClone(options);
     await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options : options).ConfigureAwait(false);
 }
示例#28
0
 public async Task <TeamCollection> GetChannelTeamsAsync(ulong channelId, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <TeamCollection>("GET", $"channels/{channelId}/teams", options).ConfigureAwait(false));
 }
 public async Task SendGuildSyncAsync(IEnumerable <ulong> guildIds, RequestOptions options = null)
 {
     options = RequestOptions.CreateOrClone(options);
     await SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options : options).ConfigureAwait(false);
 }
示例#30
0
 public async Task <UserCollection> GetUsersAsync(string[] usernames, RequestOptions options)
 {
     options = RequestOptions.CreateOrClone(options);
     return(await SendAsync <UserCollection>(new GetUsersRequest(usernames), options).ConfigureAwait(false));
 }