Advertisement
Guest User

try this

a guest
Sep 5th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.32 KB | None | 0 0
  1. package dpp;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStreamWriter;
  7. import java.io.PrintWriter;
  8. import java.net.Socket;
  9. import java.net.URL;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. public class Bot {
  13.  
  14.     public static String IRC_SERVER = "", IRC_PASSWORD = "", IRC_USERNAME = "",
  15.             str = "";
  16.     public static int IRC_PORT = 6667;
  17.     public static PrintWriter o;
  18.     public static Socket s;
  19.     public static BufferedReader i;
  20.     public static List activeQueue = new ArrayList();
  21.  
  22.     public static String SendCommand(String username, String command, int bm, String mode)
  23.             throws IOException, InterruptedException {
  24.         activeQueue.add(username);
  25.         URL oracle = new URL("http://192.168.0.100/bot/osu_ripple.php?k=routine&command=" + command + "&b=" + bm + "&u=" + username + "&m=" + mode);
  26.         BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
  27.         String inputLine;
  28.         while ((inputLine = in.readLine()) != null)
  29.             return inputLine;
  30.         in.close();
  31.         activeQueue.remove(username);
  32.         return inputLine;
  33.     }
  34.  
  35.     public static void main(String[] args) throws IOException, InterruptedException {
  36.         s = new Socket(IRC_SERVER, IRC_PORT);
  37.         i = new BufferedReader(new InputStreamReader(s.getInputStream()));
  38.         o = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
  39.         o.print("PASS " + IRC_PASSWORD + "\r\n");
  40.         o.print("USER " + IRC_USERNAME + " 0 * :" + IRC_USERNAME + "\r\n" + "NICK " + IRC_USERNAME + "\r\n");
  41.         //o.print("JOIN #bulgarian" + "\r\n");
  42.         o.flush();
  43.         if (s.isConnected())
  44.             System.out.println("Connected!");
  45.         while (s.isConnected()) {
  46.             str = i.readLine();
  47.             //System.out.println(str);
  48.             if (str.startsWith("PING")) {
  49.                 o.print("PONG " + str.substring(5) + "\r\n");
  50.                 o.flush();
  51.             }
  52.             if (str.charAt(0) != ':')
  53.                 continue;
  54.             if (str.split(" ")[1].equals("PRIVMSG")) {
  55.                 String USERNAME = str.split("!")[0].substring(1);
  56.                 USERNAME = USERNAME.split("\\s+")[0];
  57.                 USERNAME = USERNAME.split(":")[0];
  58.                 String[] split = str.split("!");
  59.                 if (str.split(":")[2].contains("listening") || str.split(":")[2].contains("playing")
  60.                         || str.split(":")[2].contains("watching")) {
  61.                     if (str.contains("http://osu.ppy.sh/b/") || str.contains("https://osu.ppy.sh/b/")) {
  62.                         int bm = Integer.parseInt(str.split("osu.ppy.sh/b/")[1].split(" ")[0]);
  63.                         o.print("PRIVMSG " + USERNAME + " :"
  64.                                 + SendCommand(USERNAME, "np", bm, "0")
  65.                                 + "\r\n");
  66.                         o.flush();
  67.                     }
  68.                     TimeUnit.SECONDS.sleep(3);
  69.                 }
  70.                 if (str.split(":")[2].startsWith("!mode")) {
  71.                     String[] split1 = str.split("!mode");
  72.                     if (split1.length > 1 && !split1[1].isEmpty()) {
  73.                         String usr = str.split("!mode ", -1)[1];
  74.                         o.print("PRIVMSG " + USERNAME + " :" + SendCommand(USERNAME, "mode", 0, usr) + "\r\n");
  75.                         o.flush();
  76.                     }
  77.                     TimeUnit.SECONDS.sleep(3);
  78.                 } else {
  79.                     if (str.split(":")[2].startsWith("!")) {
  80.                         if (split.length > 1 && !split[1].isEmpty()) {
  81.                             String COMMAND = str.split("!")[1];
  82.                             if (activeQueue.contains(USERNAME)) {
  83.                                 // Active Queue
  84.                             } else {
  85.                                 o.print("PRIVMSG " + USERNAME + " :" + SendCommand(USERNAME, COMMAND, 0, "") + "\n");
  86.                                 o.flush();
  87.                             }
  88.                         }
  89.                     }
  90.                     TimeUnit.SECONDS.sleep(3);
  91.                 }
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement