示例#1
0
        private async Task ReceiveDataAsync()
        {
            try
            {
                while (true)
                {
                    var data = await ReceiveAsync();

                    if (data.Length <= 0)
                    {
                        continue;
                    }
                    var message = _encoding.GetString(data);
                    var trimmed = message.Trim('\0');
                    OnReceive?.Invoke(trimmed);
                }
            }
            catch (OperationCanceledException opEx)
            {
                _lavalink.LogError("Server disconnected.", opEx);
            }
            catch (WebSocketException wsEx)
            {
                _lavalink.LogError("Websocket error.", wsEx);
            }
            catch (Exception ex)
            {
                _lavalink.LogError(null, ex);
            }
            finally
            {
                Volatile.Write(ref IsDisposed, true);
                OnClose?.Invoke();
            }
        }
示例#2
0
        private async Task OnShardDisconnected(Exception exc, DiscordSocketClient client)
        {
            foreach (var guild in client.Guilds)
            {
                if (!_players.ContainsKey(guild.Id))
                {
                    continue;
                }
                await _players[guild.Id].DisconnectAsync();
                _players.TryRemove(guild.Id, out _);
            }

            _lavalink.LogError(null, exc);
        }