Advertisement
Guest User

Twitch Bot

a guest
Mar 23rd, 2015
1,799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ircclient
  4. {
  5. class MainClass
  6. {
  7. public static void Main(string[] args)
  8. {
  9. int port;
  10. string buf, nick, owner, server, chan;
  11. System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient();
  12. System.IO.TextReader input;
  13. System.IO.TextWriter output;
  14.  
  15. //Get pass, nick, owner, server, port, and channel from user
  16. Console.Write("Enter bot nick: ");
  17. nick = Console.ReadLine();
  18. Console.Write("Enter bot owner name: ");
  19. owner = Console.ReadLine();
  20. Console.Write("Enter server IP: ");
  21. server = Console.ReadLine();
  22. Console.Write("Enter port number: ");
  23. port = Convert.ToInt32(Console.ReadLine());
  24. Console.Write("Channel: ");
  25. chan = Console.ReadLine();
  26.  
  27. //Connect to irc server and get input and output text streams from TcpClient.
  28. sock.Connect(server, port);
  29. if (!sock.Connected)
  30. {
  31. Console.WriteLine("Failed to connect!");
  32. return;
  33. }
  34. input = new System.IO.StreamReader(sock.GetStream());
  35. output = new System.IO.StreamWriter(sock.GetStream());
  36.  
  37. //Starting USER and NICK login commands
  38. output.Write(
  39. "USER " + nick + " 0 * :" + owner + "\r\n" +
  40. "NICK " + nick + "\r\n" +
  41. "PASS " + "oauth:drg908drg03kdgr09drgi0drg90se" + "\r\n"
  42. );
  43. output.Flush();
  44.  
  45. //Process each line received from irc server
  46. for (buf = input.ReadLine(); ; buf = input.ReadLine())
  47. {
  48.  
  49. //Display received irc message
  50. Console.WriteLine(buf);
  51.  
  52. //Send pong reply to any ping messages
  53. if (buf.StartsWith("PING ")) { output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush(); }
  54. if (buf[0] != ':') continue;
  55.  
  56. /* IRC commands come in one of these formats:
  57. * :NICK!USER@HOST COMMAND ARGS ... :DATA\r\n
  58. * :SERVER COMAND ARGS ... :DATA\r\n
  59. */
  60.  
  61. //After server sends 001 command, we can set mode to bot and join a channel
  62. if (buf.Split(' ')[1] == "001")
  63. {
  64. output.Write(
  65. "MODE " + nick + " +B\r\n" +
  66. "JOIN " + chan + "\r\n"
  67. );
  68. output.Flush();
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement