08-28-2010, 04:58 AM
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