Skip to content

Commit

Permalink
catchup plugin should capture & playback NOTICEs
Browse files Browse the repository at this point in the history
  • Loading branch information
danlarkin committed Jun 9, 2011
1 parent 150fe0f commit 48d1b65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
26 changes: 13 additions & 13 deletions src/subrosa/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@
(defcommand privmsg [channel args]
(let [[recipient received-msg] (.split args " " 2)
msg (format ":%s PRIVMSG %s %s"
(format-client channel) recipient received-msg)
plain-msg (subs received-msg 1)]
(format-client channel) recipient received-msg)]
(if (not (empty? recipient))
(if (not (nil? received-msg))
(if (room-for-name recipient)
(do
(send-to-room-except recipient msg channel)
(run-hook 'privmsg-room-hook
channel recipient plain-msg))
(if-let [channel (channel-for-nick recipient)]
(let [plain-msg (subs received-msg 1)]
(if (room-for-name recipient)
(do
(send-to-client* channel msg)
(run-hook 'privmsg-nick-hook
(send-to-room-except recipient msg channel)
(run-hook 'privmsg-room-hook
channel recipient plain-msg))
(raise {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" recipient)})))
(if-let [channel (channel-for-nick recipient)]
(do
(send-to-client* channel msg)
(run-hook 'privmsg-nick-hook
channel recipient plain-msg))
(raise {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" recipient)}))))
(raise {:type :client-error
:code 412
:msg ":No text to send"}))
Expand Down
21 changes: 13 additions & 8 deletions src/subrosa/plugins/catchup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@

(defn add-message [hook channel room-name msg]
(dosync
(commute buffer update-in [room-name] maybe-conj [(nick-for-channel channel)
(format "[%s] %s"
(format-time)
msg)])))
(commute buffer update-in [room-name] maybe-conj
[(nick-for-channel channel)
(if (= hook 'privmsg-room-hook)
"PRIVMSG"
"NOTICE")
(format "[%s] %s"
(format-time)
msg)])))

(defn add-hooks []
(add-hook ::catchup 'privmsg-room-hook add-message))
(add-hook ::catchup 'privmsg-room-hook add-message)
(add-hook ::catchup 'notice-room-hook add-message))

(when (config :plugins :catchup :enabled?)
(add-hooks)
Expand All @@ -49,10 +54,10 @@
(do
(send-to-client*
channel (format ":*** PRIVMSG %s :%s" room "Catchup Playback"))
(doseq [[sender msg] (take-last size (@buffer room))]
(doseq [[sender type msg] (take-last size (@buffer room))]
(send-to-client* channel
(format ":%s PRIVMSG %s :%s"
sender room msg)))
(format ":%s %s %s :%s"
sender type room msg)))
(send-to-client*
channel (format ":*** PRIVMSG %s :%s" room "Catchup Complete")))
(raise {:type :client-error
Expand Down
4 changes: 3 additions & 1 deletion test/subrosa/test/plugins/catchup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(transmit s1 "JOIN #foo")
(Thread/sleep 500)
(transmit s1 "PRIVMSG #foo :Hello, World!")
(transmit s1 "NOTICE #foo :Hey, it's a notice!")
(transmit s2 "NICK lee2")
(transmit s2 "USER lee2 0 * :Lee Hinmanm")
(transmit s2 "JOIN #foo")
Expand All @@ -20,7 +21,8 @@
(transmit s1 "CATCHUP #foo 1")
(is (received? s1 #"Goodbye, World!"))
(transmit s1 "CATCHUP #foo")
(is (received? s1 #"Hello, World!"))
(is (received? s1 #"PRIVMSG #foo :\[.*\] Hello, World!"))
(is (received? s1 #"NOTICE #foo :\[.*\] Hey, it's a notice!"))
(transmit s1 "PART #foo")
(transmit s1 "QUIT"))))

Expand Down

0 comments on commit 48d1b65

Please sign in to comment.