Use keyword arguments for response functions

Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
This commit is contained in:
Sebastian Crane 2022-02-18 22:03:24 +00:00
parent 77b022455e
commit c1572ed121
2 changed files with 15 additions and 15 deletions

View File

@ -13,13 +13,13 @@
(game/get-players-of-game state) (game/get-players-of-game state)
(sort))) (sort)))
(defn match-string [state game _] (defn match-string [& {:keys [state game]}]
(str "Anyone ready for " (str "Anyone ready for "
game game
"? " "? "
(str/join " " (sorted-players-of-game state game)))) (str/join " " (sorted-players-of-game state game))))
(defn list-players-string [state game _] (defn list-players-string [& {:keys [state game]}]
(let [players (str/join (map #(str " _" % "_") (let [players (str/join (map #(str " _" % "_")
(sorted-players-of-game state game)))] (sorted-players-of-game state game)))]
(str "Players of " (str "Players of "
@ -27,21 +27,21 @@
":" ":"
players))) players)))
(defn add-player-string [_ game player] (defn add-player-string [& {:keys [game player]}]
(str "Added " (str "Added "
player player
" to the list of players for " " to the list of players for "
game game
"!")) "!"))
(defn remove-player-string [_ game player] (defn remove-player-string [& {:keys [game player]}]
(str "Removed " (str "Removed "
player player
" from the list of players for " " from the list of players for "
game game
"!")) "!"))
(defn list-games-string [state _ _] (defn list-games-string [& {:keys [state]}]
(str "Games with a list of players: " (str "Games with a list of players: "
(str/join (str/join
", " ", "
@ -63,21 +63,21 @@
(if game (if game
(condp = command (condp = command
"!match" "!match"
(match-string @state game nil) (match-string :state @state :game game)
"!add" "!add"
(do (swap! state game/add-player-of-game game-keyword sender) (do (swap! state game/add-player-of-game game-keyword sender)
(add-player-string nil game sender)) (add-player-string :game game :player sender))
"!players" "!players"
(list-players-string @state game nil) (list-players-string :state @state :game game)
"!remove" "!remove"
(do (swap! state game/remove-player-of-game game-keyword sender) (do (swap! state game/remove-player-of-game game-keyword sender)
(remove-player-string nil game sender)) (remove-player-string :game game :player sender))
nil) nil)
(condp = command (condp = command
"!list" "!list"
(list-games-string @state nil nil) (list-games-string :state @state)
nil)))) nil))))

View File

@ -11,23 +11,23 @@
(deftest match-string-test (deftest match-string-test
(is (= '"Anyone ready for quasi-Rts? 123 abc" (is (= '"Anyone ready for quasi-Rts? 123 abc"
(match-string test-state "quasi-Rts" nil)))) (match-string :state test-state :game "quasi-Rts"))))
(deftest list-players-string-test (deftest list-players-string-test
(is (= "Players of HYPOTHETICAL-shooter: _123_ _abc_ _xyz_" (is (= "Players of HYPOTHETICAL-shooter: _123_ _abc_ _xyz_"
(list-players-string test-state "HYPOTHETICAL-shooter" nil)))) (list-players-string :state test-state :game "HYPOTHETICAL-shooter"))))
(deftest add-player-string-test (deftest add-player-string-test
(is (= "Added abc to the list of players for Quasi-Rts!" (is (= "Added abc to the list of players for Quasi-Rts!"
(add-player-string nil "Quasi-Rts" "abc")))) (add-player-string :game "Quasi-Rts" :player "abc"))))
(deftest remove-player-string-test (deftest remove-player-string-test
(is (= "Removed abc from the list of players for hypothetical-shooter!" (is (= "Removed abc from the list of players for hypothetical-shooter!"
(remove-player-string nil "hypothetical-shooter" "abc")))) (remove-player-string :game "hypothetical-shooter" :player "abc"))))
(deftest list-games-string-test (deftest list-games-string-test
(is (= "Games with a list of players: hypothetical-shooter, imaginary-rpg, quasi-rts" (is (= "Games with a list of players: hypothetical-shooter, imaginary-rpg, quasi-rts"
(list-games-string test-state nil nil)))) (list-games-string :state test-state))))
(deftest split-message-test (deftest split-message-test
(is (= {:command "!match" :game "Quasi-Rts" :game-keyword :quasi-rts} (is (= {:command "!match" :game "Quasi-Rts" :game-keyword :quasi-rts}