-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot-lib.bot
109 lines (97 loc) · 2.86 KB
/
bot-lib.bot
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(define-macro ; (lambda (x ...) "" )
)
(define ping
(lambda () "pong"))
(define report
(lambda (val str) str))
(define sayit
(lambda () "David's an idiot"))
(define slap
(lambda (args ...)
(join
(list
(if (nil? args)
(nth (name-list) (rand (len (name-list))))
(car args))
(if (zero? (rand 2))
"just got slapped. Hard."
"just got slapped." ))
" ")
)
)
(define hug
(lambda (args ...)
(join
(list
(if (nil? args)
(nth (name-list) (rand (len (name-list))))
(car args))
(if (zero? (rand 2))
"just got a BIG hug."
"just got a hug."))
" ")
)
)
(define y (lambda () "(y)"))
(define-once scores (ref (hashmap)))
(define-once lists (ref (hashmap)))
(define score (lambda (name) (if (nil? ((get scores) name)) 0 ((get scores) name))))
(define inc-score (lambda (name) (report (set! scores (assoc (get scores) name (+ 1 (score name)))) "Score increased")))
(define pp-list (lambda (name lst)
(join
(list
name
(join
(map (lambda (n item) (join (list n item) " - ")) (range (len lst)) lst)
"\n"
)
)
":\n-----\n"
)
))
(define list-all (lambda (args ...)
(cond
((nil? args)
(pp-list "All Lists" (map (lambda (e) (car e)) ((get lists)))))
((and (equal? (len args) 1) (type? (car args) "string"))
(pp-list (car args) ((get lists) (car args)))
)
(true "list-all should be called with no arguments or with the name of a list.")
)
))
(define list-add (lambda (args ...)
(cond
((and (equal? (len args) 1) (type? (car args) "string"))
(report (update! lists (lambda (lists-val) (assoc lists-val (car args) '()))) "List added."))
((and (equal? (len args) 2) (type? (car args) "string") (type? (second args) "string"))
(report
(update! lists
(lambda (lists-val)
(assoc lists-val
(car args)
(cons (second args)
(if (nil? ((get lists) (car args))) '()
((get lists) (car args)))))))
"List item added."
)
)
(true "list-add should be called with the name of a new list or with the name of a list and the content of an item.")
)
))
(define list-remove (lambda (args ...)
(cond
((and (equal? (len args) 1) (type? (car args) "string"))
(report (update! lists (lambda (lists-val) (dissoc lists-val (car args)))) "List added."))
((and (equal? (len args) 2) (type? (car args) "string") (type? (second args) "number"))
(report
(update! lists
(lambda (lists-val)
(assoc lists-val
(car args)
(remove-nth (lists-val (car args)) (second args)))))
"List item remove."
)
)
(true "list-add should be called with the name of a new list or with the name of a list and the content of an item.")
)
))