Beispiel #1
0
        internal LavaNode(BaseDiscordClient baseClient, LavaSocket socket, LavaConfig config)
        {
            _config     = config;
            _baseClient = baseClient;
            LavaSocket  = socket;
            _lavalink   = LavaSocket._lavalink;
            _rest       = new HttpClient();
            _rest.DefaultRequestHeaders.Add("Authorization", _config.Authorization);
            Statistics = new LavaStats();
            _players   = new ConcurrentDictionary <ulong, LavaPlayer>();

            switch (_baseClient)
            {
            case DiscordSocketClient socketClient:
                socketClient.VoiceServerUpdated    += OnVSU;
                socketClient.UserVoiceStateUpdated += OnUVSU;
                socketClient.Disconnected          += OnSocketDisconnected;
                break;

            case DiscordShardedClient shardClient:
                shardClient.VoiceServerUpdated    += OnVSU;
                shardClient.UserVoiceStateUpdated += OnUVSU;
                shardClient.ShardDisconnected     += OnShardDisconnected;
                break;
            }
        }
Beispiel #2
0
 internal LavaSocket(LavaConfig config, Lavalink lavalink)
 {
     _config   = config;
     _lavalink = lavalink;
     _encoding = new UTF8Encoding(false);
     ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
 }
Beispiel #3
0
        /// <summary>
        /// Shortcut method to add <see cref="LavaNode{TPlayer}"/> to <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="serviceCollection">
        ///     <see cref="IServiceProvider" />
        /// </param>
        /// <param name="action">LavaConfig action.</param>
        /// <typeparam name="T"><see cref="LavaPlayer"/></typeparam>
        /// <returns>
        ///     <see cref="IServiceCollection" />
        /// </returns>
        public static IServiceCollection AddLavaNode <T>(this IServiceCollection serviceCollection,
                                                         Action <LavaConfig> action = default) where T : LavaPlayer
        {
            var lavaConfig = new LavaConfig();

            action?.Invoke(lavaConfig);
            serviceCollection.AddSingleton(lavaConfig);
            serviceCollection.AddSingleton <LavaNode <T> >();
            return(serviceCollection);
        }
Beispiel #4
0
        /// <summary>
        ///     Returns the current status of route planner.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static async Task <RouteStatus> GetStatusAsync(LavaConfig lavaConfig)
        {
            if (lavaConfig == null)
            {
                throw new ArgumentNullException(nameof(lavaConfig));
            }

            var requestMessage =
                new HttpRequestMessage(HttpMethod.Get, $"{lavaConfig.HttpEndpoint}/routeplanner/status")
            {
                Headers =
                {
                    { "Authorization", lavaConfig.Authorization }
                }
            };

            var routeStatus = await VictoriaExtensions.ReadAsJsonAsync <RouteStatus>(requestMessage);

            if (!routeStatus.Equals(default))
Beispiel #5
0
 internal LavaSocket(LavaConfig lavaConfig)
 {
     _lavaConfig = lavaConfig;
     _headers    = new Dictionary <string, string>(3);
 }
Beispiel #6
0
 /// <inheritdoc />
 public LavaNode(DiscordShardedClient shardedClient, LavaConfig config) : base(shardedClient, config)
 {
 }
Beispiel #7
0
 /// <inheritdoc />
 public LavaNode(DiscordSocketClient socketClient, LavaConfig config) : base(socketClient, config)
 {
 }
Beispiel #8
0
 internal LavaSocket(LavaConfig lavaConfig)
 {
     _lavaConfig = lavaConfig;
     _webSocket  = new ClientWebSocket();
     _url        = new Uri($"{(_lavaConfig.IsSsl ? "wss" : "ws")}://{_lavaConfig.Hostname}:{_lavaConfig.Port}");
 }
Beispiel #9
0
 internal LavaSocket(LavaConfig lavaConfig)
 {
     _lavaConfig   = lavaConfig;
     _headers      = new Dictionary <string, string>(3);
     DefaultVolume = lavaConfig.DefaultVolume;
 }