-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.clj
31 lines (27 loc) · 1.01 KB
/
bot.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns bot)
(defn log
[arg]
(.println *err* (pr-str arg))
arg)
(defn send-command
[command]
(println command))
(defn parse
[state line]
; (bot/log line)
(if (or (empty? line) (= \# (first line)))
state
(let [parts (clojure.string/split line #" ")
[[handler args]] (for [s [2 1]
:let [name (clojure.string/replace (clojure.string/join "_" (take s parts)) "/" "_")
handler (find-var (symbol (str "handlers/" name)))
args (drop s parts)]
:when handler]
[handler args])]
(if (nil? handler)
(throw (Exception. (str "Don't recognize: " line)))
; (do (prn handler args)
(apply handler (cons state args)))))) ;)
(defn -main
[]
(reduce parse {:round 0} (line-seq (java.io.BufferedReader. *in*))))