| 123456789101112131415161718192021222324252627282930 |
- (in-package #:chatikbot)
- (defmacro handling-errors (&body body)
- `(handler-case (progn ,@body)
- (simple-condition (err)
- (format *error-output* "~&~A: ~%" (class-name (class-of err)))
- (apply (function format) *error-output*
- (simple-condition-format-control err)
- (simple-condition-format-arguments err))
- (format *error-output* "~&"))
- (condition (err)
- (format *error-output* "~&~A: ~% ~S~%"
- (class-name (class-of err)) err))))
- (defun rep (input)
- (when input
- (with-output-to-string (*standard-output*)
- (let ((*package* (find-package 'chatikbot))
- (*error-output* *standard-output*))
- (handling-errors
- (format t "~{~S~^ ;~% ~}~%"
- (multiple-value-list (eval (read-from-string input)))))))))
- (def-message-handler handler-admin (message)
- (when (member from-id *admins*)
- (multiple-value-bind (cmd args) (parse-cmd text)
- (case cmd
- (:eval (bot-send-message chat-id (rep (format nil "~{~A~^ ~}" args))))
- (otherwise (send-dont-understand chat-id (preprocess-input (subseq text 1))))))
- t))
|