feature: add DiscordSocketRestClient (#1198)
* feature: add DiscordSocketRestClient this resolves #803. Users can access a DiscordSocketRestClient from the new `DiscordSocketClient.Rest` property. DiscordSocketRestClient is a wrapper over DiscordRestClient with certain state-modifying methods, such as Login/Logout disabled, to prevent users from breaking the client state. DiscordSocketRestClient uses the same API client as the DiscordSocketClient, allowing for shared ratelimiting - meaning users can now force HTTP requests without needing to wory about running into 429s. * fix: disallow users from bypassing shadowed login
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Discord.Rest
|
||||
}
|
||||
finally { _stateLock.Release(); }
|
||||
}
|
||||
private async Task LoginInternalAsync(TokenType tokenType, string token, bool validateToken)
|
||||
internal virtual async Task LoginInternalAsync(TokenType tokenType, string token, bool validateToken)
|
||||
{
|
||||
if (_isFirstLogin)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ namespace Discord.Rest
|
||||
}
|
||||
finally { _stateLock.Release(); }
|
||||
}
|
||||
private async Task LogoutInternalAsync()
|
||||
internal virtual async Task LogoutInternalAsync()
|
||||
{
|
||||
if (LoginState == LoginState.LoggedOut) return;
|
||||
LoginState = LoginState.LoggingOut;
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Discord.Rest
|
||||
/// </summary>
|
||||
/// <param name="config">The configuration to be used with the client.</param>
|
||||
public DiscordRestClient(DiscordRestConfig config) : base(config, CreateApiClient(config)) { }
|
||||
// used for socket client rest access
|
||||
internal DiscordRestClient(DiscordRestConfig config, API.DiscordRestApiClient api) : base(config, api) { }
|
||||
|
||||
private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config)
|
||||
=> new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent);
|
||||
|
||||
Reference in New Issue
Block a user