Example #1
0
 /// <summary>
 /// Creates a Lavalink Cluster from LavalinkNodeOptions and an existing HttpClient
 /// </summary>
 /// <param name="nodeOptions">The Node Options to create this Cluster with</param>
 /// <param name="httpClient">The HttpClient to use for this Cluster</param>
 protected LavalinkCluster(IEnumerable <LavalinkNodeOptions> nodeOptions, HttpClient httpClient)
 {
     foreach (var option in nodeOptions)
     {
         LavalinkNodes.Add(new LavalinkNode(this, option));
     }
     HttpClient = httpClient;
 }
Example #2
0
        /// <summary>
        /// Gets the Node corresponding for a GuildID, takes the <see cref="Filter"/> into account
        /// </summary>
        /// <param name="guildID">The GuildID to get the Node for</param>
        /// <returns>LavalinkNode</returns>
        /// <exception cref="Exception">thrown if no node could be found because of the filter</exception>
        public LavalinkNode GetNode(long guildID)
        {
            var node = LavalinkNodes.Find(lavalinkNode => lavalinkNode.Players.ContainsKey(guildID)) ?? Sort(guildID).Find(lavalinkNode => Filter(lavalinkNode, guildID));

            if (node != null)
            {
                return(node);
            }
            throw new Exception("unable to find appropriate node; please check your filter");
        }
Example #3
0
 /// <summary>
 /// Connects all Lavalink Nodes in this Cluster
 /// </summary>
 /// <returns>Task</returns>
 public Task ConnectAsync()
 => Task.WhenAll(LavalinkNodes.Select(node => node.ConnectAsync()));
Example #4
0
 /// <summary>
 /// Checks if this Cluster contains a Player, by GuildID
 /// </summary>
 /// <param name="guildID">The GuildID to check for</param>
 /// <returns>bool</returns>
 public bool HasPlayer(long guildID)
 => LavalinkNodes.Any(node => node.Players.ContainsKey(guildID));