linkxs

Untitled

Mar 30th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. import java.io.BufferedInputStream;
  2. import java.io.PrintWriter;
  3. import java.net.Socket;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class main {
  8. static String VERSION = "1.1";
  9.  
  10. static boolean DEBUG = true;
  11. static String SERVER = "irc.freenode.net";
  12. static int PORT = 6667;
  13. static String NICK = "buttbott";
  14. static String OWNER = "linkxs";
  15. static String USER = NICK
  16. + " 0 * : Ima bott you in the mouth! ("
  17. + OWNER + ")";
  18. static ArrayList<String> CHANNELS = new ArrayList<String>();
  19.  
  20. static Socket cs = null;
  21. static private Scanner sin = null;
  22. static private PrintWriter sout = null;
  23.  
  24. public static void main(String args[]) {
  25. if (DEBUG) {
  26. CHANNELS.add("#testgradius");
  27. CHANNELS.add("#botters-test");
  28. CHANNELS.add("##wrccdc");
  29. startMe();
  30. }
  31. if (args.length < 1 && !DEBUG)
  32. System.out
  33. .println("Wrong usage.\n\tjava -jar imabot.jar [channel]");
  34. else if (args.length >= 1) {
  35. try {
  36. for (int i = 0; i < args.length; i++) {
  37. CHANNELS.add("#" + args[i]);
  38. }
  39. startMe();
  40. } catch (Exception e) {
  41. System.out
  42. .println("Wrong usage.\n\tjava -jar imabot.jar [channel]");
  43. }
  44. }
  45. }
  46.  
  47. static boolean startMe() {
  48. try {
  49. cs = new Socket(SERVER, PORT);
  50. sout = new PrintWriter(cs.getOutputStream());
  51. sin = new Scanner(new BufferedInputStream(cs.getInputStream()));
  52.  
  53. sout.print("NICK " + NICK + "\r\n");
  54. sout.print("USER " + USER + "\r\n");
  55. sout.flush();
  56. sout.print("PRIVMSG nickserv :identify whataFUCKINGfatOassOWodForthisBot\r\n");
  57. sout.flush();
  58. for (String s : CHANNELS) {
  59. sout.print("JOIN " + s + "\r\n");
  60. }
  61. sout.flush();
  62. while (true) {
  63. String temp = sin.nextLine();
  64. System.out.println(temp);
  65. if (temp.contains("PING")) {
  66. temp.replace("PING", "PONG");
  67. sout.print(temp + "\r\n");
  68. sout.flush();
  69. } else if (temp.contains(":&")) {
  70. if (temp.startsWith(":[email protected]")) {
  71. System.err.println(" >>> Obey the master!");
  72. execute(temp.substring(temp.indexOf('&')), temp);
  73. } else {
  74. unPrivedExec(temp.substring(temp.indexOf('&')), temp);
  75. }
  76. } else if (temp.contains("buttbott :VERSION")) {
  77. String tchan = temp.substring(1, temp.indexOf("!"));
  78. sout.print("PRIVMSG " + tchan + " :I am versionless v "
  79. + VERSION + "\r\n");
  80. sout.flush();
  81. } else if (temp.contains("who is ")) {
  82. System.err.println(" >>> Faggot message.");
  83. try {
  84. String tchan = temp.substring(
  85. temp.indexOf("PRIVMSG ") + 8, temp.indexOf(' ',
  86. temp.indexOf("PRIVMSG ") + 10));
  87. System.err.println("\t" + tchan + " is channell. 1: "
  88. + temp.indexOf('?', temp.indexOf("who is "))
  89. + " 2:"
  90. + temp.indexOf(' ', temp.indexOf("who is "))
  91. + 8);
  92. String tnick = "";
  93. if (temp.indexOf('?', temp.indexOf("who is ")) > 0
  94. && (temp.indexOf('?', temp.indexOf("who is ")) < temp
  95. .indexOf('\n',
  96. temp.indexOf("who is ") + 8) || (temp
  97. .indexOf('?', temp.indexOf("who is ")) < temp
  98. .indexOf(' ',
  99. temp.indexOf("who is ") + 8)))) {
  100. tnick = temp
  101. .substring(
  102. temp.indexOf("who is ") + 7,
  103. temp.indexOf('?',
  104. temp.indexOf("who is ")) - 1);
  105. System.err.println("A");
  106. } else if (temp.indexOf('!', temp.indexOf("who is ")) > 0
  107. && (temp.indexOf('!', temp.indexOf("who is ")) < temp
  108. .indexOf('\n',
  109. temp.indexOf("who is ") + 8) || temp
  110. .indexOf('!', temp.indexOf("who is ")) < temp
  111. .indexOf(' ',
  112. temp.indexOf("who is ") + 8))) {
  113. tnick = temp
  114. .substring(
  115. temp.indexOf("who is ") + 7,
  116. temp.indexOf('!',
  117. temp.indexOf("who is ")) - 1);
  118. System.err.println("B");
  119. } else if (temp.indexOf(' ',
  120. temp.indexOf("who is ") + 7) > 0) {
  121. tnick = temp.substring(temp.indexOf("who is ") + 7,
  122. temp.indexOf(' ',
  123. temp.indexOf("who is ") + 8));
  124. System.err.println("C");
  125. } else {
  126. tnick = temp.substring(temp.indexOf("who is ") + 7);
  127. System.err.println("D");
  128. }
  129. System.err.println("\ttnick: " + tnick);
  130.  
  131. if (tnick.contains(NICK)) {
  132. sout.print("PRIVMSG " + tchan + " :"
  133. + "I am a faggot.\r\n");
  134. } else if (tnick.equals(OWNER)) {
  135. sout.print("PRIVMSG " + tchan + " :"
  136. + "According to my tests, " + OWNER
  137. + " isn't a faggot.\r\n");
  138. } else {
  139. sout.print("PRIVMSG " + tchan + " :" + tnick
  140. + " is a faggot.\r\n");
  141. }
  142. sout.flush();
  143. } catch (Exception e) {
  144. System.err
  145. .println("Things broke. bad substring in faggot?");
  146. }
  147. }
  148. }
  149. } catch (Exception e) {
  150. e.printStackTrace();
  151. }
  152. return false;
  153. }
  154.  
  155. static boolean unPrivedExec(String command, String line) {
  156. if (command.contains("version") || command.contains("VERSION")) {
  157. System.err.println("\tLooks like it's version");
  158. String tchan = line.substring(line.indexOf("PRIVMSG ") + 8,
  159. line.indexOf(' ', line.indexOf(":&") - 1));
  160. sout.print("PRIVMSG " + tchan + " :I am versionless.\r\n");
  161. sout.flush();
  162. }
  163. return false;
  164. }
  165.  
  166. static boolean execute(String command, String line) {
  167. System.err.println("\t\tCommand is " + command);
  168. if (command.contains("quit")) {
  169. try {
  170. String tchan = line.substring(line.indexOf("PRIVMSG ") + 8,
  171. line.indexOf(' ', line.indexOf(":&") - 1));
  172. System.err.println("\t\tLooks like it's quit");
  173. sout.print("PRIVMSG " + tchan + " :bye!\r\n");
  174. sout.flush();
  175. } catch (Exception e) {
  176. System.err.println("Things broke. bad substring in &quit?");
  177. }
  178. System.exit(0);
  179.  
  180. } else if (command.contains("restart")) {
  181. System.err.println("\t\tRestarting..");
  182. try {
  183. cs.close();
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. }
  187. startMe();
  188. return true;
  189. }
  190. unPrivedExec(command, line);
  191. return false;
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment