Permalink
Browse files

add KICK support

  • Loading branch information...
danlarkin committed Jun 12, 2011
1 parent 0b6a4dc commit d521029e4d6d8f24c5253bf5aded6fb80aa5e20a
Showing with 143 additions and 0 deletions.
  1. +52 −0 src/subrosa/commands.clj
  2. +91 −0 test/subrosa/test/rooms.clj
View
@@ -405,3 +405,55 @@
(raise {:type :client-error
:code 461
:msg "INVITE :Not enough parameters"}))))
+
+(defcommand kick [channel args]
+ (let [[rooms nicks comment] (.split args " " 3)]
+ (if (and rooms nicks)
+ (let [rooms (.split rooms ",")
+ nicks (.split nicks ",")
+ comment (or (and comment (subs comment 1))
+ (nick-for-channel channel))
+ do-kick (fn [nick room]
+ (if (room-for-name room)
+ (if (nick-in-room? (nick-for-channel channel) room)
+ (if (nick-in-room? nick room)
+ (dosync
+ (send-to-room room (format ":%s KICK %s %s :%s"
+ (format-client channel)
+ room
+ nick
+ comment))
+ (remove-nick-from-room! nick room)
+ (run-hook 'kick-hook channel room nick comment))
+ (raise {:type :client-error
+ :code 441
+ :msg (format
+ "%s %s :They aren't on that channel"
+ nick
+ room)}))
+ (raise {:type :client-error
+ :code 442
+ :msg (format "%s :You're not on that channel"
+ room)}))
+ (raise {:type :client-error
+ :code 403
+ :msg (format "%s :No such channel" room)})))]
+ (cond
+ (and (= 1 (count rooms))
+ (>= 1 (count nicks)))
+ (doseq [nick nicks]
+ (do-kick nick
+ (first rooms)))
+
+ (= (count rooms) (count nicks))
+ (doseq [[room nick] (zipmap rooms nicks)]
+ (do-kick nick room))
+
+ :else (raise {:type :client-error
+ :code 461
+ :msg "KICK :Not enough parameters"})))
+ (raise {:type :client-error
+ :code 461
+ :msg "KICK :Not enough parameters"}))))
+
+
@@ -262,3 +262,94 @@
(transmit s "INVITE dan2 #foo")
(is (received? s2 #"dan!dan@.* INVITE dan2 #foo"))
(is (received? s #"341 dan #foo dan2")))))
+
+(deftest kick-with-no-comment
+ (with-connection s
+ (transmit s "NICK dan")
+ (transmit s "USER dan 0 * :Dan Larkin")
+ (transmit s "JOIN #bam")
+ (with-connection s2
+ (transmit s2 "NICK dan2")
+ (transmit s2 "USER dan 0 * :Dan Larkin")
+ (transmit s2 "JOIN #bam")
+ (Thread/sleep 1000)
+ (transmit s "KICK #bam dan2")
+ (is (received? s2 #"dan!dan@.* KICK #bam dan2 :dan"))
+ (is (received? s #"dan!dan@.* KICK #bam dan2 :dan"))
+ (transmit s "NAMES #bam")
+ (is (received? s #"353 dan = #bam :dan")))))
+
+(deftest kick-with-comment
+ (with-connection s
+ (transmit s "NICK dan")
+ (transmit s "USER dan 0 * :Dan Larkin")
+ (transmit s "JOIN #bam")
+ (with-connection s2
+ (transmit s2 "NICK dan2")
+ (transmit s2 "USER dan 0 * :Dan Larkin")
+ (transmit s2 "JOIN #bam")
+ (Thread/sleep 1000)
+ (transmit s "KICK #bam dan2 :Bye, jerk!")
+ (is (received? s2 #"dan!dan@.* KICK #bam dan2 :Bye, jerk!"))
+ (is (received? s #"dan!dan@.* KICK #bam dan2 :Bye, jerk!"))
+ (transmit s "NAMES #bam")
+ (is (received? s #"353 dan = #bam :dan")))))
+
+(deftest kick-with-comment
+ (with-connection s
+ (transmit s "NICK dan")
+ (transmit s "USER dan 0 * :Dan Larkin")
+ (transmit s "JOIN #bam")
+ (with-connection s2
+ (transmit s2 "NICK dan2")
+ (transmit s2 "USER dan 0 * :Dan Larkin")
+ (transmit s2 "JOIN #bam")
+ (Thread/sleep 1000)
+ (transmit s "KICK #bam dan2 :Bye, jerk!")
+ (is (received? s2 #"dan!dan@.* KICK #bam dan2 :Bye, jerk!"))
+ (is (received? s #"dan!dan@.* KICK #bam dan2 :Bye, jerk!"))
+ (transmit s "NAMES #bam")
+ (is (received? s #"353 dan = #bam :dan")))))
+
+(deftest kick-with-bad-syntax
+ (with-connection s
+ (transmit s "NICK dan")
+ (transmit s "USER dan 0 * :Dan Larkin")
+ (transmit s "JOIN #bam")
+ (with-connection s2
+ (transmit s2 "NICK dan2")
+ (transmit s2 "USER dan 0 * :Dan Larkin")
+ (transmit s2 "JOIN #bam")
+ (Thread/sleep 1000)
+ (transmit s "KICK")
+ (is (received? s #"461 dan KICK :Not enough parameters"))
+ (reset! (:received s) [])
+ (transmit s "KICK #bam")
+ (is (received? s #"461 dan KICK :Not enough parameters"))
+ (reset! (:received s) [])
+ (transmit s "KICK #bam,#foo")
+ (is (received? s #"461 dan KICK :Not enough parameters"))
+ (reset! (:received s) [])
+ (transmit s "KICK #bam,#foo dan2")
+ (is (received? s #"461 dan KICK :Not enough parameters"))
+ (reset! (:received s) []))))
+
+(deftest kick-error-conditions
+ (with-connection s
+ (transmit s "NICK dan")
+ (transmit s "USER dan 0 * :Dan Larkin")
+ (transmit s "JOIN #bam")
+ (transmit s "JOIN #supercool")
+ (with-connection s2
+ (transmit s2 "NICK dan2")
+ (transmit s2 "USER dan 0 * :Dan Larkin")
+ (transmit s2 "JOIN #bam")
+ (transmit s2 "JOIN #bam2")
+ (Thread/sleep 1000)
+ (transmit s "KICK #foo dan2")
+ (is (received? s #"403 dan \#foo :No such channel"))
+ (transmit s "KICK #bam2 dan2")
+ (is (received? s #"442 dan \#bam2 :You're not on that channel"))
+ (transmit s "KICK #supercool dan2")
+ (is (received?
+ s #"441 dan dan2 \#supercool :They aren't on that channel")))))

0 comments on commit d521029

Please sign in to comment.