add text filtering and remove newlines from input (thanks natalia\!)
parent
775eb31bc0
commit
34b6b3eee4
14
anna.scm
14
anna.scm
|
@ -76,10 +76,19 @@
|
|||
(define (send-action stream chn action)
|
||||
(format stream "PRIVMSG ~a :\x01ACTION ~a\x01\r\n" chn action))
|
||||
|
||||
(define (input-filter str)
|
||||
(define (remove-newline lst)
|
||||
(cond
|
||||
((or (null? lst)
|
||||
(null? (cdr lst))) lst)
|
||||
((eq? (car lst) #\\) (remove-newline (cddr lst)))
|
||||
(else (cons (car lst) (remove-newline (cdr lst))))))
|
||||
(list->string (remove-newline (string->list str))))
|
||||
|
||||
(define (evaluate str)
|
||||
(guard (ex
|
||||
(else (begin (display "error encountered!\n")
|
||||
'error)))
|
||||
'error))) ;; << this gets printed in chat
|
||||
(eval-in-sandbox (read (open-input-string str)))))
|
||||
|
||||
(define (main-loop stream)
|
||||
|
@ -95,7 +104,8 @@
|
|||
(equal? ":!anna" (slist-ref data 3)))
|
||||
(send-message stream chn "Hello! I respond to !rollcall, !anna, and !eval <s-expr>."))
|
||||
((equal? ":!eval" (slist-ref data 3))
|
||||
(let* ((expr (string-concatenate (intersperse " " (cdr (member ":!eval" data))))))
|
||||
(let* ((filtered-data (map input-filter data))
|
||||
(expr (string-concatenate (intersperse " " (cdr (member ":!eval" filtered-data))))))
|
||||
(send-message stream chn (evaluate expr))))
|
||||
((and (= 7 (length data))
|
||||
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
|
||||
|
|
Loading…
Reference in New Issue