Advertisement
Guest User

irc

a guest
May 16th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  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.  
  10. namespace TwitchBot
  11. {
  12.     class IrcClient
  13.     {
  14.         private string userName;
  15.         private string channel;
  16.  
  17.         private TcpClient tcpClient;
  18.         private StreamReader inputStream;
  19.         private StreamWriter outputStream;
  20.  
  21.         public IrcClient(string ip, int port, string userName, string password)
  22.         {
  23.             this.userName = userName;
  24.  
  25.             tcpClient = new TcpClient(ip, port);
  26.             inputStream = new StreamReader(tcpClient.GetStream());
  27.             outputStream = new StreamWriter(tcpClient.GetStream());
  28.  
  29.             outputStream.WriteLine("PASS " + password);
  30.             outputStream.WriteLine("NICK " + userName);
  31.             outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  32.             outputStream.Flush();
  33.         }
  34.  
  35.         public void joinRoom(string channel)
  36.         {
  37.             this.channel = channel;
  38.             outputStream.WriteLine("JOIN #" + channel);
  39.             outputStream.Flush();
  40.         }
  41.  
  42.         public void sendIrcMessage(string message)
  43.         {
  44.             outputStream.WriteLine(message);
  45.             outputStream.Flush();
  46.         }
  47.  
  48.         public void sendChatMessage(string message)
  49.         {
  50.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  51.         }
  52.  
  53.         public string readMessage()
  54.         {
  55.             string message = inputStream.ReadLine();
  56.             if (message == "PING :tmi.twitch.tv")
  57.             {
  58.                 sendIrcMessage("PONG :tmi.twitch.tv");
  59.             }
  60.             return message;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement