Skip to content

Commit

Permalink
Merge branch 'handle-missing-colon'
Browse files Browse the repository at this point in the history
  • Loading branch information
danlarkin committed Oct 17, 2012
2 parents 3679378 + a1c379d commit 7b401bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/subrosa/commands.clj
Expand Up @@ -207,13 +207,26 @@
(join " " names))))
(send-to-client channel 366 (format "%s :End of NAMES list" room-name)))

(defn make-plain-msg [msg]
(if (= (.charAt msg 0) \:)
(subs msg 1)
msg))

(defn make-adorned-msg [msg]
(if (and msg
(= (.charAt msg 0) \:))
msg
(str ":" msg)))

(defcommand privmsg [channel args]
(let [[recipient received-msg] (.split args " " 2)
msg (format ":%s PRIVMSG %s %s"
(format-client channel) recipient received-msg)]
(format-client channel)
recipient
(make-adorned-msg received-msg))]
(if (not (empty? recipient))
(if (not (nil? received-msg))
(let [plain-msg (subs received-msg 1)]
(let [plain-msg (make-plain-msg received-msg)]
(if (room-for-name recipient)
(do
(send-to-room-except recipient msg channel)
Expand All @@ -237,10 +250,12 @@
(defcommand notice [channel args]
(let [[recipient received-msg] (.split args " " 2)
msg (format ":%s NOTICE %s %s"
(format-client channel) recipient received-msg)]
(format-client channel)
recipient
(make-adorned-msg received-msg))]
(when (and (not (empty? recipient))
(not (nil? received-msg)))
(let [plain-msg (subs received-msg 1)]
(let [plain-msg (make-plain-msg received-msg)]
(if (room-for-name recipient)
(do
(send-to-room-except recipient msg channel)
Expand Down
29 changes: 29 additions & 0 deletions test/subrosa/test/chat.clj
Expand Up @@ -18,6 +18,20 @@
(Thread/sleep 1000)) ; give some time for the message to get to the server
(is (received? s1 #"dan2!dan@.* PRIVMSG #foo :Hello, World!"))))

(deftest basic-privmsg-to-room-missing-colon
(with-connection s1
(transmit s1 "NICK dan")
(transmit s1 "USER dan 0 * :Dan Larkin")
(transmit s1 "JOIN #foo")
(is (received? s1 #"JOIN #foo"))
(with-connection s2
(transmit s2 "NICK dan2")
(transmit s2 "USER dan 0 * :Dan Larkin")
(transmit s2 "JOIN #foo")
(transmit s2 "PRIVMSG #foo hello")
(Thread/sleep 1000)) ; give some time for the message to get to the server
(is (received? s1 #"dan2!dan@.* PRIVMSG #foo :hello"))))

(deftest basic-privmsg-to-user
(with-connection s1
(transmit s1 "NICK dan")
Expand Down Expand Up @@ -53,6 +67,21 @@
(Thread/sleep 1000)) ; give some time for the message to get to the server
(is (received? s1 #"dan2!dan@.* NOTICE #foo :Hello, World!"))))

(deftest notice-to-room-missing-colon
(with-connection s1
(transmit s1 "NICK dan")
(transmit s1 "USER dan 0 * :Dan Larkin")
(transmit s1 "JOIN #foo")
(is (received? s1 #"JOIN #foo"))
(with-connection s2
(transmit s2 "NICK dan2")
(transmit s2 "USER dan 0 * :Dan Larkin")
(transmit s2 "JOIN #foo")
(transmit s2 "NOTICE #foo hello")
(Thread/sleep 1000)) ; give some time for the message to get to the server
(is (received? s1 #"dan2!dan@.* NOTICE #foo :hello"))))


(deftest notice-to-user
(with-connection s1
(transmit s1 "NICK dan")
Expand Down

0 comments on commit 7b401bd

Please sign in to comment.