added !tz

master
opfez 2021-05-17 13:48:05 +00:00
parent 090a11042e
commit 41eb8315f1
1 changed files with 24 additions and 1 deletions

25
anna.scm 100644 → 100755
View File

@ -11,6 +11,7 @@
(rnrs exceptions))
(define +channels+ '("#tildetown" "#bots"))
;; (define +channels+ '("#bots"))
(define (scdr lst)
"Safe CDR. Returns CDR of lst, if it is a list. Returns lst otherwise."
@ -58,6 +59,14 @@
port)))
sock))
(define (get-username str)
(define (get-username-list lst)
(cond ((null? lst) '())
((eq? (car lst) #\!) '())
(else (cons (car lst)
(get-username-list (cdr lst))))))
(list->string (cdr (get-username-list (string->list str)))))
(define (pong stream)
(format stream "PONG :anna\r\n"))
@ -103,6 +112,16 @@
((eq? language 'cl) (find-cl-documentation search))
(else "Unrecognized language! Supported languages are: cl")))
(define (read-file f)
(call-with-input-file f get-string-all))
(define (timezone user)
(let ((path (string-append "/home/" user "/.tz")))
(if (access? path R_OK)
(read-file path)
(string-append user
" has not set their timezone. Use `echo '<timezone here>' > ~/.tz' to add your timezone."))))
(define (slice start end lst)
"Return the list between index start and end (start inclusive, end not inclusive)."
(cond
@ -154,7 +173,7 @@
(pong stream))
((or (equal? ":!rollcall" (slist-ref data 3))
(equal? ":!anna" (slist-ref data 3)))
(send-message stream chn "Hello! I respond to !rollcall, !anna, and !eval <s-expr>."))
(send-message stream chn "Hello! I respond to !rollcall, !anna, !tz <optionally user>, and !eval <s-expr>."))
((equal? ":!eval" (slist-ref data 3))
(let ((expr (string-concatenate (intersperse " " (cdr (member ":!eval" filtered-data))))))
(send-message stream chn (evaluate expr))))
@ -162,6 +181,10 @@
(let ((lang (slist-ref data 4))
(search (escape-string (string-concatenate (intersperse " " (cddr (member ":!doc" filtered-data)))))))
(send-message stream chn (find-documentation (string->symbol lang) search))))
((equal? ":!tz" (slist-ref data 3))
(send-message stream chn (if (= 4 (length data))
(timezone (get-username (car data)))
(timezone (slist-ref data 4)))))
((and (= 7 (length data))
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
(send-action stream chn "dies")