Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Connect(string username, string password)
- {
- if (Connected)
- return;
- Connected = true;
- twitchClient = new TcpClient("irc.chat.twitch.tv", 6667);
- reader = new StreamReader(twitchClient.GetStream());
- writer = new StreamWriter(twitchClient.GetStream());
- writer.WriteLine("CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership");
- writer.Flush();
- writer.WriteLine("PASS " + "<oauth token goes here>");
- writer.WriteLine("NICK " + username);
- writer.WriteLine("USER " + username + " 8 * :" + username);
- //! TEMP CHANNEL
- OnConnected?.Invoke();
- timer.Interval = TimeSpan.FromSeconds(.1f);
- timer.Tick += TimerOnTick;
- timer.Start();
- }
- public void Disconnect()
- {
- timer.Stop();
- twitchClient.Client.Close();
- reader = null;
- writer = null;
- OnDisconnected?.Invoke();
- Connected = false;
- ConnectedChannels.Clear();
- }
- private void TimerOnTick(object sender, EventArgs eventArgs)
- {
- if (Connected)
- {
- ReadChat();
- }
- else
- {
- timer.Tick -= TimerOnTick;
- timer.Stop();
- }
- }
- public void JoinChannel(string channel)
- {
- writer.WriteLine($"JOIN #{channel}");
- writer.Flush();
- ConnectedChannels.Add( new IrcChannel( channel ));
- }
- public void PartChannel(string channel)
- {
- writer.WriteLine($"PART #{channel}");
- writer.Flush();
- for (var i = ConnectedChannels.Count - 1; i >= 0; i--)
- {
- var connectedChannel = ConnectedChannels[i];
- if (connectedChannel.ChannelName == channel)
- {
- ConnectedChannels.Remove(connectedChannel);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement