tags:

views:

61

answers:

1

I'm trying to write an ircBot in Java for some practice. I am using this (http://oreilly.com/pub/h/1966) sample code as the base. I'm trying to figure out how to get it to read in text from my console so I can actually talk to people with the bot. There's the one while loop that takes in the input from the ircserver and spits it out to console and responds to PINGs. I'm assuming I have to have another thread that takes the input from the user and then uses the same BufferedWriter to spit it out to the ircserver again but I can't get that figured out. Any help would be awesome!

+1  A: 

In the code you have linked to, the 'reader' and 'writer' instances, are indeed connected to respectively the ingoing and outgoing ends of the two-way socket you have established with the IRC server.

So in order to get input from the User, you do indeed new another thread which takes commands from the user in some fashion and acts upon these. The most basic model, would naturally be to use System.in for this, preferably wrapping it so that you can retrieve whole line inputs from the User, and parse these as a command.

To read whole lines from System.in you could do something like this:

BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
String line;
while ((line = bin.readLine()) != null) {
    // Do stuff
}

You could also consider using one of the CLI libraries that is out there for Java, like JLine

micdah