misc: VoiceRegions and related changes (#1720)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -75,6 +76,7 @@ namespace Discord.WebSocket
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A read-only collection of voice regions that the user has access to.
|
/// A read-only collection of voice regions that the user has access to.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
[Obsolete("This property is obsolete, use the GetVoiceRegionsAsync method instead.")]
|
||||||
public abstract IReadOnlyCollection<RestVoiceRegion> VoiceRegions { get; }
|
public abstract IReadOnlyCollection<RestVoiceRegion> VoiceRegions { get; }
|
||||||
|
|
||||||
internal BaseSocketClient(DiscordSocketConfig config, DiscordRestApiClient client)
|
internal BaseSocketClient(DiscordSocketConfig config, DiscordRestApiClient client)
|
||||||
@@ -169,7 +171,26 @@ namespace Discord.WebSocket
|
|||||||
/// A REST-based voice region associated with the identifier; <c>null</c> if the voice region is not
|
/// A REST-based voice region associated with the identifier; <c>null</c> if the voice region is not
|
||||||
/// found.
|
/// found.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
[Obsolete("This method is obsolete, use GetVoiceRegionAsync instead.")]
|
||||||
public abstract RestVoiceRegion GetVoiceRegion(string id);
|
public abstract RestVoiceRegion GetVoiceRegion(string id);
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all voice regions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options">The options to be used when sending the request.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A task that contains a read-only collection of REST-based voice regions.
|
||||||
|
/// </returns>
|
||||||
|
public abstract ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null);
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a voice region.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The identifier of the voice region (e.g. <c>eu-central</c> ).</param>
|
||||||
|
/// <param name="options">The options to be used when sending the request.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A task that contains a REST-based voice region associated with the identifier; <c>null</c> if the
|
||||||
|
/// voice region is not found.
|
||||||
|
/// </returns>
|
||||||
|
public abstract ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public abstract Task StartAsync();
|
public abstract Task StartAsync();
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace Discord.WebSocket
|
|||||||
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => GetPrivateChannels().ToReadOnlyCollection(GetPrivateChannelCount);
|
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => GetPrivateChannels().ToReadOnlyCollection(GetPrivateChannelCount);
|
||||||
public IReadOnlyCollection<DiscordSocketClient> Shards => _shards;
|
public IReadOnlyCollection<DiscordSocketClient> Shards => _shards;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[Obsolete("This property is obsolete, use the GetVoiceRegionsAsync method instead.")]
|
||||||
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _shards[0].VoiceRegions;
|
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _shards[0].VoiceRegions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -264,9 +265,22 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[Obsolete("This method is obsolete, use GetVoiceRegionAsync instead.")]
|
||||||
public override RestVoiceRegion GetVoiceRegion(string id)
|
public override RestVoiceRegion GetVoiceRegion(string id)
|
||||||
=> _shards[0].GetVoiceRegion(id);
|
=> _shards[0].GetVoiceRegion(id);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
|
||||||
|
{
|
||||||
|
return await _shards[0].GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
return await _shards[0].GetVoiceRegionAsync(id, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="guilds"/> is <see langword="null"/></exception>
|
/// <exception cref="ArgumentNullException"><paramref name="guilds"/> is <see langword="null"/></exception>
|
||||||
public override async Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
|
public override async Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ namespace Discord.WebSocket
|
|||||||
public IReadOnlyCollection<SocketGroupChannel> GroupChannels
|
public IReadOnlyCollection<SocketGroupChannel> GroupChannels
|
||||||
=> State.PrivateChannels.OfType<SocketGroupChannel>().ToImmutableArray();
|
=> State.PrivateChannels.OfType<SocketGroupChannel>().ToImmutableArray();
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection();
|
[Obsolete("This property is obsolete, use the GetVoiceRegionsAsync method instead.")]
|
||||||
|
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => GetVoiceRegionsAsync().GetAwaiter().GetResult();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new REST/WebSocket-based Discord client.
|
/// Initializes a new REST/WebSocket-based Discord client.
|
||||||
@@ -178,7 +179,6 @@ namespace Discord.WebSocket
|
|||||||
return Task.Delay(0);
|
return Task.Delay(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
_voiceRegions = ImmutableDictionary.Create<string, RestVoiceRegion>();
|
|
||||||
_largeGuilds = new ConcurrentQueue<ulong>();
|
_largeGuilds = new ConcurrentQueue<ulong>();
|
||||||
}
|
}
|
||||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||||
@@ -204,13 +204,6 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override async Task OnLoginAsync(TokenType tokenType, string token)
|
internal override async Task OnLoginAsync(TokenType tokenType, string token)
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
await Rest.OnLoginAsync(tokenType, token);
|
await Rest.OnLoginAsync(tokenType, token);
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -218,7 +211,7 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
await StopAsync().ConfigureAwait(false);
|
await StopAsync().ConfigureAwait(false);
|
||||||
_applicationInfo = null;
|
_applicationInfo = null;
|
||||||
_voiceRegions = ImmutableDictionary.Create<string, RestVoiceRegion>();
|
_voiceRegions = null;
|
||||||
await Rest.OnLogoutAsync();
|
await Rest.OnLogoutAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,11 +343,39 @@ namespace Discord.WebSocket
|
|||||||
=> State.RemoveUser(id);
|
=> State.RemoveUser(id);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[Obsolete("This method is obsolete, use GetVoiceRegionAsync instead.")]
|
||||||
public override RestVoiceRegion GetVoiceRegion(string id)
|
public override RestVoiceRegion GetVoiceRegion(string id)
|
||||||
|
=> GetVoiceRegionAsync(id).GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
|
||||||
{
|
{
|
||||||
if (_voiceRegions.TryGetValue(id, out RestVoiceRegion region))
|
if (_parentClient == null)
|
||||||
return region;
|
{
|
||||||
return null;
|
if (_voiceRegions == null)
|
||||||
|
{
|
||||||
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
options.IgnoreState = true;
|
||||||
|
var voiceRegions = await ApiClient.GetVoiceRegionsAsync(options).ConfigureAwait(false);
|
||||||
|
_voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id);
|
||||||
|
}
|
||||||
|
return _voiceRegions.ToReadOnlyCollection();
|
||||||
|
}
|
||||||
|
return await _parentClient.GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
if (_parentClient == null)
|
||||||
|
{
|
||||||
|
if (_voiceRegions == null)
|
||||||
|
await GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||||
|
if (_voiceRegions.TryGetValue(id, out RestVoiceRegion region))
|
||||||
|
return region;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return await _parentClient.GetVoiceRegionAsync(id, options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -2120,11 +2141,11 @@ namespace Discord.WebSocket
|
|||||||
=> Task.FromResult<IUser>(GetUser(username, discriminator));
|
=> Task.FromResult<IUser>(GetUser(username, discriminator));
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options)
|
async Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options)
|
||||||
=> Task.FromResult<IReadOnlyCollection<IVoiceRegion>>(VoiceRegions);
|
=> await GetVoiceRegionsAsync(options).ConfigureAwait(false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options)
|
async Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options)
|
||||||
=> Task.FromResult<IVoiceRegion>(GetVoiceRegion(id));
|
=> await GetVoiceRegionAsync(id, options).ConfigureAwait(false);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task IDiscordClient.StartAsync()
|
async Task IDiscordClient.StartAsync()
|
||||||
|
|||||||
Reference in New Issue
Block a user