Innocenty Enikeew преди 10 години
родител
ревизия
caa4fcc7a2
променени са 1 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 22 0
      chatikbot.lisp

+ 22 - 0
chatikbot.lisp

@@ -108,6 +108,27 @@
               for i = 1 then (1+ i)
               collect (format nil "~D. ~A [~A]" i text type)))))
 
+(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)))))))))
+
 (defun handle-admin-cmd (chat-id text cmd args)
   (if (find chat-id *admins*)
       (case cmd
@@ -120,6 +141,7 @@
          (setf *responses* (delete (nth (1- (parse-integer (car args))) *responses*) *responses*))
          (%admin-send-responses chat-id))
         (:sendresponse (send-response chat-id (nth (1- (parse-integer (car args))) *responses*)))
+        (:eval (telegram-send-message chat-id (rep (format nil "~{~A~^ ~}" args))))
         (otherwise (send-dont-understand chat-id text)))
       (send-dont-understand chat-id text)))