|
|
@@ -245,9 +245,6 @@
|
|
|
|
|
|
|
|
|
;; Foursquare
|
|
|
-(defvar *fsq-send-to* (make-hash-table)
|
|
|
- "Hash of chat-id's to fsq users list to send checkings to")
|
|
|
-
|
|
|
(defun fsq-user-name (user)
|
|
|
(when user
|
|
|
(format nil "~@[~A~]~@[ ~A~]"
|
|
|
@@ -257,7 +254,7 @@
|
|
|
(defun handle-cmd-post-checkins (chat-id message-id args)
|
|
|
(log:info "handle-cmd-post-checkins" chat-id message-id args)
|
|
|
(handler-case
|
|
|
- (let ((users (gethash chat-id *fsq-send-to*))
|
|
|
+ (let ((users (db-fsq-get-chat-users chat-id))
|
|
|
(friends (fsq-fetch-friends)))
|
|
|
(if (null args)
|
|
|
(telegram-send-message chat-id
|
|
|
@@ -283,8 +280,7 @@
|
|
|
(progn
|
|
|
(push user users)
|
|
|
(telegram-send-message chat-id (format nil "Теперь палим ~A" username)))))))
|
|
|
- (setf (gethash chat-id *fsq-send-to*) users)
|
|
|
- (save-settings))))
|
|
|
+ (db-fsq-set-chat-users chat-id users))))
|
|
|
(error (e)
|
|
|
(log:error e)
|
|
|
(telegram-send-message chat-id "Ошибочка вышла"))))
|
|
|
@@ -292,7 +288,7 @@
|
|
|
(defun handle-cmd-fsq-friends (chat-id message-id args)
|
|
|
(log:info "handle-cmd-fsq-friends" chat-id message-id args)
|
|
|
(handler-case
|
|
|
- (let ((users (gethash chat-id *fsq-send-to*))
|
|
|
+ (let ((users (db-fsq-get-chat-users chat-id))
|
|
|
(friends (fsq-fetch-friends)))
|
|
|
(telegram-send-message
|
|
|
chat-id
|
|
|
@@ -309,7 +305,7 @@
|
|
|
(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*)))
|
|
|
+ (let ((users (db-fsq-get-chat-users chat-id)))
|
|
|
(when users
|
|
|
(telegram-send-message
|
|
|
chat-id
|
|
|
@@ -320,20 +316,19 @@
|
|
|
(error (e) (log:error e))))
|
|
|
|
|
|
|
|
|
-(defvar *fsq-seen-ids* nil "Ids of seen checkins")
|
|
|
-
|
|
|
(defun process-latest-checkins ()
|
|
|
(handler-case
|
|
|
- (let ((checkins (make-hash-table)))
|
|
|
- (dolist (checkin (fsq-fetch-new-checkins))
|
|
|
+ (let ((checkins (make-hash-table))
|
|
|
+ (ts (princ-to-string (1+ (or (db-fsq-last-created) -1)))))
|
|
|
+ (dolist (checkin (fsq-fetch-checkins ts))
|
|
|
(let ((id (aget "id" checkin))
|
|
|
+ (created-at (aget "createdAt" 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*))))
|
|
|
+ (unless (db-fsq-has-seen id)
|
|
|
+ (dolist (chat-id (db-fsq-get-user-chats user))
|
|
|
+ (push (fsq-format-checkin checkin)
|
|
|
+ (gethash chat-id checkins)))
|
|
|
+ (db-fsq-add-seen id created-at))))
|
|
|
(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))))
|
|
|
@@ -453,8 +448,7 @@
|
|
|
:if-does-not-exist :create)
|
|
|
(write '(in-package #:chatikbot) :stream s)
|
|
|
(write
|
|
|
- `(setf *fsq-send-to* (alexandria:alist-hash-table ',(alexandria:hash-table-alist *fsq-send-to*))
|
|
|
- *chat-locations* ',*chat-locations*
|
|
|
+ `(setf *chat-locations* ',*chat-locations*
|
|
|
*akb-send-to* ',*akb-send-to*
|
|
|
*akb-last-id* ,*akb-last-id*
|
|
|
*rss-chat-feeds* (%load-rss-feeds ',(%save-rss-feeds)))
|