Parcourir la source

[ledger] print

Innocenty Enikeew il y a 8 ans
Parent
commit
4f4bd31711
3 fichiers modifiés avec 24 ajouts et 2 suppressions
  1. 22 0
      plugins/ledger.lisp
  2. 1 1
      plugins/raiffeisen.lisp
  3. 1 1
      plugins/tinkoff.lisp

+ 22 - 0
plugins/ledger.lisp

@@ -83,6 +83,28 @@
     ((null args) (ledger/handle-balance chat-id "assets"))
     ((null args) (ledger/handle-balance chat-id "assets"))
     (:otherwise (ledger/handle-balance chat-id (spaced args)))))
     (:otherwise (ledger/handle-balance chat-id (spaced args)))))
 
 
+(defun ledger/handle-journal (chat-id query)
+  (let ((pair (gethash chat-id *ledger/chat-journals*)))
+    (if pair
+        (destructuring-bind (journal . ut) pair
+          (let* ((entries (pta-ledger:journal-print journal query))
+                 (len (length entries))
+                 (count (min len 20)))
+            (bot-send-message chat-id (format nil "```~%~{~A~^ ~%~%~}```Обновлено: ~A"
+                                              (subseq entries (- len count) len)
+                                              (ledger/format-time ut))
+                              :parse-mode "markdown")))
+        (with-secret (uri (list :ledger chat-id))
+          (if uri
+              (progn (ledger/parse-uri chat-id uri)
+                     (ledger/handle-balance chat-id query))
+              (send-response chat-id "Добавь урл журнала, /ledger <url>"))))))
+
+(def-message-cmd-handler handler-journal (:journal)
+  (cond
+    ((null args) (ledger/handle-journal chat-id "date:thisweek"))
+    (:otherwise (ledger/handle-journal chat-id (spaced args)))))
+
 (def-webhook-handler ledger/handle-webhook ("ledger")
 (def-webhook-handler ledger/handle-webhook ("ledger")
   (when (= 2 (length paths))
   (when (= 2 (length paths))
     (destructuring-bind (chat-id hmac) paths
     (destructuring-bind (chat-id hmac) paths

+ 1 - 1
plugins/raiffeisen.lisp

@@ -259,7 +259,7 @@
           (new (get-chat-last-entries chat-id (* 7 +day+))))
           (new (get-chat-last-entries chat-id (* 7 +day+))))
       (when new
       (when new
         (when old
         (when old
-          (alexandria:when-let (changes (set-difference new old :test #'equal))
+          (alexandria:when-let (changes (set-difference new old :test #'equalp))
             (log:info changes)
             (log:info changes)
             (bot-send-message chat-id (format-changes changes) :parse-mode "markdown")))
             (bot-send-message chat-id (format-changes changes) :parse-mode "markdown")))
         (setf (gethash chat-id *last-entries*) new)))))
         (setf (gethash chat-id *last-entries*) new)))))

+ 1 - 1
plugins/tinkoff.lisp

@@ -212,7 +212,7 @@
           (new (get-chat-last-entries chat-id (* 7 24 60 60))))
           (new (get-chat-last-entries chat-id (* 7 24 60 60))))
       (when new
       (when new
         (when old
         (when old
-          (alexandria:when-let (changes (set-difference new old :test #'equal))
+          (alexandria:when-let (changes (set-difference new old :test #'equalp))
             (log:info changes)
             (log:info changes)
             (bot-send-message chat-id (format-entries changes) :parse-mode "markdown")))
             (bot-send-message chat-id (format-entries changes) :parse-mode "markdown")))
         (setf (gethash chat-id *last-entries*) new)))))
         (setf (gethash chat-id *last-entries*) new)))))