| @@ -57,18 +57,21 @@ namespace Discord.API | |||
| { | |||
| AuthTokenType = tokenType; | |||
| switch (tokenType) | |||
| if (token != null) | |||
| { | |||
| case TokenType.Bot: | |||
| token = $"Bot {token}"; | |||
| break; | |||
| case TokenType.Bearer: | |||
| token = $"Bearer {token}"; | |||
| break; | |||
| case TokenType.User: | |||
| break; | |||
| default: | |||
| throw new ArgumentException("Unknown oauth token type", nameof(tokenType)); | |||
| switch (tokenType) | |||
| { | |||
| case TokenType.Bot: | |||
| token = $"Bot {token}"; | |||
| break; | |||
| case TokenType.Bearer: | |||
| token = $"Bearer {token}"; | |||
| break; | |||
| case TokenType.User: | |||
| break; | |||
| default: | |||
| throw new ArgumentException("Unknown oauth token type", nameof(tokenType)); | |||
| } | |||
| } | |||
| _restClient.SetHeader("authorization", token); | |||
| @@ -485,7 +488,7 @@ namespace Discord.API | |||
| while (true) | |||
| { | |||
| int runLimit = (limit >= DiscordConfig.MaxUsersPerBatch) ? DiscordConfig.MaxUsersPerBatch : limit; | |||
| string endpoint = $"guild/{guildId}/members?limit={limit}&offset={offset}"; | |||
| string endpoint = $"guild/{guildId}/members?limit={runLimit}&offset={offset}"; | |||
| var models = await Send<GuildMember[]>("GET", endpoint).ConfigureAwait(false); | |||
| //Was this an empty batch? | |||
| @@ -52,7 +52,8 @@ namespace Discord.Net.Rest | |||
| public void SetHeader(string key, string value) | |||
| { | |||
| _client.DefaultRequestHeaders.Remove(key); | |||
| _client.DefaultRequestHeaders.Add(key, value); | |||
| if (value != null) | |||
| _client.DefaultRequestHeaders.Add(key, value); | |||
| } | |||
| public async Task<Stream> Send(string method, string endpoint, string json = null, bool headerOnly = false) | |||
| @@ -43,6 +43,7 @@ namespace Discord.Rest | |||
| _connectionLock = new SemaphoreSlim(1, 1); | |||
| _log = new LogManager(config.LogLevel); | |||
| _userAgent = DiscordConfig.UserAgent; | |||
| BaseClient = new API.DiscordRawClient(_restClientProvider, _cancelTokenSource.Token); | |||
| _log.Message += (s,e) => Log.Raise(this, e); | |||
| } | |||
| @@ -72,7 +73,6 @@ namespace Discord.Rest | |||
| try | |||
| { | |||
| var cancelTokenSource = new CancellationTokenSource(); | |||
| BaseClient = new API.DiscordRawClient(_restClientProvider, cancelTokenSource.Token); | |||
| var args = new LoginParams { Email = email, Password = password }; | |||
| await BaseClient.Login(args).ConfigureAwait(false); | |||
| @@ -87,7 +87,6 @@ namespace Discord.Rest | |||
| try | |||
| { | |||
| var cancelTokenSource = new CancellationTokenSource(); | |||
| BaseClient = new API.DiscordRawClient(_restClientProvider, cancelTokenSource.Token); | |||
| BaseClient.SetToken(tokenType, token); | |||
| await CompleteLogin(cancelTokenSource, validateToken).ConfigureAwait(false); | |||
| @@ -126,7 +125,7 @@ namespace Discord.Rest | |||
| catch { } | |||
| } | |||
| BaseClient = null; | |||
| BaseClient.SetToken(TokenType.User, null); | |||
| _currentUser = null; | |||
| if (wasLoggedIn) | |||
| @@ -186,7 +185,7 @@ namespace Discord.Rest | |||
| { | |||
| var model = await BaseClient.GetGuildEmbed(id).ConfigureAwait(false); | |||
| if (model != null) | |||
| return new GuildEmbed(this, model); | |||
| return new GuildEmbed(model); | |||
| return null; | |||
| } | |||
| public async Task<IEnumerable<UserGuild>> GetGuilds() | |||