Skip to content

Commit

Permalink
Change out reflection for dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
NycroV committed Aug 13, 2024
1 parent b52e265 commit 9f4abb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
35 changes: 0 additions & 35 deletions src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs

This file was deleted.

11 changes: 7 additions & 4 deletions src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Lavalink4NET.DSharpPlus;
using Lavalink4NET = Clients.Events;
using Lavalink4NET.Events;
using Microsoft.Extensions.Logging;
using System.Reflection;

/// <summary>
/// Wraps a <see cref="DiscordClient"/> instance.
Expand All @@ -28,20 +27,24 @@ public sealed class DiscordClientWrapper : IDiscordClientWrapper
public event AsyncEventHandler<Lavalink4NET.VoiceStateUpdatedEventArgs>? VoiceStateUpdated;

private readonly DiscordClient _client;
private readonly IShardOrchestrator _shardOrchestrator;
private readonly ILogger<DiscordClientWrapper> _logger;
private readonly TaskCompletionSource<ClientInformation> _readyTaskCompletionSource;

/// <summary>
/// Creates a new instance of <see cref="DiscordClientWrapper"/>.
/// </summary>
/// <param name="discordClient">The Discord Client to wrap.</param>
/// <param name="logger">a logger associated with this wrapper.</param>
public DiscordClientWrapper(DiscordClient discordClient, ILogger<DiscordClientWrapper> logger)
/// <param name="shardOrchestrator">The Discord shard orchestrator associated with this client.</param>
/// <param name="logger">A logger associated with this wrapper.</param>
public DiscordClientWrapper(DiscordClient discordClient, IShardOrchestrator shardOrchestrator, ILogger<DiscordClientWrapper> logger)
{
ArgumentNullException.ThrowIfNull(discordClient);
ArgumentNullException.ThrowIfNull(shardOrchestrator);
ArgumentNullException.ThrowIfNull(logger);

_client = discordClient;
_shardOrchestrator = shardOrchestrator;
_logger = logger;
_readyTaskCompletionSource = new TaskCompletionSource<ClientInformation>(TaskCreationOptions.RunContinuationsAsynchronously);
}
Expand Down Expand Up @@ -141,7 +144,7 @@ internal Task OnGuildDownloadCompleted(DiscordClient discordClient, GuildDownloa
var clientInformation = new ClientInformation(
Label: "DSharpPlus",
CurrentUserId: discordClient.CurrentUser.Id,
ShardCount: discordClient.GetConnectedShardCount());
ShardCount: _shardOrchestrator.ConnectedShardCount);

Check failure on line 147 in src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

'IShardOrchestrator' does not contain a definition for 'ConnectedShardCount' and no accessible extension method 'ConnectedShardCount' accepting a first argument of type 'IShardOrchestrator' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

'IShardOrchestrator' does not contain a definition for 'ConnectedShardCount' and no accessible extension method 'ConnectedShardCount' accepting a first argument of type 'IShardOrchestrator' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build (Release)

'IShardOrchestrator' does not contain a definition for 'ConnectedShardCount' and no accessible extension method 'ConnectedShardCount' accepting a first argument of type 'IShardOrchestrator' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/Lavalink4NET.DSharpPlus.Nightly/DiscordClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build (Release)

'IShardOrchestrator' does not contain a definition for 'ConnectedShardCount' and no accessible extension method 'ConnectedShardCount' accepting a first argument of type 'IShardOrchestrator' could be found (are you missing a using directive or an assembly reference?)

_readyTaskCompletionSource.TrySetResult(clientInformation);
return Task.CompletedTask;
Expand Down

0 comments on commit 9f4abb0

Please sign in to comment.