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