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)
(sort)))
(defn match-string [state game _]
(defn match-string [& {:keys [state game]}]
(str "Anyone ready for "
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 " _" % "_")
(sorted-players-of-game state game)))]
(str "Players of "
@ -27,21 +27,21 @@
":"
players)))
(defn add-player-string [_ game player]
(defn add-player-string [& {:keys [game player]}]
(str "Added "
player
" to the list of players for "
game
"!"))
(defn remove-player-string [_ game player]
(defn remove-player-string [& {:keys [game player]}]
(str "Removed "
player
" from the list of players for "
game
"!"))
(defn list-games-string [state _ _]
(defn list-games-string [& {:keys [state]}]
(str "Games with a list of players: "
(str/join
", "
@ -63,21 +63,21 @@
(if game
(condp = command
"!match"
(match-string @state game nil)
(match-string :state @state :game game)
"!add"
(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"
(list-players-string @state game nil)
(list-players-string :state @state :game game)
"!remove"
(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)
(condp = command
"!list"
(list-games-string @state nil nil)
(list-games-string :state @state)
nil))))

View File

@ -11,23 +11,23 @@
(deftest match-string-test
(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
(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
(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
(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
(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
(is (= {:command "!match" :game "Quasi-Rts" :game-keyword :quasi-rts}