diff --git a/src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs b/src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs
index 57428a5c..b871764c 100644
--- a/src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs
+++ b/src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs
@@ -17,7 +17,7 @@ namespace Lavalink4NET.DSharpPlus;
using System.Collections.Concurrent;
///
-/// Wraps a or instance.
+/// Wraps a instance.
///
public sealed class DiscordClientWrapper : IDiscordClientWrapper
{
@@ -27,21 +27,9 @@ public sealed class DiscordClientWrapper : IDiscordClientWrapper
///
public event AsyncEventHandler? VoiceStateUpdated;
- private readonly object _client; // either DiscordShardedClient or DiscordClient
+ private readonly DiscordClient _client; // sharded clients are now also managed by the same DiscordClient type
private readonly ILogger _logger;
private readonly TaskCompletionSource _readyTaskCompletionSource;
- private bool _disposed;
-
- private DiscordClientWrapper(object discordClient, ILogger logger)
- {
- ArgumentNullException.ThrowIfNull(discordClient);
- ArgumentNullException.ThrowIfNull(logger);
-
- _client = discordClient;
- _logger = logger;
-
- _readyTaskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
- }
///
/// Creates a new instance of .
@@ -49,9 +37,14 @@ private DiscordClientWrapper(object discordClient, ILogger
/// The Discord Client to wrap.
/// a logger associated with this wrapper.
public DiscordClientWrapper(DiscordClient discordClient, ILogger logger)
- : this((object)discordClient, logger)
{
ArgumentNullException.ThrowIfNull(discordClient);
+ ArgumentNullException.ThrowIfNull(logger);
+
+ _client = discordClient;
+ _logger = logger;
+
+ _readyTaskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
void AddEventHandler(Type eventArgsType, Delegate eventHandler)
{
@@ -73,21 +66,6 @@ void AddEventHandler(Type eventArgsType, Delegate eventHandler)
AddEventHandler(typeof(GuildDownloadCompletedEventArgs), new AsyncEventHandler(OnGuildDownloadCompleted));
}
- ///
- /// Creates a new instance of .
- ///
- /// The Sharded Discord Client to wrap.
- /// a logger associated with this wrapper.
- public DiscordClientWrapper(DiscordShardedClient shardedDiscordClient, ILogger logger)
- : this((object)shardedDiscordClient, logger)
- {
- ArgumentNullException.ThrowIfNull(shardedDiscordClient);
-
- shardedDiscordClient.VoiceStateUpdated += OnVoiceStateUpdated;
- shardedDiscordClient.VoiceServerUpdated += OnVoiceServerUpdated;
- shardedDiscordClient.GuildDownloadCompleted += OnGuildDownloadCompleted;
- }
-
///
/// thrown if the instance is disposed
public async ValueTask> GetChannelUsersAsync(
@@ -101,7 +79,7 @@ public async ValueTask> GetChannelUsersAsync(
DiscordChannel channel;
try
{
- channel = await GetClientForGuild(guildId)
+ channel = await _client
.GetChannelAsync(voiceChannelId)
.ConfigureAwait(false);
@@ -145,8 +123,6 @@ public async ValueTask SendVoiceUpdateAsync(
{
cancellationToken.ThrowIfCancellationRequested();
- var client = GetClientForGuild(guildId);
-
var payload = new VoiceStateUpdatePayload
{
GuildId = guildId,
@@ -155,13 +131,17 @@ public async ValueTask SendVoiceUpdateAsync(
IsSelfDeafened = selfDeaf,
};
+#pragma warning disable DSP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#pragma warning disable CS0618 // This method should not be used unless you know what you're doing. Instead, look towards the other explicitly implemented methods which come with client-side validation.
+
// Jan 23, 2024, OoLunar: We're telling Discord that we're joining a voice channel.
// At the time of writing, both DSharpPlus.VoiceNext and DSharpPlus.VoiceLinkâ˘
// use this method to send voice state updates.
- await client
- .SendPayloadAsync(GatewayOpCode.VoiceStateUpdate, payload)
+ await _client
+ .SendPayloadAsync(GatewayOpCode.VoiceStateUpdate, payload, guildId)
.ConfigureAwait(false);
+
+#pragma warning restore DSP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#pragma warning restore CS0618 // This method should not be used unless you know what you're doing. Instead, look towards the other explicitly implemented methods which come with client-side validation.
}
@@ -172,11 +152,7 @@ public ValueTask WaitForReadyAsync(CancellationToken cancella
return new(_readyTaskCompletionSource.Task.WaitAsync(cancellationToken));
}
- private DiscordClient GetClientForGuild(ulong guildId) => _client is DiscordClient discordClient
- ? discordClient
- : ((DiscordShardedClient)_client).GetShard(guildId);
-
- private Task OnGuildDownloadCompleted(DiscordClient discordClient, GuildDownloadCompletedEventArgs eventArgs)
+ private async Task OnGuildDownloadCompleted(DiscordClient discordClient, GuildDownloadCompletedEventArgs eventArgs)
{
ArgumentNullException.ThrowIfNull(discordClient);
ArgumentNullException.ThrowIfNull(eventArgs);
@@ -184,10 +160,9 @@ private Task OnGuildDownloadCompleted(DiscordClient discordClient, GuildDownload
var clientInformation = new ClientInformation(
Label: "DSharpPlus",
CurrentUserId: discordClient.CurrentUser.Id,
- ShardCount: discordClient.ShardCount);
+ ShardCount: (await discordClient.GetGatewayInfoAsync()).ShardCount);
_readyTaskCompletionSource.TrySetResult(clientInformation);
- return Task.CompletedTask;
}
private async Task OnVoiceServerUpdated(DiscordClient discordClient, VoiceServerUpdatedEventArgs voiceServerUpdateEventArgs)
diff --git a/src/Lavalink4NET.DSharpPlus.Nightly/Lavalink4NET.DSharpPlus.Nightly.csproj b/src/Lavalink4NET.DSharpPlus.Nightly/Lavalink4NET.DSharpPlus.Nightly.csproj
index c561a925..820efd13 100644
--- a/src/Lavalink4NET.DSharpPlus.Nightly/Lavalink4NET.DSharpPlus.Nightly.csproj
+++ b/src/Lavalink4NET.DSharpPlus.Nightly/Lavalink4NET.DSharpPlus.Nightly.csproj
@@ -11,7 +11,7 @@
False
-
+