Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TPU;
- import java.net.*;
- import java.awt.*;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.io.*;
- import java.lang.reflect.Field;
- import java.lang.reflect.Modifier;
- import java.util.LinkedList;
- /**
- *
- * @author Laptop
- */
- public class TPWinXP {
- static String pass = "oauth:ucq1bt9ymd14kp0b90ewhn2vsovwm4";
- static String username = "razorsharpfang";
- static double restart = 100;
- static double nRestart = 150;
- static long keyTD = 500;
- static Robot robot;
- // default keyTime
- static int autoDelay = 20;
- // default auto delay of robot
- public static void main(String[] args) {
- while(true) {
- try {
- TPMC();
- }
- catch(Exception e) {
- System.out.println("Whoops.");
- System.out.println(e);
- }
- }
- }
- public static void TPMC() throws Exception {
- Socket socket = null;
- BufferedWriter output = null;
- LineNumberReader input = null;
- String command = null;
- String user = null;
- robot = null;
- //long restartTime = System.currentTimeMillis();
- long pingTime = System.currentTimeMillis();
- LinkedList<KeyDuration> keyList = new LinkedList();
- //double speed = 100;
- try {
- robot = new Robot();
- socket = new Socket(InetAddress.getByName("irc.twitch.tv"),6667);
- //socket.connect(socket.getRemoteSocketAddress());
- //System.out.println("We have created a socket!");
- output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
- input = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
- //System.out.println("We have allocated our writers and readers");
- output.write("PASS "+pass+"\n\r");
- output.write("NICK "+username+"\n\r");
- output.write("JOIN #razorsharpfang\n\r");
- output.flush();
- //System.out.println("We have passed our credentials!");
- output.write("PRIVMSG #razorsharpfang :TPWinXP Bot ONLINE!!\n\r");
- output.flush();
- }
- catch(Exception e) {
- System.out.println("We had trouble setting up....");
- System.out.println(e.getMessage());
- Thread.sleep(1000);
- return;
- }
- robot.setAutoDelay(autoDelay);
- long previous = System.currentTimeMillis();
- //long delta;
- Point p = MouseInfo.getPointerInfo().getLocation();
- int mouseX=0;
- int mouseY=0;
- // these two variables hold the amount that the mouse needs to move
- while(true) {
- //10 milliseconds is desired.
- if(System.currentTimeMillis() < previous + 10) {
- Thread.sleep(10 - (System.currentTimeMillis() - previous));
- }
- //delta = System.currentTimeMillis() - previous;
- previous = System.currentTimeMillis();
- try {
- // this should release any keys that are scheduled to be released
- for(KeyDuration kd : keyList) {
- if(System.currentTimeMillis() > kd.time) {
- robot.keyRelease(kd.keycode);
- keyList.remove(kd);
- }
- }
- // move the mouse 20% of the distance between it and the destination
- p = MouseInfo.getPointerInfo().getLocation();
- if((Math.abs(mouseX) <= 1) && (Math.abs(mouseY) <= 1)) {
- //robot.mouseMove(p.x + mouseX, p.y + mouseY);
- //mouseX = 0;
- //mouseY = 0;
- }
- else {
- int dX = (int)Math.ceil(mouseX*0.05);
- int dY = (int)Math.ceil(mouseY*0.05);
- mouseX -= dX;
- mouseY -= dY;
- robot.mouseMove(dX + p.x,p.y + dY);
- }
- //System.out.printf("[%d,%d,%d]\n",mouseX,mouseY,delta);
- if(System.currentTimeMillis() > pingTime + 300000) {
- output.write("PRIVMSG #RAZORSHARPFANG :Bot is unsure if it's online.\n\r");
- output.flush();
- pingTime = System.currentTimeMillis();
- }
- if(socket.isConnected()) {
- //System.out.println("We are connected...");
- if(input.ready()) {
- while(input.ready()) {
- command = input.readLine();
- if(command.contains("PING")) {
- output.write("PONG :"+command.split(":")[1]+"\n\r");
- System.out.println("PONG :"+command.split(":")[1]);
- output.flush();
- pingTime = System.currentTimeMillis();
- }
- if(command.contains("PRIVMSG")) { // ignore this.
- user = command.split(":")[1];
- user = user.split("!")[0];
- command = command.toUpperCase();
- command = command.substring(command.indexOf(":")+1);
- command = command.substring(command.indexOf(":")+1);
- if(command.indexOf('!') == 0) {
- // This is a command, parse it as a command.
- command = command.substring(1);
- System.out.print(user + ": ");
- try {
- String[] commands = command.split(" ");
- if(commands[0].equals("KEY")) {
- // Keyboard command
- System.out.print("KEY ");
- if(commands[1].equals("PRESS")) {
- // Press a key for a tiny duration
- System.out.print("PRESS "+commands[2]);
- int key = GetKey(commands[2]);
- robot.keyPress(key);
- try {
- long duration = Long.parseLong(commands[3]);
- KeyDuration kD = new KeyDuration(key,duration + System.currentTimeMillis());
- keyList.add(kD);
- System.out.print(duration);
- }
- catch(Exception e) {
- robot.keyRelease(key);
- }
- }
- else if(commands[1].equals("DOWN")) {
- // Hold down a key
- System.out.print("DOWN "+commands[2]);
- int key = GetKey(commands[2]);
- robot.keyPress(key);
- }
- else if(commands[1].equals("UP")) {
- // Release a held key
- System.out.print("UP "+commands[2]);
- if(commands[2].equals("ALL")) {
- Field[] fields = KeyEvent.class.getDeclaredFields();
- for(Field field : fields) {
- try {
- if(Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()))
- robot.keyRelease(field.getInt(null));
- }
- catch(Exception e) {
- ;// catch and throw away
- }
- }
- }
- else {
- int key = GetKey(commands[2]);
- robot.keyRelease(key);
- }
- }
- else {
- throw new Exception("Invalid argument, must be one of the following: { press, down, up }");
- }
- }
- else if(commands[0].equals("MOUSE")) {
- System.out.print("MOUSE ");
- // Mouse command
- if(commands[1].equals("MOVE")) {
- System.out.print("MOVE ");
- int distance;
- if(commands[2].equals("UP")) {
- System.out.print("UP");
- if(commands.length > 3) {
- distance = Integer.parseInt(commands[3]);
- }
- else {
- distance = 50;
- }
- mouseY += -distance;
- }
- else if(commands[2].equals("DOWN")) {
- System.out.print("DOWN");
- if(commands.length > 3) {
- distance = Integer.parseInt(commands[3]);
- }
- else {
- distance = 50;
- }
- mouseY += distance;
- }
- else if(commands[2].equals("LEFT")) {
- System.out.print("LEFT");
- if(commands.length > 3) {
- distance = Integer.parseInt(commands[3]);
- }
- else {
- distance = 50;
- }
- mouseX += -distance;
- }
- else if(commands[2].equals("RIGHT")) {
- System.out.print("RIGHT");
- if(commands.length > 3) {
- distance = Integer.parseInt(commands[3]);
- }
- else {
- distance = 50;
- }
- mouseX += distance;
- }
- else {
- throw new Exception("Direction required, must be one of the following: { up, down, left, right }");
- }
- }
- else if(commands[1].equals("BUTTON")) {
- System.out.print("BUTTON ");
- if(commands[2].equals("CLICK")) {
- System.out.print("CLICK ");
- if(commands[3].equals("LEFT")) {
- System.out.print("LEFT ");
- robot.mousePress(MouseEvent.BUTTON1_MASK);
- robot.mouseRelease(MouseEvent.BUTTON1_MASK);
- }
- else if(commands[3].equals("RIGHT")) {
- System.out.print("RIGHT ");
- robot.mousePress(MouseEvent.BUTTON3_MASK);
- robot.mouseRelease(MouseEvent.BUTTON3_MASK);
- }
- else if(commands[3].equals("MIDDLE")) {
- System.out.print("MIDDLE");
- robot.mousePress(MouseEvent.BUTTON2_MASK);
- robot.mouseRelease(MouseEvent.BUTTON2_MASK);
- }
- else {
- throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
- }
- }
- else if(commands[2].equals("DOWN")) {
- System.out.print("CLICK ");
- if(commands[3].equals("LEFT")) {
- System.out.print("LEFT ");
- robot.mousePress(MouseEvent.BUTTON1_MASK);
- }
- else if(commands[3].equals("RIGHT")) {
- System.out.print("RIGHT ");
- robot.mousePress(MouseEvent.BUTTON3_MASK);
- }
- else if(commands[3].equals("MIDDLE")) {
- System.out.print("MIDDLE");
- robot.mousePress(MouseEvent.BUTTON2_MASK);
- }
- else {
- throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
- }
- }
- else if(commands[2].equals("UP")) {
- System.out.print("UP ");
- if(commands[3].equals("LEFT")) {
- System.out.print("LEFT ");
- robot.mouseRelease(MouseEvent.BUTTON1_MASK);
- }
- else if(commands[3].equals("RIGHT")) {
- System.out.print("RIGHT ");
- robot.mouseRelease(MouseEvent.BUTTON3_MASK);
- }
- else if(commands[3].equals("MIDDLE")) {
- System.out.print("MIDDLE");
- robot.mouseRelease(MouseEvent.BUTTON2_MASK);
- }
- else {
- throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
- }
- }
- else {
- throw new Exception("Invalid argument for mouse button action, must be one of these: { click, down, up }");
- }
- }
- else if(commands[1].equals("SCROLL")) {
- System.out.print("SCROLL ");
- if(commands[2].equals("UP")) {
- System.out.print("UP");
- robot.mouseWheel(-1);
- }
- else if(commands[2].equals("DOWN")) {
- System.out.print("DOWN");
- robot.mouseWheel(1);
- }
- else {
- throw new Exception("Invalid argument for scroll action, must be one of the following: { up, down }");
- }
- }
- else {
- throw new Exception("Invalid argument for mouse : Must be one of the following : { move, button, scroll }");
- }
- }
- else if(commands[0].equals("RESTART")) {
- ;
- }
- else if(commands[0].equals("Y")) {
- ;
- }
- else if(commands[0].equals("N")) {
- ;
- }
- else {
- throw new Exception("Not a valid command. Must be one of { key, mouse} ");
- }
- }
- catch(ArrayIndexOutOfBoundsException e) {
- output.write("PRIVMSG #RAZORSHARPFANG :@"+user+ ":" +" Not enough arguments for that command.\n\r");
- output.flush();
- System.out.println("OH DEAR, OUT OF BOUNDS! D:");
- System.out.println(e);
- }
- catch(Exception e) {
- output.write("PRIVMSG #RAZORSHARPFANG :@"+user + ":" + e.getMessage()+"\n\r");
- output.flush();
- System.out.println(e);
- System.out.println(e.getMessage());
- }
- System.out.print(";");
- System.out.println();
- }
- }
- }
- }
- }
- else {
- System.out.println("Not connected, restarting...");
- return;
- }
- output.flush();
- }
- catch(IOException e) {
- System.out.println("CRITICAL ERROR!");
- System.out.println(e);
- System.out.println("BOT RESTARTING!");
- }
- catch(Exception e) {
- System.out.println("That didn't work.");
- System.out.println(e);
- }
- }
- }
- static int GetKey(String s) throws Exception {
- int key = 0;
- switch(s) {
- case "ESC":
- key = KeyEvent.VK_ESCAPE;
- break;
- case "F1":
- key = KeyEvent.VK_F1;
- break;
- case "F2":
- key = KeyEvent.VK_F2;
- break;
- case "F3":
- key = KeyEvent.VK_F3;
- break;
- case "F4":
- key = KeyEvent.VK_F4;
- break;
- case "F5":
- key = KeyEvent.VK_F5;
- break;
- case "F6":
- key = KeyEvent.VK_F6;
- break;
- case "F7":
- key = KeyEvent.VK_F7;
- break;
- case "F8":
- key = KeyEvent.VK_F8;
- break;
- case "F9":
- key = KeyEvent.VK_F9;
- break;
- case "F10":
- key = KeyEvent.VK_F10;
- break;
- case "F11":
- key = KeyEvent.VK_F11;
- break;
- case "F12":
- key = KeyEvent.VK_F12;
- break;
- case "INSERT":
- key = KeyEvent.VK_INSERT;
- break;
- case "DELETE":
- key = KeyEvent.VK_DELETE;
- break;
- // first row
- case "`":
- key = KeyEvent.VK_BACK_QUOTE;
- break;
- case "1":
- key = KeyEvent.VK_1;
- break;
- case "2":
- key = KeyEvent.VK_2;
- break;
- case "3":
- key = KeyEvent.VK_3;
- break;
- case "4":
- key = KeyEvent.VK_4;
- break;
- case "5":
- key = KeyEvent.VK_5;
- break;
- case "6":
- key = KeyEvent.VK_6;
- break;
- case "7":
- key = KeyEvent.VK_7;
- break;
- case "8":
- key = KeyEvent.VK_8;
- break;
- case "9":
- key = KeyEvent.VK_9;
- break;
- case "0":
- key = KeyEvent.VK_0;
- break;
- case "-":
- key = KeyEvent.VK_SUBTRACT;
- break;
- case "=":
- key = KeyEvent.VK_EQUALS;
- break;
- case "BACKSPACE":
- key = KeyEvent.VK_BACK_SPACE;
- break;
- // second row
- case "TAB":
- key = KeyEvent.VK_TAB;
- break;
- case "Q":
- key = KeyEvent.VK_Q;
- break;
- case "W":
- key = KeyEvent.VK_W;
- break;
- case "E":
- key = KeyEvent.VK_E;
- break;
- case "R":
- key = KeyEvent.VK_R;
- break;
- case "T":
- key = KeyEvent.VK_T;
- break;
- case "Y":
- key = KeyEvent.VK_Y;
- break;
- case "U":
- key = KeyEvent.VK_U;
- break;
- case "I":
- key = KeyEvent.VK_I;
- break;
- case "O":
- key = KeyEvent.VK_O;
- break;
- case "P":
- key = KeyEvent.VK_P;
- break;
- case "[":
- key = KeyEvent.VK_OPEN_BRACKET;
- break;
- case "]":
- key = KeyEvent.VK_CLOSE_BRACKET;
- break;
- case "\\":
- key = KeyEvent.VK_BACK_SLASH;
- break;
- // third row
- case "CAPSLOCK":
- key = KeyEvent.VK_CAPS_LOCK;
- break;
- case "A":
- key = KeyEvent.VK_A;
- break;
- case "S":
- key = KeyEvent.VK_S;
- break;
- case "D":
- key = KeyEvent.VK_D;
- break;
- case "F":
- key = KeyEvent.VK_F;
- break;
- case "G":
- key = KeyEvent.VK_G;
- break;
- case "H":
- key = KeyEvent.VK_H;
- break;
- case "J":
- key = KeyEvent.VK_J;
- break;
- case "K":
- key = KeyEvent.VK_K;
- break;
- case "L":
- key = KeyEvent.VK_L;
- break;
- case ";":
- key = KeyEvent.VK_SEMICOLON;
- break;
- case "'":
- key = KeyEvent.VK_QUOTE;
- break;
- case "ENTER":
- key = KeyEvent.VK_ENTER;
- break;
- //forth row?
- case "SHIFT":
- key = KeyEvent.VK_SHIFT;
- break;
- case "Z":
- key = KeyEvent.VK_Z;
- break;
- case "X":
- key = KeyEvent.VK_X;
- break;
- case "C":
- key = KeyEvent.VK_C;
- break;
- case "V":
- key = KeyEvent.VK_V;
- break;
- case "B":
- key = KeyEvent.VK_B;
- break;
- case "N":
- key = KeyEvent.VK_N;
- break;
- case "M":
- key = KeyEvent.VK_M;
- break;
- case ",":
- key = KeyEvent.VK_COMMA;
- break;
- case ".":
- key = KeyEvent.VK_PERIOD;
- break;
- case "/":
- key = KeyEvent.VK_SLASH;
- break;
- //NO RIGHT SHIFT KEY
- //Fifth row?
- case "CONTROL":
- key = KeyEvent.VK_CONTROL;
- break;
- case "WINDOWS":
- key = KeyEvent.VK_WINDOWS;
- break;
- case "ALT":
- key = KeyEvent.VK_ALT;
- break;
- case "SPACE":
- key = KeyEvent.VK_SPACE;
- break;
- case "UP":
- key = KeyEvent.VK_UP;
- break;
- case "DOWN":
- key = KeyEvent.VK_DOWN;
- break;
- case "LEFT":
- key = KeyEvent.VK_LEFT;
- break;
- case "RIGHT":
- key = KeyEvent.VK_RIGHT;
- break;
- //no repeats
- // extras?
- case "HOME":
- key = KeyEvent.VK_HOME;
- break;
- case "END":
- key = KeyEvent.VK_END;
- break;
- case "PAGEUP":
- key = KeyEvent.VK_PAGE_UP;
- break;
- case "PAGEDOWN":
- key = KeyEvent.VK_PAGE_DOWN;
- break;
- case "PRINTSCREEN":
- key = KeyEvent.VK_PRINTSCREEN;
- break;
- case "BREAK":
- key = KeyEvent.VK_CANCEL;
- break;
- case "PAUSE":
- key = KeyEvent.VK_PAUSE;
- break;
- case "SCROLLLOCK":
- key = KeyEvent.VK_SCROLL_LOCK;
- break;
- default:
- throw new Exception("Invalid command, no such key: "+s);
- //break;
- }
- return key;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement