admin.lisp 1.1 KB

123456789101112131415161718192021222324252627282930
  1. (in-package #:chatikbot)
  2. (defmacro handling-errors (&body body)
  3. `(handler-case (progn ,@body)
  4. (simple-condition (err)
  5. (format *error-output* "~&~A: ~%" (class-name (class-of err)))
  6. (apply (function format) *error-output*
  7. (simple-condition-format-control err)
  8. (simple-condition-format-arguments err))
  9. (format *error-output* "~&"))
  10. (condition (err)
  11. (format *error-output* "~&~A: ~% ~S~%"
  12. (class-name (class-of err)) err))))
  13. (defun rep (input)
  14. (when input
  15. (with-output-to-string (*standard-output*)
  16. (let ((*package* (find-package 'chatikbot))
  17. (*error-output* *standard-output*))
  18. (handling-errors
  19. (format t "~{~S~^ ;~% ~}~%"
  20. (multiple-value-list (eval (read-from-string input)))))))))
  21. (def-message-handler handler-admin (message)
  22. (when (member from-id *admins*)
  23. (multiple-value-bind (cmd args) (parse-cmd text)
  24. (case cmd
  25. (:eval (bot-send-message chat-id (rep (format nil "~{~A~^ ~}" args))))
  26. (otherwise (send-dont-understand chat-id (preprocess-input (subseq text 1))))))
  27. t))