add greets
parent
41eb8315f1
commit
23c4a2cf00
58
anna.scm
58
anna.scm
|
@ -161,6 +161,43 @@
|
||||||
sublink)))
|
sublink)))
|
||||||
(else "Symbol not found in documentation."))))
|
(else "Symbol not found in documentation."))))
|
||||||
|
|
||||||
|
(define *left-greets* '())
|
||||||
|
(define *right-greets* '())
|
||||||
|
|
||||||
|
(define (greets category name)
|
||||||
|
(if (not (assoc name category))
|
||||||
|
"0"
|
||||||
|
(number->string (cdr (assoc name category)))))
|
||||||
|
|
||||||
|
;; has to be separate functions since modifying the argument won't change global state
|
||||||
|
(define (inc-left-greets name)
|
||||||
|
(if (not (assoc name *left-greets*))
|
||||||
|
(set! *left-greets* (acons name 1 *left-greets*))
|
||||||
|
(assoc-set! *left-greets* name (+ 1 (cdr (assoc name *left-greets*))))))
|
||||||
|
|
||||||
|
(define (inc-right-greets name)
|
||||||
|
(if (not (assoc name *right-greets*))
|
||||||
|
(set! *right-greets* (acons name 1 *right-greets*))
|
||||||
|
(assoc-set! *right-greets* name (+ 1 (cdr (assoc name *right-greets*))))))
|
||||||
|
|
||||||
|
(define (all-greets category)
|
||||||
|
(if (null? category)
|
||||||
|
0
|
||||||
|
(+ (cdr (car category))
|
||||||
|
(all-greets (cdr category)))))
|
||||||
|
|
||||||
|
(define (empty-list->string s)
|
||||||
|
(if (null? s)
|
||||||
|
""
|
||||||
|
s))
|
||||||
|
|
||||||
|
(define (concat-messages strings index length)
|
||||||
|
(if (= index length)
|
||||||
|
""
|
||||||
|
(string-append (slist-ref strings index)
|
||||||
|
(concat-messages strings (+ 1 index) length))))
|
||||||
|
|
||||||
|
|
||||||
(define (main-loop stream)
|
(define (main-loop stream)
|
||||||
(let* ((inl (read-line stream))
|
(let* ((inl (read-line stream))
|
||||||
(data (string-tokenize inl))
|
(data (string-tokenize inl))
|
||||||
|
@ -173,7 +210,7 @@
|
||||||
(pong stream))
|
(pong stream))
|
||||||
((or (equal? ":!rollcall" (slist-ref data 3))
|
((or (equal? ":!rollcall" (slist-ref data 3))
|
||||||
(equal? ":!anna" (slist-ref data 3)))
|
(equal? ":!anna" (slist-ref data 3)))
|
||||||
(send-message stream chn "Hello! I respond to !rollcall, !anna, !tz <optionally user>, and !eval <s-expr>."))
|
(send-message stream chn "Hello! I respond to !rollcall, !anna, !tz <optionally user>, !greets, !lgreets <optionally user>, !rgreets <optionally user>, and !eval <s-expr>. My source code is available at https://git.tilde.town/opfez/anna"))
|
||||||
((equal? ":!eval" (slist-ref data 3))
|
((equal? ":!eval" (slist-ref data 3))
|
||||||
(let ((expr (string-concatenate (intersperse " " (cdr (member ":!eval" filtered-data))))))
|
(let ((expr (string-concatenate (intersperse " " (cdr (member ":!eval" filtered-data))))))
|
||||||
(send-message stream chn (evaluate expr))))
|
(send-message stream chn (evaluate expr))))
|
||||||
|
@ -185,6 +222,25 @@
|
||||||
(send-message stream chn (if (= 4 (length data))
|
(send-message stream chn (if (= 4 (length data))
|
||||||
(timezone (get-username (car data)))
|
(timezone (get-username (car data)))
|
||||||
(timezone (slist-ref data 4)))))
|
(timezone (slist-ref data 4)))))
|
||||||
|
((equal? ":!lgreets" (slist-ref data 3))
|
||||||
|
(format #t "~s~%" *left-greets*)
|
||||||
|
(send-message stream chn (if (= 4 (length data))
|
||||||
|
(greets *left-greets* (get-username (car data)))
|
||||||
|
(greets *left-greets* (slist-ref data 4)))))
|
||||||
|
((equal? ":!rgreets" (slist-ref data 3))
|
||||||
|
(format #t "~s~%" *right-greets*)
|
||||||
|
(send-message stream chn (if (= 4 (length data))
|
||||||
|
(greets *right-greets* (get-username (car data)))
|
||||||
|
(greets *right-greets* (slist-ref data 4)))))
|
||||||
|
((equal? ":!greets" (slist-ref data 3))
|
||||||
|
(send-message stream chn (string-append "o/ - "
|
||||||
|
(number->string (all-greets *right-greets*))
|
||||||
|
" vs \\o - "
|
||||||
|
(number->string (all-greets *left-greets*)))))
|
||||||
|
((string-contains (empty-list->string (concat-messages data 3 (length data))) "\\o")
|
||||||
|
(inc-left-greets (get-username (car data))))
|
||||||
|
((string-contains (empty-list->string (concat-messages data 3 (length data))) "o/")
|
||||||
|
(inc-right-greets (get-username (car data))))
|
||||||
((and (= 7 (length data))
|
((and (= 7 (length data))
|
||||||
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
|
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
|
||||||
(send-action stream chn "dies")
|
(send-action stream chn "dies")
|
||||||
|
|
Loading…
Reference in New Issue