Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.Net;
- using System.IO;
- namespace TwitchBot
- {
- class IrcClient
- {
- private string userName;
- private string channel;
- private TcpClient tcpClient;
- private StreamReader inputStream;
- private StreamWriter outputStream;
- public IrcClient(string ip, int port, string userName, string password)
- {
- this.userName = userName;
- tcpClient = new TcpClient(ip, port);
- inputStream = new StreamReader(tcpClient.GetStream());
- outputStream = new StreamWriter(tcpClient.GetStream());
- outputStream.WriteLine("PASS " + password);
- outputStream.WriteLine("NICK " + userName);
- outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
- outputStream.Flush();
- }
- public void joinRoom(string channel)
- {
- this.channel = channel;
- outputStream.WriteLine("JOIN #" + channel);
- outputStream.Flush();
- }
- public void sendIrcMessage(string message)
- {
- outputStream.WriteLine(message);
- outputStream.Flush();
- }
- public void sendChatMessage(string message)
- {
- sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
- }
- public string readMessage()
- {
- string message = inputStream.ReadLine();
- if (message == "PING :tmi.twitch.tv")
- {
- sendIrcMessage("PONG :tmi.twitch.tv");
- }
- return message;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement