Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

found the missing crlf

  • Loading branch information...
commit 8d8d554c89a5adf54e1f2113f157afc510a2721b 1 parent f18172f
Anders Conbere authored
View
6 src/main/scala/Bot.scala
@@ -32,6 +32,7 @@ extends Actor with Logging {
def parseMessage(str:String) =
Parser.apply(str) match {
case Parser.Success(message, _) =>
+ println("Received: " + message)
Some(message)
case _ =>
logger.error("Could not parse: " + str)
@@ -42,7 +43,7 @@ extends Actor with Logging {
response match {
case Some(response) =>
println("Response: " + utf8(response.byteString))
- socket.write(response.byteString)
+ socket.write((new ByteStringBuilder ++= response.byteString ++= CRLF).result)
case _ =>
// no response
}
@@ -59,8 +60,9 @@ extends Actor with Logging {
IO.takeUntil(CRLF).map { in =>
parseMessage(utf8(in)) match {
case Some(message) =>
- if (responder.respondTo.isDefinedAt(message))
+ if (responder.respondTo.isDefinedAt(message)) {
writeResponse(responder.respondTo(message))
+ }
case None =>
// do nothing
}
View
1  src/main/scala/BotResponder.scala
@@ -10,7 +10,6 @@ trait BotResponder {
val defaultResponse:PartialFunction[Message,Option[Response]] = {
case Ping(from) =>
- println("Ping: " + from)
Some(Pong(from))
case msg@Mode(params) if !rooms.isEmpty =>
Some(Join(rooms))
View
24 src/main/scala/ExampleBot.scala
@@ -20,11 +20,11 @@ extends BotResponder with Logging {
User(userName, hostName, serverName, realName))
val respondTo = defaultResponse.orElse[Message,Option[Response]] {
- case PrivMsg(to, from, text) =>
- println(to + ", " + from + ", " + text)
+ case msg@PrivMsg(from, `nickName`, text) =>
+ Some(PrivMsg(from, text))
+ case PrivMsg(from, to, text) =>
None
- case msg@Message(_, _, _) =>
- println(msg)
+ case _ =>
None
}
}
@@ -32,17 +32,19 @@ extends BotResponder with Logging {
object Main extends Logging {
def main(args:Array[String]) = {
- val rooms = List(Room("#testroom", None),
- Room("#etsynomics", None))
+ val rooms = List(Room("#testroom", None))
- val responder = new Responder("irc.ny4dev.etsy.com",
- "abcdefg",
- "abcdefg",
- "all_hail_etsy",
+ val server = "irc.ny4dev.etsy.com"
+ val port = 6667
+
+ val responder = new Responder(server,
+ "testbot",
+ "testbot",
+ "password",
"Test Bot",
rooms)
- val server = Bot.start("irc.ny4dev.etsy.com", 6667, responder)
+ val actor = Bot.start(server, port, responder)
}
}
View
16 src/main/scala/Messages.scala
@@ -38,7 +38,7 @@ object Messages {
def unapply(msg:Message) = {
msg match {
case Message(Some(Prefix(from, _, _)), Command("PRIVMSG"), List(to, text)) =>
- Some((to, from, text))
+ Some((from, to, text))
case _ =>
None
}
@@ -146,4 +146,18 @@ object Messages {
}
}
}
+
+ object Part {
+ def apply(channels:List[String]) =
+ Message(None, Command("PART"), List(channels.mkString(",")))
+
+ def unapply(msg:Message) = {
+ msg match {
+ case Message(_,Command("PART"), List(channels)) =>
+ Some(channels)
+ case _ =>
+ None
+ }
+ }
+ }
}
View
3  src/test/scala/TokensSuite.scala
@@ -1,6 +1,7 @@
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
+import akka.util.ByteString
import org.conbere.irc.Parser
import org.conbere.irc.Tokens._
@@ -9,7 +10,7 @@ import org.conbere.irc.Tokens._
class TokensSuite extends FunSuite {
test("produces messages suffixed with :") {
val userMessage = Message(None, Command("USER"), List("avibot", "opae", "opae", "Avi Bryant"))
- assert(userMessage.outputString === "USER avibot opae opae :Avi Bryant")
+ assert(userMessage.byteString === ByteString("USER avibot opae opae :Avi Bryant"))
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.