Advertisement
Guest User

Untitled

a guest
Dec 16th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 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 Twitchbot
  20. {
  21. public partial class Form1 : Form
  22. {
  23. #region Variables
  24. private static string userName = "NicknameHere";
  25. private static string password = "PasswordHere";
  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.  
  34. public Form1()
  35. {
  36. InitializeComponent();
  37. }
  38. private void Form1_Load(object sender, EventArgs e)
  39. {
  40. irc.joinRoom("ChannelHere");
  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[] inStream = new byte[10025];
  50. buffsize = irc.tcpClient.ReceiveBufferSize;
  51. while (true)
  52. {
  53. try
  54. {
  55. readData = irc.readMessage();
  56. msg();
  57. }
  58. catch (Exception e)
  59. {
  60.  
  61. }
  62.  
  63. }
  64. }
  65.  
  66. private void msg()
  67. {
  68. if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  69. else
  70. {
  71. chatBox.Text = chatBox.Text + readData.ToString() + Environment.NewLine;
  72. }
  73. }
  74.  
  75.  
  76.  
  77. }
  78.  
  79. class ircClient
  80. {
  81. private string userName;
  82. private string channel;
  83.  
  84. public TcpClient tcpClient;
  85. private StreamReader inputStream;
  86. private StreamWriter outputStream;
  87.  
  88. public ircClient(string ip, int port, string userName, string password)
  89. {
  90. tcpClient = new TcpClient(ip, port);
  91. inputStream = new StreamReader(tcpClient.GetStream());
  92. outputStream = new StreamWriter(tcpClient.GetStream());
  93.  
  94. outputStream.WriteLine("PASS " + password);
  95. outputStream.WriteLine("NICK " + userName);
  96. outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  97. outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  98. outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  99. outputStream.Flush();
  100.  
  101. }
  102.  
  103. public void joinRoom(string channel)
  104. {
  105. this.channel = channel;
  106. outputStream.WriteLine("JOIN #" + channel);
  107. outputStream.Flush();
  108. }
  109.  
  110. public void leaveRoom()
  111. {
  112. outputStream.Close();
  113. inputStream.Close();
  114. }
  115.  
  116. public void sendIrcMessage(string message)
  117. {
  118. outputStream.WriteLine(message);
  119. outputStream.Flush();
  120. }
  121.  
  122. public void sendChatMessage(string message)
  123. {
  124. sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  125. }
  126.  
  127. public void pingResponse()
  128. {
  129. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  130. }
  131.  
  132. public string readMessage()
  133. {
  134. string message = "";
  135. message = inputStream.ReadLine();
  136. return message;
  137. }
  138.  
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement