Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. public class HackBot {
  5.  
  6. public static void main(String[] args) throws Exception {
  7.  
  8. // The server to connect to and our details.
  9. String server = "irc.freenode.net";
  10. String nick = "simple_bot";
  11. String login = "simple_bot";
  12.  
  13. // The channel which the bot will join.
  14. String channel = "#irchacks";
  15.  
  16. // Connect directly to the IRC server.
  17. Socket socket = new Socket(server, 6667);
  18. BufferedWriter writer = new BufferedWriter(
  19. new OutputStreamWriter(socket.getOutputStream( )));
  20. BufferedReader reader = new BufferedReader(
  21. new InputStreamReader(socket.getInputStream( )));
  22.  
  23. // Log on to the server.
  24. writer.write("NICK " + nick + "\r\n");
  25. writer.write("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
  26. writer.flush( );
  27.  
  28. // Read lines from the server until it tells us we have connected.
  29. String line = null;
  30. while ((line = reader.readLine( )) != null) {
  31. if (line.indexOf("004") >= 0) {
  32. // We are now logged in.
  33. break;
  34. }
  35. else if (line.indexOf("433") >= 0) {
  36. System.out.println("Nickname is already in use.");
  37. return;
  38. }
  39. }
  40.  
  41. // Join the channel.
  42. writer.write("JOIN " + channel + "\r\n");
  43. writer.flush( );
  44.  
  45. // Keep reading lines from the server.
  46. while ((line = reader.readLine( )) != null) {
  47. if (line.toLowerCase( ).startsWith("PING ")) {
  48. // We must respond to PINGs to avoid being disconnected.
  49. writer.write("PONG " + line.substring(5) + "\r\n");
  50. writer.write("PRIVMSG " + channel + " :I got pinged!\r\n");
  51. writer.flush( );
  52. }
  53. else {
  54. // Print the raw line received by the bot.
  55. System.out.println(line);
  56. }
  57. }
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement