some tools for dealing with IRC in scala
Switch branches/tags
Nothing to show
Clone or download
Anders Conbere
Anders Conbere add mit licensing
Latest commit ba81b84 May 26, 2015
Failed to load latest commit information.
project Add tick scheduling May 17, 2013
src work on making bots actors Jul 22, 2013
.gitignore working parser Feb 1, 2013
LICENSE add mit licensing May 26, 2015
README.mkd update docs Jul 22, 2013
build.sbt work on making bots actors Jul 22, 2013 found the missing crlf Feb 26, 2013


Scala IRC

Scala irc is a small irc framework focused on a simple interface for receiving and responding to messages and composable interfaces.


libraryDependencies += "org.conbere" %% "irc" % "0.4.0"

Usage: Bots

The easiest way to get started is to extend the ClassicBot trait

import org.conbere.irc._

class MyBot( val serverName:String
           , val nickName:String
           , val userName:String
           , val password:String
           , val realName:String
           , val rooms:List[Room])
extends ClassicBot {

For ease of use we'll grab Messages from the irc package. These form the foundational datatypes for using irc. Messages provides common extractors for all of the irc commands (PONG, PRIVMSG, JOIN, etc.) as well as providing an easy helper to produce a Message object for pushing back to the server. Tokens

  import Messages._

  val toMePattern = ("^(" + nickName + "[:| ].*)").r

Bots are simply an actor that recieves messages from the Client, defining the actor's receive method is sufficient to begin. There are two helper methods onConnect and defaultHandler which make sure that user authentication is set up and pings are handled. You'll notice that recieve's are PartialFunctions a feature that we use to chain behavior. To respond you can send a message back to the sender sender ! PrivMsg(from, msg).

And finally we match against PrivMsg's comming in looking for some simple patterns, and respond with new PrivMsgs.

  def receive = onConnect orElse defaultResponse orElse {
    case PrivMsg(from, `nickName`, _) =>
      sender ! PrivMsg(from, "Hi " + from + " this is a private message")
    case PrivMsg(from, channel, toMePattern(_match)) =>
      sender ! PrivMsg(from, "Hi " + from + " this is a channel message directed at me")

The last task is to produce an runable executable. To run your bot the Client object defines a start method which given a server and port will host your bot in an Actor.

object Main {
  def main(args:Array[String]) = {
    val system = ActorSystem("irc")

    val server = ""
    val port = 6667

    val rooms = List(Room("#testroom", None))

    val bot = system.actorOf(Prop(classOf[MyBot], server, "bot", "bot", "pass", "Bot", rooms))
    val client = system.actorOf(Prop(classOf[Client], server, port, bot))