-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatching.l
82 lines (57 loc) · 1.84 KB
/
dispatching.l
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# some dispatching
(de add-handler (Pred Fun)
(push '*Handlers
(cons Pred Fun)))
(de add-const-handler (X Fun)
(add-handler (fcmd= X)
Fun))
(de f= (@X)
(fill '((x) (= @X x))))
(de fcmd= (@X)
(fill '((X) (= @X (cadr (assoc 'cmd X))))))
(de handle (Msg)
(mapcar (quote (x) (when ((car x) Msg)
((cdr x) Msg) ) )
*Handlers ) )
## Actions
#Oh glory Assoc Lists -- here we are again
(de getA (Sym ALst)
(cadr (assoc Sym ALst)))
(de add-action (Action Fun)
(push '*Actions
(cons Action Fun)))
(de action? (Msg)
(= "!" (car (chop (getA 'arg Msg)))))
(de parse-action (Msg)
(if (action? Msg)
(let (Words (words (getA 'arg Msg)))
(list
(list 'action (car Words))
(list 'args (mapcar 'pack (cdr Words)))))
NIL))
(setq *MinActionIntvl 1000000) # 1sec
(setq *LastActionTime (usec))
(de minTimePassed? ()
(> (- (usec) *LastActionTime)
*MinActionIntvl))
(de ircsend (Line)
(telnet-send
(pack (head 500 (chop Line)))))
(de handle-actions (Msg)
(when (action? Msg)
(if (minTimePassed?)
(let (*Msg Msg #Start a new Environment with some special Vars bound for reference
*From (getA 'from Msg)
*Arg (getA 'arg Msg)
*Cmd (getA 'cmd Msg)
*To (getA 'to Msg)
ActionMsg (parse-action Msg)
Action (cdr (assoc (cadr (assoc 'action ActionMsg)) *Actions)) )
(setq *LastActionTime (usec))
(when Action
(let Result (apply Action
(getA 'args ActionMsg)) # :)
(when Result
(ircsend (pack "PRIVMSG " (if (= (getConf 'Nick) *To) *From *To) " :" Result)) ) ) ) )
#else
(println "Action is calling too fast... Ignore this one: " Msg) ) ) )