Advertisement
Guest User

fffasdf

a guest
May 13th, 2016
322
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Sockets;
  7. using System.Net;
  8. using System.IO;
  9. using System.Threading;
  10.  
  11. namespace TwitchBot
  12. {
  13.     class IrcClient
  14.     {
  15.         private string userName;
  16.         private string channel;
  17.  
  18.         private TcpClient tcpClient;
  19.         private StreamReader inputStream;
  20.         private StreamWriter outputStream;
  21.  
  22.         public IrcClient(string ip, int port, string userName, string password)
  23.         {
  24.             this.userName = userName;
  25.  
  26.             tcpClient = new TcpClient(ip, port);
  27.             inputStream = new StreamReader(tcpClient.GetStream());
  28.             outputStream = new StreamWriter(tcpClient.GetStream());
  29.  
  30.             outputStream.WriteLine("PASS " + password);
  31.             outputStream.WriteLine("NICK " + userName);
  32.             outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  33.             outputStream.Flush();
  34.         }
  35.  
  36.         public void joinRoom(string channel)
  37.         {
  38.             this.channel = channel;
  39.             outputStream.WriteLine("JOIN #" + channel);
  40.             outputStream.Flush();
  41.         }
  42.  
  43.         public void sendIrcMessage(string message)
  44.         {
  45.             outputStream.WriteLine(message);
  46.             outputStream.Flush();
  47.         }
  48.  
  49.         public void sendChatMessage(string message)
  50.         {
  51.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  52.         }
  53.  
  54.         public string readMessage()
  55.         {
  56.             string message = inputStream.ReadLine();
  57.             if (message == "PING :tmi.twitch.tv")
  58.             {
  59.                 sendChatMessage("PONG :tmi.twitch.tv");
  60.             }
  61.             return message;
  62.         }
  63.     }
  64. }
Advertisement
RAW Paste Data Copied
Advertisement