|
@@ -22,26 +22,28 @@
|
|
|
(values))))
|
|
(values))))
|
|
|
|
|
|
|
|
(defmacro with-parsed-message (message &body body)
|
|
(defmacro with-parsed-message (message &body body)
|
|
|
- `(let ((*message-id* (agets ,message "message_id"))
|
|
|
|
|
- (*from-id* (agets ,message "from" "id"))
|
|
|
|
|
- (*chat-id* (agets ,message "chat" "id"))
|
|
|
|
|
- (*text* (agets ,message "text")))
|
|
|
|
|
|
|
+ `(let* ((*message* ,message)
|
|
|
|
|
+ (*message-id* (agets *message* "message_id"))
|
|
|
|
|
+ (*from-id* (agets *message* "from" "id"))
|
|
|
|
|
+ (*chat-id* (agets *message* "chat" "id"))
|
|
|
|
|
+ (*text* (agets *message* "text")))
|
|
|
,@body))
|
|
,@body))
|
|
|
|
|
|
|
|
-(defmacro def-message-handler (name (message &optional prio) &body body)
|
|
|
|
|
- `(progn
|
|
|
|
|
- (defun ,name (,message)
|
|
|
|
|
- (with-parsed-message ,message
|
|
|
|
|
- (handler-case (progn ,@body)
|
|
|
|
|
- (error (e)
|
|
|
|
|
- (log:error "~A" e)
|
|
|
|
|
- (bot-send-message (format nil "Ошибочка вышла~@[: ~A~]"
|
|
|
|
|
- (when (is-admin) e)))))))
|
|
|
|
|
- (when ,prio (setf (get ',name :prio) ,prio))
|
|
|
|
|
- (add-hook :update-message ',name)))
|
|
|
|
|
|
|
+(defmacro def-message-handler (name (&optional prio) &body body)
|
|
|
|
|
+ (alexandria:with-gensyms (g-message)
|
|
|
|
|
+ `(progn
|
|
|
|
|
+ (defun ,name (,g-message)
|
|
|
|
|
+ (with-parsed-message ,g-message
|
|
|
|
|
+ (handler-case (progn ,@body)
|
|
|
|
|
+ (error (e)
|
|
|
|
|
+ (log:error "~A" e)
|
|
|
|
|
+ (bot-send-message (format nil "Ошибочка вышла~@[: ~A~]"
|
|
|
|
|
+ (when (is-admin) e)))))))
|
|
|
|
|
+ (when ,prio (setf (get ',name :prio) ,prio))
|
|
|
|
|
+ (add-hook :update-message ',name))))
|
|
|
|
|
|
|
|
(defmacro def-message-cmd-handler (name (&rest commands) &body body)
|
|
(defmacro def-message-cmd-handler (name (&rest commands) &body body)
|
|
|
- `(def-message-handler ,name (*message*)
|
|
|
|
|
|
|
+ `(def-message-handler ,name ()
|
|
|
(when (and *text* (equal #\/ (char *text* 0)))
|
|
(when (and *text* (equal #\/ (char *text* 0)))
|
|
|
(multiple-value-bind (*cmd* *args*) (parse-cmd *text*)
|
|
(multiple-value-bind (*cmd* *args*) (parse-cmd *text*)
|
|
|
(when (member *cmd* (list ,@commands))
|
|
(when (member *cmd* (list ,@commands))
|
|
@@ -50,7 +52,7 @@
|
|
|
t)))))
|
|
t)))))
|
|
|
|
|
|
|
|
(defmacro def-message-admin-cmd-handler (name (&rest commands) &body body)
|
|
(defmacro def-message-admin-cmd-handler (name (&rest commands) &body body)
|
|
|
- `(def-message-handler ,name (*message*)
|
|
|
|
|
|
|
+ `(def-message-handler ,name ()
|
|
|
(when (and (is-admin)
|
|
(when (and (is-admin)
|
|
|
*text* (equal #\/ (char *text* 0)))
|
|
*text* (equal #\/ (char *text* 0)))
|
|
|
(multiple-value-bind (*cmd* *args*) (parse-cmd *text*)
|
|
(multiple-value-bind (*cmd* *args*) (parse-cmd *text*)
|
|
@@ -60,31 +62,34 @@
|
|
|
t)))))
|
|
t)))))
|
|
|
|
|
|
|
|
(defmacro with-parsed-callback (callback &body body)
|
|
(defmacro with-parsed-callback (callback &body body)
|
|
|
- `(let* ((*query-id* (agets ,callback "id"))
|
|
|
|
|
- (*from* (agets ,callback "from"))
|
|
|
|
|
- (*raw-data* (agets ,callback "data"))
|
|
|
|
|
- (*source-message* (agets ,callback "message"))
|
|
|
|
|
- (*inline-message-id* (agets ,callback "inline_message_id"))
|
|
|
|
|
|
|
+ `(let* ((*callback* ,callback)
|
|
|
|
|
+ (*query-id* (agets *callback* "id"))
|
|
|
|
|
+ (*from* (agets *callback* "from"))
|
|
|
|
|
+ (*raw-data* (agets *callback* "data"))
|
|
|
|
|
+ (*source-message* (agets *callback* "message"))
|
|
|
|
|
+ (*inline-message-id* (agets *callback* "inline_message_id"))
|
|
|
(*from-id* (agets *from* "id"))
|
|
(*from-id* (agets *from* "id"))
|
|
|
(*source-chat-id* (agets *source-message* "chat" "id"))
|
|
(*source-chat-id* (agets *source-message* "chat" "id"))
|
|
|
- (*source-message-id* (agets *source-message* "message_id")))
|
|
|
|
|
|
|
+ (*source-message-id* (agets *source-message* "message_id"))
|
|
|
|
|
+ (*chat-id* *source-chat-id*))
|
|
|
,@body))
|
|
,@body))
|
|
|
|
|
|
|
|
-(defmacro def-callback-handler (name (callback &optional prio) &body body)
|
|
|
|
|
- `(progn
|
|
|
|
|
- (defun ,name (,callback)
|
|
|
|
|
- (with-parsed-callback ,callback
|
|
|
|
|
- (handler-case (progn ,@body)
|
|
|
|
|
- (error (e)
|
|
|
|
|
- (log:error "~A" e)
|
|
|
|
|
- (bot-send-message (format nil "Ошибочка вышла~@[: ~A~]"
|
|
|
|
|
- (when (member *source-chat-id* *admins*) e))
|
|
|
|
|
- :chat-id (or *source-chat-id* *from-id*))))))
|
|
|
|
|
- (when ,prio (setf (get ',name :prio) ,prio))
|
|
|
|
|
- (add-hook :update-callback-query ',name)))
|
|
|
|
|
|
|
+(defmacro def-callback-handler (name (&optional prio) &body body)
|
|
|
|
|
+ (alexandria:with-gensyms (g-callback)
|
|
|
|
|
+ `(progn
|
|
|
|
|
+ (defun ,name (,g-callback)
|
|
|
|
|
+ (with-parsed-callback ,g-callback
|
|
|
|
|
+ (handler-case (progn ,@body)
|
|
|
|
|
+ (error (e)
|
|
|
|
|
+ (log:error "~A" e)
|
|
|
|
|
+ (bot-send-message (format nil "Ошибочка вышла~@[: ~A~]"
|
|
|
|
|
+ (when (is-admin*) e))
|
|
|
|
|
+ :chat-id (or *source-chat-id* *from-id*))))))
|
|
|
|
|
+ (when ,prio (setf (get ',name :prio) ,prio))
|
|
|
|
|
+ (add-hook :update-callback-query ',name))))
|
|
|
|
|
|
|
|
(defmacro def-callback-section-handler (name (&rest sections) &body body)
|
|
(defmacro def-callback-section-handler (name (&rest sections) &body body)
|
|
|
- `(def-callback-handler ,name (*callback*)
|
|
|
|
|
|
|
+ `(def-callback-handler ,name ()
|
|
|
(when *source-chat-id*
|
|
(when *source-chat-id*
|
|
|
(multiple-value-bind (*data* *section*) (decode-callback-data *source-chat-id* *raw-data*)
|
|
(multiple-value-bind (*data* *section*) (decode-callback-data *source-chat-id* *raw-data*)
|
|
|
(when (member *section* (list ,@sections))
|
|
(when (member *section* (list ,@sections))
|