blob: dbe5dd456e319995b5fdcd610d5376a51f1d9030 (
plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
(require [asciifarm.client.keymacros [*]])
(import [asciifarm.client.keynames [nameFromKey]])
(defclass InputHandler []
(defn --init-- [self client display connection]
(setv self.client client)
(setv self.display display)
(setv self.connection connection)
(setv self.commands None))
(defn readCommands [self commandsstring]
(setv self.commands
(dict-comp
(eval key)
(
(eval `(do
(require [asciifarm.client.keymacros [*]])
(fn [handler]
(fn [] ~value))))
self)
[[key value] (.items (read-str commandsstring))])))
(defn runCommand [self commandstring]
(try
(eval (read-str (+ "(" commandstring ")")))
(except [e Exception]
(self.client.log (repr e)))))
(defn parseMessage [self message]
(if message
(if (= (first message) "/")
(do
(setv msg (.join "" (drop 1 message)))
(if (= (first msg) "/")
(send ["chat" msg])
(self.runCommand msg)))
(send ["chat" message]))))
(defn getDocs [self]
(if (in "help" self.commands) ((get self.commands "help")) ""))
(defn onKey [self key] (do
(setv keyname (nameFromKey key))
(if (in keyname self.commands) ((get self.commands keyname)))))
)
|