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:
Christopher F
2018-12-02 13:37:25 -05:00
committed by GitHub
parent 6d3d906e60
commit 65afd37502
4 changed files with 27 additions and 3 deletions

View File

@@ -42,9 +42,10 @@ namespace Discord.WebSocket
private int _nextAudioId;
private DateTimeOffset? _statusSince;
private RestApplication _applicationInfo;
private bool _isDisposed;
/// <summary> Provides access to a REST-only client with a shared state from this client. </summary>
public DiscordSocketRestClient Rest { get; }
/// <summary> Gets the shard of of this client. </summary>
public int ShardId { get; }
/// <summary> Gets the current connection state of this client. </summary>
@@ -128,6 +129,7 @@ namespace Discord.WebSocket
AlwaysDownloadUsers = config.AlwaysDownloadUsers;
HandlerTimeout = config.HandlerTimeout;
State = new ClientState(0, 0);
Rest = new DiscordSocketRestClient(config, ApiClient);
_heartbeatTimes = new ConcurrentQueue<long>();
_stateLock = new SemaphoreSlim(1, 1);