Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.IO;
  13. using System.Threading;
  14. using System.Text.RegularExpressions;
  15. using System.Runtime.InteropServices;
  16. using System.Media;
  17. using System.Diagnostics;
  18.  
  19. namespace DorpBot
  20. {
  21.     public partial class Form1 : Form
  22.     {
  23.         #region Variables
  24.         private static string userName = "dorpbot";
  25.         private static string password = "MyToken";
  26.  
  27.         IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  28.         NetworkStream serverStream = default(NetworkStream);
  29.         string readDATA = "";
  30.         Thread chatThread;
  31.         #endregion
  32.  
  33.         public Form1()
  34.         {
  35.             InitializeComponent();
  36.         }
  37.  
  38.         private void Form1_Load(object sender, EventArgs e)
  39.         {
  40.             irc.joinRoom("xiff_");
  41.             chatThread = new Thread(getMessage);
  42.             chatThread.Start();
  43.         }
  44.  
  45.         private void getMessage()
  46.         {
  47.             serverStream = irc.tcpClient.GetStream();
  48.             int buffsize = 0;
  49.             byte[] intStream = new byte[10025];
  50.             buffsize = irc.tcpClient.ReceiveBufferSize;
  51.             while (true)
  52.             {
  53.                 try
  54.                 {
  55.                     readDATA = irc.readMessage();
  56.                     msg();
  57.                 }
  58.  
  59.                 catch (Exception e)
  60.                 {
  61.  
  62.                 }
  63.             }
  64.         }
  65.  
  66.         private void msg()
  67.         {
  68.             if (this.InvokeRequired)
  69.                 this.Invoke(new MethodInvoker(msg));
  70.             else
  71.             {
  72.                 chatBox.Text = chatBox.Text + readDATA.ToString() + Environment.NewLine;
  73.             }
  74.         }
  75.     }
  76.  
  77.     class IrcClient
  78.     {
  79.         private string userName;
  80.         private string channel;
  81.  
  82.         public TcpClient tcpClient;
  83.         private StreamReader InputStream;
  84.         private StreamWriter OutputStream;
  85.  
  86.         public IrcClient(string ip, int port, string userName, string password)
  87.         {
  88.             tcpClient = new TcpClient(ip, port);
  89.             InputStream = new StreamReader(tcpClient.GetStream());
  90.             OutputStream = new StreamWriter(tcpClient.GetStream());
  91.  
  92.             OutputStream.WriteLine("PASS " + password);
  93.             OutputStream.WriteLine("NICK " + userName);
  94.             OutputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  95.             OutputStream.WriteLine("CAP REQ :twitch.tv/membership");
  96.             OutputStream.WriteLine("CAP REQ :twitch.tv/commands");
  97.             OutputStream.Flush();
  98.         }
  99.  
  100.         public void joinRoom(string channel)
  101.         {
  102.             this.channel = channel;
  103.             OutputStream.WriteLine("JOIN #" + channel);
  104.             OutputStream.Flush();
  105.         }
  106.  
  107.         public void leaveRoom()
  108.         {
  109.             OutputStream.Close();
  110.             InputStream.Close();
  111.         }
  112.  
  113.         public void sendIrcMessage(string message)
  114.         {
  115.             OutputStream.WriteLine(message);
  116.             OutputStream.Flush();
  117.         }
  118.  
  119.         public void sendChatMessage(string message)
  120.         {
  121.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  122.         }
  123.  
  124.         public void PingResponse()
  125.         {
  126.             sendIrcMessage("PONG tmi.twitch.tv\r\n");
  127.         }
  128.  
  129.         public string readMessage()
  130.         {
  131.             string message = "";
  132.             message = InputStream.ReadLine();
  133.             return message;
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement