Advertisement
TomasBacchiocca

Untitled

Aug 30th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 TwitchBot
  20. {
  21. public partial class Form1 : Form
  22. {
  23. #region Variables
  24. private static string Username = "RoyalDestinyYT";
  25. private static string Password = "oauth:451q6mx658srysnf3humty6j6oki7x";
  26. IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, Username, Password);
  27. NetworkStream serverStream = default(NetworkStream);
  28. string readData = "";
  29. Thread chatThread;
  30. #endregion
  31. public Form1()
  32. {
  33. InitializeComponent();
  34. }
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. irc.JoinRoom("RoyalDestinyYT");
  38. chatThread = new Thread(getMessage);
  39. chatThread.Start();
  40. }
  41. private void getMessage()
  42. {
  43. serverStream = irc.tcpClient.GetStream();
  44. int buffsize = 0;
  45. byte[] inStream = new byte[10025];
  46. buffsize = irc.tcpClient.ReceiveBufferSize;
  47. while(true)
  48. {
  49. try
  50. {
  51. readData = irc.readMessage();
  52. msg();
  53. }
  54. catch(Exception e)
  55. {
  56.  
  57. }
  58. }
  59. }
  60. private void msg()
  61. {
  62. if(this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  63. else
  64. {
  65. chatBox.Text = chatBox.Text + readData.ToString() + Environment.NewLine;
  66.  
  67. }
  68. }
  69. }
  70. class IrcClient
  71. {
  72. private string Username;
  73. private string Channel;
  74. public TcpClient tcpClient;
  75. private StreamReader inputStream;
  76. private StreamWriter outputStream;
  77. public IrcClient(string Ip, int Port, string Username, string Password)
  78. {
  79. tcpClient = new TcpClient(Ip, Port);
  80. inputStream = new StreamReader(tcpClient.GetStream());
  81. outputStream = new StreamWriter(tcpClient.GetStream());
  82.  
  83. outputStream.WriteLine("PASS " + Password);
  84. outputStream.WriteLine("NICK " + Username);
  85. outputStream.WriteLine("USER " + Username + " 8 * :" + Username);
  86. outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  87. outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  88. outputStream.Flush();
  89. }
  90. public void JoinRoom(string Channel)
  91. {
  92. this.Channel = Channel;
  93. outputStream.WriteLine("JOIN #" + Channel);
  94. outputStream.Flush();
  95. }
  96.  
  97. public void LeaveRoom()
  98. {
  99. outputStream.Close();
  100. inputStream.Close();
  101. }
  102.  
  103. public void sendIrcMessage(string Message)
  104. {
  105. outputStream.WriteLine(Message);
  106. outputStream.Flush();
  107. }
  108.  
  109. public void sendChatMessage(string Message)
  110. {
  111. sendIrcMessage(":" + Username + "!" + Username + "@" + Username + ".tmi.twitch.tv PRIVMSG #" + Channel + " :" + Message);
  112. }
  113.  
  114. public void PingResponse()
  115. {
  116. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  117. }
  118.  
  119. public string readMessage()
  120. {
  121. string Message = "";
  122. Message = inputStream.ReadLine();
  123. return Message;
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement