Преглед изворни кода

Fsq, join checkins for the same chat together

Innocenty Enikeew пре 10 година
родитељ
комит
52db4fa0a3
1 измењених фајлова са 13 додато и 9 уклоњено
  1. 13 9
      chatikbot.lisp

+ 13 - 9
chatikbot.lisp

@@ -271,15 +271,19 @@
 
 (defun process-latest-checkins ()
   (handler-case
-      (dolist (checkin (fsq-fetch-new-checkins))
-        (let ((id (aget "id" checkin))
-              (user (aget "id" (aget "user" checkin))))
-          (unless (find id *fsq-seen-ids* :test #'equal)
-            (loop for chat-id being the hash-keys in *fsq-send-to* using (hash-value users)
-               do (when (member user users :test #'equal)
-                    (log:info "Sending checkin" chat-id (fsq-format-checkin checkin))
-                    (telegram-send-message chat-id (fsq-format-checkin checkin))))
-            (push id *fsq-seen-ids*))))
+      (let ((checkins (make-hash-table)))
+        (dolist (checkin (fsq-fetch-new-checkins))
+          (let ((id (aget "id" checkin))
+                (user (aget "id" (aget "user" checkin))))
+            (unless (find id *fsq-seen-ids* :test #'equal)
+              (loop for chat-id being the hash-keys in *fsq-send-to* using (hash-value users)
+                 do (when (member user users :test #'equal)
+                      (push (fsq-format-checkin checkin)
+                            (gethash chat-id checkins))))
+              (push id *fsq-seen-ids*))))
+        (loop for chat-id being the hash-keys in checkins using (hash-value texts)
+           do (log:info "Sending checkins" chat-id texts)
+             (telegram-send-message chat-id (format nil "~{~A~^~%~}" texts))))
     (error (e) (log:error e))))