Support Forums

Full Version: [Java] IRC Bot :/
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Code:
import java.io.*;
import java.net.*;
import java.lang.Throwable.*;




public class Main {

    public static void main(String[] args) {
        // The server to connect to and our details.
        String server = "irc.afterworkchat.net";
        String nick = "Pcqbot";
        String login = "pcquaddy";
        String channel = "#bblabla";

    // Connect directly to the IRC server.
        try {
        Socket socket = new Socket(server, 6667);
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(socket.getOutputStream( )));
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(socket.getInputStream( )));

        // Log on to the server.
        writer.write("NICK " + nick + "\r\n");
        writer.write("USER " + login + " 8 * : heyho\r\n");
        writer.flush( );

        String line = null;
        while ((line = reader.readLine( )) != null) {
            if (line.indexOf("004") >= 0) {
                // We are now logged in.
                break;
            }
            else if

(line.indexOf("433") >= 0) {
                System.out.println("Nickname is already in use.");
                return;
            }
        }



        // Log on to the server.
        writer.write("NICK " + nick + "\r\n");
        writer.write("USER " + login + " 8 * : yoo\r\n");
        writer.flush( );

        //Join the channel.
        writer.write("JOIN " + channel + "\r\n");
        writer.write("PRIVMSG " + channel + " :yo guys \r\n");

        writer.flush( );

        while ((line = reader.readLine( )) != null) {
            if (line.toLowerCase( ).startsWith("PING "))       {

                writer.write("PONG " + line.substring(5) + "\r\n");
                writer.flush( );
                                 }
       String[] tmp = line.split(" :");
       System.out.println(tmp[0] + "::" + tmp[1]);
       if (tmp[1].length() >= 5) {
       if (tmp[1].substring(0,6).equals(nick)) {
       if (tmp[1].length() >= 11 && tmp[1].substring(7, 11).equals("say ")) {
       String[] tmp2 = tmp[1].split("say ");
       System.out.println(tmp[1] + "::" + tmp2[1]);
       writer.write("PRIVMSG " + channel + " :" + tmp2[1] + "\r\n");
       writer.flush();
       }}}

       String[] tmp1 = line.split(" :");
       System.out.println(tmp1[0] + "::" + tmp1[1]);
       if (tmp1[1].length() >= 5) {
       if (tmp1[1].substring(0,6).equals(nick)) {
       if (tmp1[1].length() >= 12 && tmp1[1].substring(7, 12).equals("join ")) {
       String[] tmp12 = tmp1[1].split("join ");
       System.out.println(tmp1[1] + "::" + tmp12[1]);
       writer.write("JOIN " + " :" + tmp12[1] + "\r\n");
       writer.flush();
       }}}

       String[] tmp11 = line.split(" :");
       System.out.println(tmp11[0] + "::" + tmp11[1]);
       if (tmp11[1].length() >= 5) {
       if (tmp11[1].substring(0,6).equals(nick)) {
       if (tmp11[1].length() >= 12 && tmp1[1].substring(7, 12).equals("part ")) {
       String[] tmp112 = tmp11[1].split("part ");
       System.out.println(tmp11[1] + "::" + tmp112[1]);
       writer.write("PART " + " :" + tmp112[1] + "\r\n");
       writer.flush();
       }}}




            String[] tmp3 = line.split(" :");
       System.out.println(tmp3[0] + "::" + tmp3[1]);
       if (tmp3[1].length() >= 5) {
       if (tmp3[1].substring(0,6).equals(nick)) {
       if (tmp3[1].length() >= 11 && tmp3[1].substring(7, 11).equals("topic ")) {
       String[] tmp2 = tmp3[1].split("topic ");
       System.out.println(tmp3[1] + "::" + tmp2[1]);
       writer.write("TOPIC " + channel + " :" + tmp2[1] + "\r\n");
       writer.flush();
       }}}

  

                                }
    }
    catch (Throwable e) {
             System.out.println(e);
                          }


                     }
            }

Found on pcquad's website Big Grin
Nice code, thanks!
(08-29-2010, 01:18 AM)Starky Wrote: [ -> ]Nice code, thanks!

indeed its a nice code :2

easyily modified into a great project.
You're flamingworm V2? The epic coppy and paste leechbot.
(09-07-2010, 12:11 PM)iraqkey Wrote: [ -> ]You're flamingworm V2? The epic coppy and paste leechbot.

of course not.

i give credits, always.
(09-08-2010, 07:58 AM)Scammer Wrote: [ -> ]of course not.

i give credits, always.
still leeching.
He gave credits, and is sharing a great code. Don't flame him, it isn't necessary or helpful.
Quote:In computing and specifically on the Internet, a leech or leecher is one who benefits, usually deliberately, from others' information or effort but does not offer anything in return, or makes only token offerings in an attempt to avoid being called a leech. In economics this type of behavior is called "free riding" and is associated with the free rider problem.

I gave original coder credits. gtfo.
Is it outdated, and is it stable or?
wow great code man. thanks for the share.
Pages: 1 2