Skip to content

Instantly share code, notes, and snippets.

@metamorph
Created February 21, 2013 08:21
Show Gist options
  • Save metamorph/5003153 to your computer and use it in GitHub Desktop.
Save metamorph/5003153 to your computer and use it in GitHub Desktop.
Tiny embryo for an IRC bot using Akka I/O
import akka.actor.ActorSystem
import akka.io.IO
import akka.io._
object Boot extends App {
import akka.io.Tcp._
implicit val sys = ActorSystem("io")
import akka.actor.{Actor, Props, ActorRef}
import akka.util.ByteString
class Client extends Actor {
def receive = {
case Connected(remote, local) =>
println("Connected to " + remote)
context.sender ! Register(self)
context.sender ! Write(ByteString("USER sbot engand localhost :Anders Engstrom\n"))
context.sender ! Write(ByteString("NICK sbot\n"))
context.sender ! Write(ByteString("JOIN #gp\n"))
case Received(data) =>
println("Received: " + data.decodeString("UTF-8"))
case _: ConnectionClosed => println("Connection was closed")
case any => println("Received " + any)
}
}
val client = sys.actorOf(Props[Client], "client")
val mgr = IO(Tcp)
mgr.tell(Connect(new java.net.InetSocketAddress("localhost", 9999)), client)
Thread sleep 20000
sys.shutdown
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment