don't crash on errors in evaluate
parent
7a75544e46
commit
dc699e006b
14
anna.scm
14
anna.scm
|
@ -3,7 +3,9 @@
|
|||
|
||||
(use-modules (ice-9 rdelim)
|
||||
(ice-9 textual-ports)
|
||||
(ice-9 format))
|
||||
(ice-9 format)
|
||||
(ice-9 control)
|
||||
(rnrs exceptions))
|
||||
|
||||
(define +channels+ '("#tildetown" "#bots"))
|
||||
|
||||
|
@ -67,13 +69,18 @@
|
|||
(format stream "JOIN ~a\r\n" chn))
|
||||
+channels+))
|
||||
|
||||
|
||||
(define (send-message stream chn msg)
|
||||
(format stream "PRIVMSG ~a :~a\r\n" chn msg))
|
||||
|
||||
(define (send-action stream chn action)
|
||||
(format stream "PRIVMSG ~a :\x01ACTION ~a\x01\r\n" chn action))
|
||||
|
||||
(define (evaluate str)
|
||||
(guard (ex
|
||||
(else (begin (display "error encountered!\n")
|
||||
'error)))
|
||||
(eval (read (open-input-string str)) (interaction-environment))))
|
||||
|
||||
(define (main-loop stream)
|
||||
(let* ((inl (read-line stream))
|
||||
(data (string-tokenize inl))
|
||||
|
@ -88,8 +95,7 @@
|
|||
(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))))))
|
||||
(send-message stream chn (eval (read (open-input-string expr))
|
||||
(interaction-environment)))))
|
||||
(send-message stream chn (evaluate expr))))
|
||||
((and (= 7 (length data))
|
||||
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
|
||||
(send-action stream chn "dies")
|
||||
|
|
Loading…
Reference in New Issue