Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedInputStream;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class main {
- static String VERSION = "1.1";
- static boolean DEBUG = true;
- static String SERVER = "irc.freenode.net";
- static int PORT = 6667;
- static String NICK = "buttbott";
- static String OWNER = "linkxs";
- static String USER = NICK
- + " 0 * : Ima bott you in the mouth! ("
- + OWNER + ")";
- static ArrayList<String> CHANNELS = new ArrayList<String>();
- static Socket cs = null;
- static private Scanner sin = null;
- static private PrintWriter sout = null;
- public static void main(String args[]) {
- if (DEBUG) {
- CHANNELS.add("#testgradius");
- CHANNELS.add("#botters-test");
- CHANNELS.add("##wrccdc");
- startMe();
- }
- if (args.length < 1 && !DEBUG)
- System.out
- .println("Wrong usage.\n\tjava -jar imabot.jar [channel]");
- else if (args.length >= 1) {
- try {
- for (int i = 0; i < args.length; i++) {
- CHANNELS.add("#" + args[i]);
- }
- startMe();
- } catch (Exception e) {
- System.out
- .println("Wrong usage.\n\tjava -jar imabot.jar [channel]");
- }
- }
- }
- static boolean startMe() {
- try {
- cs = new Socket(SERVER, PORT);
- sout = new PrintWriter(cs.getOutputStream());
- sin = new Scanner(new BufferedInputStream(cs.getInputStream()));
- sout.print("NICK " + NICK + "\r\n");
- sout.print("USER " + USER + "\r\n");
- sout.flush();
- sout.print("PRIVMSG nickserv :identify whataFUCKINGfatOassOWodForthisBot\r\n");
- sout.flush();
- for (String s : CHANNELS) {
- sout.print("JOIN " + s + "\r\n");
- }
- sout.flush();
- while (true) {
- String temp = sin.nextLine();
- System.out.println(temp);
- if (temp.contains("PING")) {
- temp.replace("PING", "PONG");
- sout.print(temp + "\r\n");
- sout.flush();
- } else if (temp.contains(":&")) {
- if (temp.startsWith(":[email protected]")) {
- System.err.println(" >>> Obey the master!");
- execute(temp.substring(temp.indexOf('&')), temp);
- } else {
- unPrivedExec(temp.substring(temp.indexOf('&')), temp);
- }
- } else if (temp.contains("buttbott :VERSION")) {
- String tchan = temp.substring(1, temp.indexOf("!"));
- sout.print("PRIVMSG " + tchan + " :I am versionless v "
- + VERSION + "\r\n");
- sout.flush();
- } else if (temp.contains("who is ")) {
- System.err.println(" >>> Faggot message.");
- try {
- String tchan = temp.substring(
- temp.indexOf("PRIVMSG ") + 8, temp.indexOf(' ',
- temp.indexOf("PRIVMSG ") + 10));
- System.err.println("\t" + tchan + " is channell. 1: "
- + temp.indexOf('?', temp.indexOf("who is "))
- + " 2:"
- + temp.indexOf(' ', temp.indexOf("who is "))
- + 8);
- String tnick = "";
- if (temp.indexOf('?', temp.indexOf("who is ")) > 0
- && (temp.indexOf('?', temp.indexOf("who is ")) < temp
- .indexOf('\n',
- temp.indexOf("who is ") + 8) || (temp
- .indexOf('?', temp.indexOf("who is ")) < temp
- .indexOf(' ',
- temp.indexOf("who is ") + 8)))) {
- tnick = temp
- .substring(
- temp.indexOf("who is ") + 7,
- temp.indexOf('?',
- temp.indexOf("who is ")) - 1);
- System.err.println("A");
- } else if (temp.indexOf('!', temp.indexOf("who is ")) > 0
- && (temp.indexOf('!', temp.indexOf("who is ")) < temp
- .indexOf('\n',
- temp.indexOf("who is ") + 8) || temp
- .indexOf('!', temp.indexOf("who is ")) < temp
- .indexOf(' ',
- temp.indexOf("who is ") + 8))) {
- tnick = temp
- .substring(
- temp.indexOf("who is ") + 7,
- temp.indexOf('!',
- temp.indexOf("who is ")) - 1);
- System.err.println("B");
- } else if (temp.indexOf(' ',
- temp.indexOf("who is ") + 7) > 0) {
- tnick = temp.substring(temp.indexOf("who is ") + 7,
- temp.indexOf(' ',
- temp.indexOf("who is ") + 8));
- System.err.println("C");
- } else {
- tnick = temp.substring(temp.indexOf("who is ") + 7);
- System.err.println("D");
- }
- System.err.println("\ttnick: " + tnick);
- if (tnick.contains(NICK)) {
- sout.print("PRIVMSG " + tchan + " :"
- + "I am a faggot.\r\n");
- } else if (tnick.equals(OWNER)) {
- sout.print("PRIVMSG " + tchan + " :"
- + "According to my tests, " + OWNER
- + " isn't a faggot.\r\n");
- } else {
- sout.print("PRIVMSG " + tchan + " :" + tnick
- + " is a faggot.\r\n");
- }
- sout.flush();
- } catch (Exception e) {
- System.err
- .println("Things broke. bad substring in faggot?");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- static boolean unPrivedExec(String command, String line) {
- if (command.contains("version") || command.contains("VERSION")) {
- System.err.println("\tLooks like it's version");
- String tchan = line.substring(line.indexOf("PRIVMSG ") + 8,
- line.indexOf(' ', line.indexOf(":&") - 1));
- sout.print("PRIVMSG " + tchan + " :I am versionless.\r\n");
- sout.flush();
- }
- return false;
- }
- static boolean execute(String command, String line) {
- System.err.println("\t\tCommand is " + command);
- if (command.contains("quit")) {
- try {
- String tchan = line.substring(line.indexOf("PRIVMSG ") + 8,
- line.indexOf(' ', line.indexOf(":&") - 1));
- System.err.println("\t\tLooks like it's quit");
- sout.print("PRIVMSG " + tchan + " :bye!\r\n");
- sout.flush();
- } catch (Exception e) {
- System.err.println("Things broke. bad substring in &quit?");
- }
- System.exit(0);
- } else if (command.contains("restart")) {
- System.err.println("\t\tRestarting..");
- try {
- cs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- startMe();
- return true;
- }
- unPrivedExec(command, line);
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment