-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Lavalink4NET.DSharpPlus; | ||
|
||
using System.Reflection; | ||
using global::DSharpPlus; | ||
using global::DSharpPlus.Clients; | ||
|
||
/// <summary> | ||
/// An utility for getting internal / private fields from DSharpPlus WebSocket Gateway Payloads. | ||
/// </summary> | ||
public static partial class DSharpPlusUtilities | ||
{ | ||
/// <summary> | ||
/// The internal "orchestrator" property info in <see cref="DiscordClient"/>. | ||
/// </summary> | ||
private static readonly FieldInfo orchestratorField = | ||
typeof(DiscordClient).GetField("orchestrator", BindingFlags.NonPublic | BindingFlags.Instance)!; | ||
|
||
/// <summary> | ||
/// Gets the amount of shards handled by this client's orchestrator. | ||
/// </summary> | ||
public static int GetConnectedShardCount(this DiscordClient client) | ||
{ | ||
var orchestrator = (IShardOrchestrator)orchestratorField.GetValue(client)!; | ||
return orchestrator.ConnectedShardCount; | ||
Check failure on line 24 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Debug)
Check failure on line 24 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Debug)
Check failure on line 24 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Release)
Check failure on line 24 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Release)
|
||
} | ||
|
||
/// <summary> | ||
/// Gets the total amount of shards connected to this bot. | ||
/// </summary> | ||
public static int GetTotalShardCount(this DiscordClient client) | ||
{ | ||
var orchestrator = (IShardOrchestrator)orchestratorField.GetValue(client)!; | ||
return orchestrator.TotalShardCount; | ||
Check failure on line 33 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Debug)
Check failure on line 33 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Debug)
Check failure on line 33 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Release)
Check failure on line 33 in src/Lavalink4NET.DSharpPlus.Nightly/DSharpPlusUtilities.cs GitHub Actions / build (Release)
|
||
} | ||
} |