Skip to content

Instantly share code, notes, and snippets.

@seymores
Created September 20, 2011 13:55
Show Gist options
  • Save seymores/1229114 to your computer and use it in GitHub Desktop.
Save seymores/1229114 to your computer and use it in GitHub Desktop.
Simple Scala Irc client
import java.net._
import java.io._
import scala.io._
import scala.util.control.Breaks._
val server = "irc.freenode.net";
val nick = "SeymourCakes"
val login = "SeymourCakesBot"
val channel = "#myoss"
val socket = new Socket(server, 6667)
val writer = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream( )));
val reader = new BufferedReader( new InputStreamReader(socket.getInputStream( )));
writer.write("NICK " + nick + "\r\n");
writer.write("USER " + login + " 8 * : Shitmores.blogspot.com Bot\r\n");
writer.flush();
var line = "";
breakable {
while ({line = reader.readLine(); line != null}) {
if (line.indexOf("004") >= 0) {
println(" All ok, break now?")
break;
} else if (line.indexOf("433") >= 0) {
println("Nickname is already in use.");
break;
}
}
}
writer.write("JOIN " + channel + "\r\n");
writer.flush( );
while ({line = reader.readLine(); line != null}) {
if (line.toLowerCase( ).startsWith("PING ")) {
// We must respond to PINGs to avoid being disconnected.
writer.write("PONG " + line.substring(5) + "\r\n");
writer.write("PRIVMSG " + channel + " :I got pinged!\r\n");
writer.flush( );
} else {
println(line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment