Guest User

Untitled

a guest
Jul 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using System.IO;
  5. using System.Threading;
  6.  
  7.  
  8. class IrcBot
  9. {
  10. // Irc server to connect
  11. public static string SERVER = "snext.serveirc.com";
  12.  
  13. private static int PORT = 6667;
  14.  
  15. private static string USER = "USER predsbot 8 * :I'm a C# irc bot";
  16.  
  17. private static string NICK = "Licos";
  18.  
  19. private static string CHANNEL = "#preds";
  20.  
  21. // StreamWriter is declared here so that PingSender can access it
  22. public static StreamWriter writer;
  23.  
  24. static void Main(string[] args)
  25. {
  26. NetworkStream stream;
  27. TcpClient irc;
  28. string inputLine;
  29. StreamReader reader;
  30.  
  31. try
  32. {
  33. irc = new TcpClient(SERVER, PORT);
  34. stream = irc.GetStream();
  35. reader = new StreamReader(stream);
  36. writer = new StreamWriter(stream);
  37.  
  38. // Start PingSender thread
  39. PingSender ping = new PingSender();
  40. ping.Start();
  41.  
  42. writer.WriteLine(USER);
  43. writer.Flush();
  44. writer.WriteLine("NICK " + NICK);
  45. Thread.Sleep(2000);
  46. writer.Flush();
  47. writer.WriteLine("JOIN " + CHANNEL);
  48. writer.Flush();
  49.  
  50. while (true)
  51. {
  52. while ((inputLine = reader.ReadLine()) != null)
  53. {
  54.  
  55.  
  56. Console.WriteLine(inputLine);
  57. if (inputLine.EndsWith("licos about"))
  58. {
  59. writer.WriteLine("PRIVMSG " + CHANNEL + " :LicosBot V1.0, Creator preds rule");
  60. writer.Flush();
  61. Thread.Sleep(2000);
  62. }
  63. if (inputLine.Contains("licos shutdown"))
  64. {
  65. string[] splitArray = inputLine.Split(new char[] { ':' });
  66. string[] splitArray2 = splitArray[1].Split(new char[] { '!' });
  67. string[] splitArray3 = splitArray2[1].Split(new char[] { ' ' });
  68. string compmsg = "";
  69. string nick = splitArray2[0];
  70. string message = compmsg;
  71. if (nick.ToLower() == "predsrule")
  72. writer.WriteLine("PRIVMSG " + CHANNEL + " :Shutting Down...");
  73. writer.Flush();
  74. Thread.Sleep(2000);
  75. Environment.Exit(0);
  76. }
  77. if (inputLine.EndsWith("licos"))
  78. {
  79. writer.WriteLine("PRIVMSG " + CHANNEL + " :LicosBot Online");
  80. writer.Flush();
  81. Thread.Sleep(2000);
  82. }
  83. if (inputLine.EndsWith("licos fail"))
  84. {
  85. writer.WriteLine("PRIVMSG " + CHANNEL + " :i'm a failure");
  86. writer.Flush();
  87. Thread.Sleep(2000);
  88. }
  89. if (inputLine.Contains("licos mshutdown"))
  90. {
  91. string[] splitArray = inputLine.Split(new char[] { ':' });
  92. string[] splitArray2 = splitArray[1].Split(new char[] { '!' });
  93. string[] splitArray3 = splitArray2[1].Split(new char[] { ' ' });
  94. string compmsg = "";
  95. string nick = splitArray2[0];
  96. string message = compmsg;
  97. if (nick.ToLower() == "predsrule")
  98. writer.WriteLine("PRIVMSG " + CHANNEL + " :Shutting Down for Maintenance...");
  99. writer.WriteLine("PRIVMSG " + CHANNEL + " :Back in 5 Minutes");
  100. writer.Flush();
  101. Thread.Sleep(2000);
  102. Environment.Exit(0);
  103. }
  104. if (inputLine.EndsWith("licos pray"))
  105. {
  106. writer.WriteLine("PRIVMSG " + CHANNEL + " :The Programmers Prayer");
  107. writer.WriteLine("PRIVMSG " + CHANNEL + " :Our Program who are in Memory.");
  108. writer.WriteLine("PRIVMSG " + CHANNEL + " :Hello by thy Name.");
  109. writer.WriteLine("PRIVMSG " + CHANNEL + " :Thy Operating System come.");
  110. writer.WriteLine("PRIVMSG " + CHANNEL + " :Thy Commands be done at the Printer as it is on the Screen.");
  111. writer.WriteLine("PRIVMSG " + CHANNEL + " :Give us this day our daily Data,");
  112. writer.WriteLine("PRIVMSG " + CHANNEL + " :And forgive us our I/O errors");
  113. writer.WriteLine("PRIVMSG " + CHANNEL + " :As we forgive those whose logic circuits are faulty.");
  114. writer.WriteLine("PRIVMSG " + CHANNEL + " :Lead us not into frustration, and deliver us from Power Surges.");
  115. writer.WriteLine("PRIVMSG " + CHANNEL + " :For Thine is the Algorithm,");
  116. writer.WriteLine("PRIVMSG " + CHANNEL + " :The Application,");
  117. writer.WriteLine("PRIVMSG " + CHANNEL + " :And the Solution");
  118. writer.WriteLine("PRIVMSG " + CHANNEL + " :Looping forever and ever.");
  119. writer.WriteLine("PRIVMSG " + CHANNEL + " :Return");
  120. writer.Flush();
  121. Thread.Sleep(2000);
  122. }
  123. if (inputLine.Contains("{say} fail"))
  124. {
  125. writer.WriteLine("PRIVMSG " + CHANNEL + " :You Fail");
  126. writer.Flush();
  127. Thread.Sleep(2000);
  128. }
  129. if (inputLine.Contains("Licos ns"))
  130. {
  131. writer.WriteLine("PRIVMSG NickServ :identify jamie51822");
  132. writer.Flush();
  133. Thread.Sleep(2000);
  134. }
  135. }
  136.  
  137. // Close all streams
  138. writer.Close();
  139. reader.Close();
  140. irc.Close();
  141. }
  142. }
  143. catch (Exception e)
  144. {
  145. // Show the exception, sleep for a while and try to establish a new connection to irc server
  146. Console.WriteLine(e.ToString());
  147. Thread.Sleep(5000);
  148. string[] argv = { };
  149. Main(argv);
  150. }
  151. }
  152. }
Add Comment
Please, Sign In to add comment