Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Java] IRC Bot :/
#1
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
Reply
#2
Nice code, thanks!
Reply
#3
(08-29-2010, 01:18 AM)Starky Wrote: Nice code, thanks!

indeed its a nice code :2

easyily modified into a great project.
Reply
#4
You're flamingworm V2? The epic coppy and paste leechbot.
Reply
#5
(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.
Reply
#6
(09-08-2010, 07:58 AM)Scammer Wrote: of course not.

i give credits, always.
still leeching.
Reply
#7
He gave credits, and is sharing a great code. Don't flame him, it isn't necessary or helpful.
Reply
#8
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.
Reply
#9
Is it outdated, and is it stable or?
Reply
#10
wow great code man. thanks for the share.
Like marketing? join www.marketforums.org My user: Weeds
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why java haphazard 8 1,790 12-12-2011, 03:23 AM
Last Post: RDCA
  Need Java help from java expert. Blazin 2 2,101 09-07-2011, 02:43 PM
Last Post: AceInfinity
  Java help php 1 1,047 04-06-2010, 06:41 AM
Last Post: php
  Java Problem for real java programmer Testgamma1 10 5,203 03-14-2010, 09:08 AM
Last Post: uber1337
  How do i get java Mozz 4 1,614 02-13-2010, 12:29 PM
Last Post: Mozz

Forum Jump:


Users browsing this thread: 2 Guest(s)