|
@@ -196,6 +196,64 @@
|
|
|
((null args) (ledger/handle-journal chat-id "date:thisweek"))
|
|
((null args) (ledger/handle-journal chat-id "date:thisweek"))
|
|
|
(:otherwise (ledger/handle-journal chat-id (spaced args)))))
|
|
(:otherwise (ledger/handle-journal chat-id (spaced args)))))
|
|
|
|
|
|
|
|
|
|
+(def-message-cmd-handler hander-add-report (:add_report)
|
|
|
|
|
+ (bot-send-message chat-id "Введи название"
|
|
|
|
|
+ :reply-markup (telegram-force-reply))
|
|
|
|
|
+ (on-next-message chat-id
|
|
|
|
|
+ (let ((name text))
|
|
|
|
|
+ (bot-send-message chat-id "Введи запрос"
|
|
|
|
|
+ :reply-markup (telegram-force-reply))
|
|
|
|
|
+ (on-next-message chat-id
|
|
|
|
|
+ (let ((query text))
|
|
|
|
|
+ (pta-ledger:parse-query query) ;; Validate query
|
|
|
|
|
+ (bot-send-message chat-id "Введи расписание, ex: (:day-of-week 0 :hour 10), (:day * :hour 10)"
|
|
|
|
|
+ :reply-markup (telegram-force-reply))
|
|
|
|
|
+ (on-next-message chat-id
|
|
|
|
|
+ (let* ((schedule text))
|
|
|
|
|
+ (add-chat-cron :ledger-report chat-id schedule name query)
|
|
|
|
|
+ (bot-send-message chat-id "Добавил"))))))))
|
|
|
|
|
+
|
|
|
|
|
+(defun run-report (chat-id name query)
|
|
|
|
|
+ (with-chat-journal (chat-id journal updated)
|
|
|
|
|
+ (bot-send-message chat-id
|
|
|
|
|
+ (text-chunks (split-sequence:split-sequence
|
|
|
|
|
+ #\Newline
|
|
|
|
|
+ (format nil "*~A*~%~%~A" name
|
|
|
|
|
+ (pta-ledger:journal-balance journal query)))
|
|
|
|
|
+ :text-sep "
|
|
|
|
|
+")
|
|
|
|
|
+ :parse-mode "markdown")))
|
|
|
|
|
+
|
|
|
|
|
+(def-chat-cron-handler handler-chat-cron (:ledger-report chat-id schedule name query)
|
|
|
|
|
+ (run-report chat-id name query))
|
|
|
|
|
+
|
|
|
|
|
+(def-message-cmd-handler handler-reports (:reports)
|
|
|
|
|
+ (let ((crons (get-chat-crons :ledger-report chat-id)))
|
|
|
|
|
+ (if crons
|
|
|
|
|
+ (bot-send-message
|
|
|
|
|
+ chat-id "Отчёты"
|
|
|
|
|
+ :parse-mode "markdown"
|
|
|
|
|
+ :reply-markup
|
|
|
|
|
+ (get-inline-keyboard
|
|
|
|
|
+ chat-id
|
|
|
|
|
+ (append
|
|
|
|
|
+ (loop for (schedule name query) in crons
|
|
|
|
|
+ for idx from 0
|
|
|
|
|
+ collect
|
|
|
|
|
+ (let ((cron-index idx)
|
|
|
|
|
+ (cron-name name))
|
|
|
|
|
+ (list (inline-button ((format nil "Удалить '~A'" cron-name))
|
|
|
|
|
+ (delete-chat-cron :ledger-report chat-id cron-index)
|
|
|
|
|
+ (bot-send-message chat-id (format nil "Удалил *~A*" cron-name)
|
|
|
|
|
+ :parse-mode "markdown")))))
|
|
|
|
|
+ (list (list (inline-button ("Отмена")
|
|
|
|
|
+ (telegram-edit-message-reply-markup
|
|
|
|
|
+ nil :chat-id source-chat-id :message-id source-message-id)))))))
|
|
|
|
|
+ (bot-send-message
|
|
|
|
|
+ chat-id "Отчётов пока нет"
|
|
|
|
|
+ :reply-markup (telegram-reply-keyboard-markup (list (list (list :text "/add_report")))
|
|
|
|
|
+ :one-time-keyboard t)))))
|
|
|
|
|
+
|
|
|
(defun match-entry (text journal)
|
|
(defun match-entry (text journal)
|
|
|
(labels ((two-post (entries)
|
|
(labels ((two-post (entries)
|
|
|
(remove-if-not #'(lambda (e)
|
|
(remove-if-not #'(lambda (e)
|