Esempio n. 1
0
        public TwitchIRCClient(string hostname, int port, string oAuth, string username
                               , TwitchIRCClientCapabilities capabilities = TwitchIRCClientCapabilities.Commands | TwitchIRCClientCapabilities.Membership | TwitchIRCClientCapabilities.Tags)
        {
            _hostname     = hostname;
            _port         = port;
            _oAuth        = oAuth;
            _username     = username;
            _capabilities = capabilities;

            OnRawMessage += _ParseMessage;

            _runner = _ReadMessages();
        }
Esempio n. 2
0
        private async Task _Connect(string host, int port, string oAuth, string username, TwitchIRCClientCapabilities capabilities = TwitchIRCClientCapabilities.Commands | TwitchIRCClientCapabilities.Membership | TwitchIRCClientCapabilities.Tags)
        {
            _tcpClient    = new TcpClient(host, port);
            _inputStream  = TextReader.Synchronized(new StreamReader(_tcpClient.GetStream()));
            _outputStream = TextWriter.Synchronized(new StreamWriter(_tcpClient.GetStream()));

            await _outputStream.WriteLineAsync(String.Format("PASS oauth:{0}", oAuth));

            await _outputStream.WriteLineAsync(String.Format("NICK {0}", username));

            await _outputStream.FlushAsync();

            if (capabilities.HasFlag(TwitchIRCClientCapabilities.Membership))
            {
                await _outputStream.WriteLineAsync(String.Format("CAP REQ :twitch.tv/membership"));
            }

            if (capabilities.HasFlag(TwitchIRCClientCapabilities.Commands))
            {
                await _outputStream.WriteLineAsync(String.Format("CAP REQ :twitch.tv/commands"));
            }

            if (capabilities.HasFlag(TwitchIRCClientCapabilities.Tags))
            {
                await _outputStream.WriteLineAsync(String.Format("CAP REQ :twitch.tv/tags"));
            }

            await _outputStream.FlushAsync();

            //if this is a reconnect, we may need to rejoin channels that we lost.
            if (_channels.Count > 0)
            {
                foreach (var i in _channels)
                {
                    if (!string.IsNullOrWhiteSpace(i.Value?.Name))
                    {
                        await JoinChannel(i.Value.Name);
                    }
                }
            }
            await _outputStream.FlushAsync();

            _finishedConnecting = true;
            _InvokeConnect(new ConnectEventArgs(true));
        }