/// <summary> /// Utility Method to Compare Lavalink Nodes by there CPU Usage /// </summary> /// <param name="a">Node A</param> /// <param name="b">Node B</param> /// <returns>int</returns> public static int CompareCPU(LavalinkNode a, LavalinkNode b) { if (a.LavalinkStats == null || b.LavalinkStats == null || !b.Connected) { return(-1); } return((int)(a.LavalinkStats.CPU.SystemLoad / a.LavalinkStats.CPU.Cores - (b.LavalinkStats.CPU.SystemLoad - b.LavalinkStats.CPU.Cores))); }
/// <summary> /// Moves this Player to another Lavalink Node /// </summary> /// <param name="node">The new Node of this Player</param> /// <returns>Task</returns> /// <exception cref="Exception"></exception> public async Task MoveToAsync(LavalinkNode node) { if (node == Node) throw new Exception("can't move to the same node"); var voiceServer = VoiceServer; var voiceState = VoiceState; if (voiceServer == null || voiceState == null) throw new Exception("no voice state/server data to move"); await DestroyAsync(); node.Players.TryAdd(GuildID, this); await Task.WhenAll(node.VoiceServerUpdateAsync(voiceServer), node.VoiceStateUpdateAsync(voiceState)); Node = node; }
/// <summary> /// Creates a new PlayerStore instance /// </summary> /// <param name="node">The LavalinkNode this PlayerStore is for</param> public PlayerStore(LavalinkNode node) => Node = node;
/// <summary> /// Creates a new Player Instance /// </summary> /// <param name="node">The Node this Player was created on</param> /// <param name="guildID">The GuildID of this Player</param> public Player(LavalinkNode node, long guildID) { Node = node; GuildID = guildID; }
/// <summary> /// Abstract Filter method that should be used to determine if a Node is appropriate for a Player /// </summary> /// <param name="node">The Node to test</param> /// <param name="guildID">The GuildID to test on this Node</param> /// <returns>bool</returns> protected abstract bool Filter(LavalinkNode node, long guildID);
/// <summary> /// Creates a new StatsEventArgs instance /// </summary> /// <param name="node">The Node where the Event occured</param> /// <param name="stats">The new Stats of the Node</param> public StatsEventArgs(LavalinkNode node, LavalinkStats stats) { Node = node; Stats = stats; }
/// <summary> /// Creates a new MessageEventArgs instance /// </summary> /// <param name="node">The Node where the Event occured</param> /// <param name="message">The JObject of the Event</param> public MessageEventArgs(LavalinkNode node, JObject message) { Node = node; Event = message; }
/// <summary> /// Creates a new StatsEventArgs instance /// </summary> /// <param name="node">The Node where the Event occured, if this is null it comes from the Cluster</param> /// <param name="logLevel">The LogLevel of this Event</param> /// <param name="message">The Message of this Log</param> public LogEventArgs(LavalinkNode node, LogLevel logLevel, string message) { Node = node; LogLevel = logLevel; Message = message; }