Advertisement
Guest User

some bot

a guest
May 23rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 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 ChatBot
  20. {
  21. public partial class Form1 : Form
  22. {
  23. #region Variables
  24. private static string userName = "NameOfMyBotAcc";
  25. private static string password = "oauth******";
  26.  
  27.  
  28.  
  29. IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  30. NetworkStream serverStream = default(NetworkStream);
  31. string readData = "";
  32. Thread chatThread;
  33. #endregion
  34.  
  35. public Form1()
  36. {
  37. InitializeComponent();
  38. }
  39. private void Form1_Load(object sender, EventArgs e)
  40. {
  41. irc.joinRoom("NameOfMyMainAcc");
  42. chatThread = new Thread(getMessage);
  43. chatThread.Start();
  44. }
  45. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  46. {
  47. irc.leaveRoom();
  48. serverStream.Dispose();
  49. Environment.Exit(0);
  50. }
  51.  
  52. private void getMessage()
  53. {
  54. serverStream = irc.tcpClient.GetStream();
  55. int buffsize = 0;
  56. byte[] intStream = new byte[10025];
  57. buffsize = irc.tcpClient.ReceiveBufferSize;
  58. while (true)
  59. {
  60. try
  61. {
  62. readData = irc.readMessage();
  63. msg();
  64. }
  65. catch(Exception e)
  66. {
  67.  
  68. }
  69. }
  70. }
  71.  
  72. private void msg()
  73. {
  74. if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  75. else chatBox.Text = chatBox.Text + readData.ToString() + Environment.NewLine;
  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. public void joinRoom(string channel)
  103. {
  104. this.channel = channel;
  105. outputStream.WriteLine("JOIN #" + channel);
  106. outputStream.Flush();
  107. }
  108.  
  109. public void leaveRoom()
  110. {
  111. outputStream.Close();
  112. inputStream.Close();
  113. }
  114.  
  115. public void sendIrcMessage(string message)
  116. {
  117. outputStream.WriteLine(message);
  118. outputStream.Flush();
  119. }
  120.  
  121. public void sendChatMessage(string message)
  122. {
  123. sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  124. }
  125.  
  126. public void PingResponse()
  127. {
  128. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  129. }
  130.  
  131. public string readMessage()
  132. {
  133. string message = "";
  134. message = inputStream.ReadLine();
  135. return message;
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement