1
0
Innokenty Enikev 10 роки тому
батько
коміт
07bd52d6c8
2 змінених файлів з 22 додано та 3 видалено
  1. 15 0
      chatikbot.lisp
  2. 7 3
      foursquare.lisp

+ 15 - 0
chatikbot.lisp

@@ -68,6 +68,7 @@
               (:daily (handle-cmd-weather chat-id id '("daily")))
               (:rates (handle-cmd-rates chat-id id args))
               (:postcheckins (handle-cmd-post-checkins chat-id id args))
+              (:checkins (handle-cmd-checkins chat-id id args))
               (otherwise (handle-admin-cmd chat-id text cmd args))))
           (send-dont-understand chat-id (preprocess-input text))))
     (when location
@@ -213,6 +214,20 @@
                   (telegram-send-message chat-id (format nil "Теперь палим ~A" user)))))
           (setf (gethash chat-id *fsq-send-to*) users)))))
 
+(defun handle-cmd-checkins (chat-id message-id args)
+  (log:info "handle-cmd-checkins" chat-id message-id args)
+  (handler-case
+      (let ((users (gethash chat-id *fsq-send-to*)))
+	(when users
+	  (telegram-send-message
+	   chat-id
+	   (format nil "~{~A~^~%~}"
+		   (loop for checkin in (fsq-fetch-checkins)
+		      if (member (aget "id" (aget "user" checkin)) users :test #'equal)
+		      collect (fsq-format-checkin checkin t))))))
+    (error (e) (log:error e))))
+
+
 (defvar *fsq-seen-ids* nil "Ids of seen checkins")
 
 (defun process-latest-checkins ()

+ 7 - 3
foursquare.lisp

@@ -36,11 +36,15 @@
       (setf *fsq-last-timestamp* (princ-to-string (1+ (aget "createdAt" (first recent))))))
     recent))
 
-(defun fsq-format-checkin (checkin)
+(defun fsq-format-checkin (checkin &optional with-dates)
   (when checkin
     (let ((user (aget "user" checkin))
           (venue (aget "venue" checkin)))
-      (format nil "📍 ~@[~A~]~@[ ~A~]~@[ в ~A~]~@[ (~A)~]~@[ 📢 ~A~]"
+      (format nil "📍 ~@[~A~]~@[ ~A~]~@[ в ~A~]~@[ (~A)~]~@[ 📢 ~A~]~:[~; ~A~]"
               (aget "firstName" user) (aget "lastName" user)
               (aget "name" venue) (first (aget "formattedAddress" (aget "location" venue)))
-              (aget "shout" checkin)))))
+              (aget "shout" checkin)
+	      with-dates (local-time:format-timestring
+			  nil
+			  (local-time:unix-to-timestamp (aget "createdAt" checkin))
+			  :format '(:year "-" (:month 2) "-" (:day 2) " " (:hour 2) ":" (:min 2)))))))