package com.company;
import java.io.*;
import java.net.*;
public class Main
{
public static void main(String[] args) throws Exception
{
// The server to connect to and our details.
String server = "irc.rizon.net";
String nick = "nodeBot";
String login = "nodeBot";
// The channel which the bot will join.
String channel = "#destinysc2";
//connect to IRC
Socket socket = new Socket(server, 6667);
/*1st line below: reading the output, BufferedWriter writes text to a character-output stream
*2nd line: takes in output from the socket above and reads in the output from irc*/
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream()));
//same as above, but input
BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
/* logging in to IRC, writing to the stream*/
writer.write("Nick " + nick);
writer.newLine();
//for the '0' http://t...content-available-to-author-only...f.org/html/rfc2812#section-3.1
writer.write("USER " + login + " 0 * : nodesBot");
// need this newline so it knows it's done with command
writer.newLine();
//basically hitting enter
writer.flush();
// Read lines from the server until it tells us we have connected.
String line = null;
// 004 http://t...content-available-to-author-only...f.org/html/rfc2812#section-5.1
while ((line = reader.readLine()) != null)
{
if (line.contains("004"))
{
// We are now logged in.
break;
}
else if (line.contains("433"))
{
System.out.println("Nickname is already in use.");
return;
}
}
// Join the channel.
writer.write("JOIN " + channel );
writer.newLine();
writer.flush( );
// Keep reading lines from the server.
while ((line = reader.readLine( )) != null)
{
if (line.startsWith("PING "))
{
//responding to ping
writer.write("PONG " + line.substring(5) );
writer.newLine();
writer.flush( );
}
else
{
// Print the raw line received by the bot.
System.out.println(line);
}
}
//write input to channel
writer.write("PRIVMSG " + channel + " :Hey");
writer.newLine();
writer.flush();
}
}