Stop spamming users/@me and voice/regions
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Discord.WebSocket
|
||||
_shardIdsToIndex.Add(_shardIds[i], i);
|
||||
var newConfig = config.Clone();
|
||||
newConfig.ShardId = _shardIds[i];
|
||||
_shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock);
|
||||
_shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock, i != 0 ? _shards[0] : null);
|
||||
RegisterEvents(_shards[i]);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace Discord.WebSocket
|
||||
var newConfig = _baseConfig.Clone();
|
||||
newConfig.ShardId = _shardIds[i];
|
||||
newConfig.TotalShards = _totalShards;
|
||||
_shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock);
|
||||
_shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock, i != 0 ? _shards[0] : null);
|
||||
RegisterEvents(_shards[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Discord.API
|
||||
|
||||
public DiscordSocketApiClient(RestClientProvider restClientProvider, string userAgent, WebSocketProvider webSocketProvider,
|
||||
RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, true)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer)
|
||||
{
|
||||
WebSocketClient = webSocketProvider();
|
||||
//WebSocketClient.SetHeader("user-agent", DiscordConfig.UserAgent); (Causes issues in .NET Framework 4.6+)
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Discord.WebSocket
|
||||
private readonly Logger _gatewayLogger;
|
||||
private readonly JsonSerializer _serializer;
|
||||
private readonly SemaphoreSlim _connectionGroupLock;
|
||||
private readonly DiscordSocketClient _parentClient;
|
||||
|
||||
private string _sessionId;
|
||||
private int _lastSeq;
|
||||
@@ -71,9 +72,9 @@ namespace Discord.WebSocket
|
||||
/// <summary> Creates a new REST/WebSocket discord client. </summary>
|
||||
public DiscordSocketClient() : this(new DiscordSocketConfig()) { }
|
||||
/// <summary> Creates a new REST/WebSocket discord client. </summary>
|
||||
public DiscordSocketClient(DiscordSocketConfig config) : this(config, CreateApiClient(config), null) { }
|
||||
internal DiscordSocketClient(DiscordSocketConfig config, SemaphoreSlim groupLock) : this(config, CreateApiClient(config), groupLock) { }
|
||||
private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClient client, SemaphoreSlim groupLock)
|
||||
public DiscordSocketClient(DiscordSocketConfig config) : this(config, CreateApiClient(config), null, null) { }
|
||||
internal DiscordSocketClient(DiscordSocketConfig config, SemaphoreSlim groupLock, DiscordSocketClient parentClient) : this(config, CreateApiClient(config), groupLock, parentClient) { }
|
||||
private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClient client, SemaphoreSlim groupLock, DiscordSocketClient parentClient)
|
||||
: base(config, client)
|
||||
{
|
||||
ShardId = config.ShardId ?? 0;
|
||||
@@ -90,6 +91,7 @@ namespace Discord.WebSocket
|
||||
_nextAudioId = 1;
|
||||
_gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : "Shard #" + ShardId);
|
||||
_connectionGroupLock = groupLock;
|
||||
_parentClient = parentClient;
|
||||
|
||||
_serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() };
|
||||
_serializer.Error += (s, e) =>
|
||||
@@ -134,8 +136,13 @@ namespace Discord.WebSocket
|
||||
|
||||
protected override async Task OnLoginAsync(TokenType tokenType, string token)
|
||||
{
|
||||
var voiceRegions = await ApiClient.GetVoiceRegionsAsync(new RequestOptions { IgnoreState = true, RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
|
||||
_voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id);
|
||||
if (_parentClient == null)
|
||||
{
|
||||
var voiceRegions = await ApiClient.GetVoiceRegionsAsync(new RequestOptions { IgnoreState = true, RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
|
||||
_voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id);
|
||||
}
|
||||
else
|
||||
_voiceRegions = _parentClient._voiceRegions;
|
||||
}
|
||||
protected override async Task OnLogoutAsync()
|
||||
{
|
||||
@@ -603,6 +610,7 @@ namespace Discord.WebSocket
|
||||
var state = new ClientState(data.Guilds.Length, data.PrivateChannels.Length);
|
||||
|
||||
var currentUser = SocketSelfUser.Create(this, state, data.User);
|
||||
ApiClient.CurrentUserId = currentUser.Id;
|
||||
int unavailableGuilds = 0;
|
||||
for (int i = 0; i < data.Guilds.Length; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user