I need a few simple java classes that will login to a irc channel, print all the messages in channel and can also send messages to channel. So far I have a java class to read irc messages from a channel:
import java.io.*;
import java.net.*;
public class IRCClient {
public static void main(String[] args) throws Exception {
// The server to connect to and our details.
String server = "[login to view URL]";
String nick = "simple_bot";
String login = "simple_bot";
// The channel which the bot will join.
String channel = "#rsbot";
// Connect directly to the IRC server.
Socket socket = new Socket(server, 7000);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter([login to view URL]( )));
BufferedReader reader = new BufferedReader(
new InputStreamReader([login to view URL]( )));
// Log on to the server.
[login to view URL]("NICK " + nick + "\r\n");
[login to view URL]("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
[login to view URL]( );
// Read lines from the server until it tells us we have connected.
String line = null;
while ((line = [login to view URL]( )) != null) {
if ([login to view URL]("004") >= 0) {
// We are now logged in.
break;
}
else if ([login to view URL]("433") >= 0) {
[login to view URL]("Nickname is already in use.");
return;
}
}
// Join the channel.
[login to view URL]("JOIN " + channel + "\r\n");
[login to view URL]( );
// Keep reading lines from the server.
while ((line = [login to view URL]( )) != null) {
if ([login to view URL]( ).startsWith("PING ")) {
// We must respond to PINGs to avoid being disconnected.
[login to view URL]("PONG " + [login to view URL](5) + "\r\n");
[login to view URL]("PRIVMSG " + channel + " :I got pinged!\r\n");
[login to view URL]( );
}
else {
// Print the raw line received by the bot.
[login to view URL](line);
}
}
}
}