diff --git a/src/bot.clj b/src/bot.clj new file mode 100644 index 0000000..a4c0781 --- /dev/null +++ b/src/bot.clj @@ -0,0 +1,42 @@ +;; SPDX-License-Identifier: Apache-2.0 +;; SPDX-FileCopyrightText: 2022 Sebastian Crane + +(ns bot + (:require [clojure.string :as str] + [game] + [irclj.core])) + +(defn sorted-players-of-game [state game] + (->> game + (str/lower-case) + (keyword) + (game/get-players-of-game state) + (sort))) + +(defn match-string [state game] + (str "Anyone ready for " + game + "? " + (str/join " " (sorted-players-of-game state game)))) + +(defn list-players-string [state game] + (let [players (str/join (map #(str " _" % "_") + (sorted-players-of-game state game)))] + (str "Players of " + game + ":" + players))) + +(defn add-player-string [player game] + (str "Added " + player + " to the list of players for " + game + "!")) + +(defn remove-player-string [player game] + (str "Removed " + player + " from the list of players for " + game + "!")) diff --git a/test/bot_test.clj b/test/bot_test.clj new file mode 100644 index 0000000..7ba01ec --- /dev/null +++ b/test/bot_test.clj @@ -0,0 +1,26 @@ +;; SPDX-License-Identifier: Apache-2.0 +;; SPDX-FileCopyrightText: 2022 Sebastian Crane + +(ns bot-test + (:require [clojure.test :refer :all] + [bot :refer :all])) + +(def test-state '{:games {:hypothetical-shooter #{"abc" "xyz" "123"} + :quasi-rts #{"abc" "123"} + :imaginary-rpg #{"xyz" "abc"}}}) + +(deftest match-string-test + (is (= '"Anyone ready for quasi-Rts? 123 abc" + (match-string test-state "quasi-Rts")))) + +(deftest list-players-string-test + (is (= "Players of HYPOTHETICAL-shooter: _123_ _abc_ _xyz_" + (list-players-string test-state "HYPOTHETICAL-shooter")))) + +(deftest add-player-string-test + (is (= "Added abc to the list of players for Quasi-Rts!" + (add-player-string "abc" "Quasi-Rts")))) + +(deftest remove-player-string-test + (is (= "Removed abc from the list of players for hypothetical-shooter!" + (remove-player-string "abc" "hypothetical-shooter"))))