electra13x7777

C# Twitch Bot Backbone

Nov 20th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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;
  7. using System.Net.Sockets;
  8. using System.IO;
  9.  
  10. namespace TwitchmIRCbot
  11. {
  12.  
  13.     class IrcClient
  14.     {
  15.         private string UserName;
  16.         private string Channel;
  17.  
  18.         private TcpClient TPCClient;
  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.             TPCClient = new TcpClient(ip, port);
  26.             InputStream = new StreamReader(TPCClient.GetStream());
  27.             OutputStream = new StreamWriter(TPCClient.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.         public void SendIrcMessage(string message)
  42.         {
  43.             OutputStream.WriteLine(message);
  44.             OutputStream.Flush();
  45.         }
  46.         public void SendChatMessage(string message)
  47.         {
  48.             SendIrcMessage(":" + UserName + "!" + UserName + "@" + UserName + ".tmi.twitch PRIVMSG #" + Channel + " :" + message);
  49.         }
  50.  
  51.         public string ReadMessage()
  52.         {
  53.  
  54.             string message = InputStream.ReadLine();
  55.             return message;
  56.         }
  57.        
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment