|
@@ -74,7 +74,8 @@
|
|
|
(send-dont-understand chat-id (preprocess-input text))))
|
|
(send-dont-understand chat-id (preprocess-input text))))
|
|
|
(when location
|
|
(when location
|
|
|
(push (cons chat-id location) *chat-locations*)
|
|
(push (cons chat-id location) *chat-locations*)
|
|
|
- (telegram-send-message chat-id "Взял на карандаш"))
|
|
|
|
|
|
|
+ (telegram-send-message chat-id "Взял на карандаш")
|
|
|
|
|
+ (save-settings))
|
|
|
(when sticker
|
|
(when sticker
|
|
|
(send-dont-understand chat-id))))
|
|
(send-dont-understand chat-id))))
|
|
|
|
|
|
|
@@ -119,7 +120,8 @@
|
|
|
*akb-send-to* (set-difference *akb-send-to*
|
|
*akb-send-to* (set-difference *akb-send-to*
|
|
|
(list chat-id)))
|
|
(list chat-id)))
|
|
|
(setf *akb-send-to* (cons chat-id *akb-send-to*)))
|
|
(setf *akb-send-to* (cons chat-id *akb-send-to*)))
|
|
|
- (telegram-send-message chat-id message)))
|
|
|
|
|
|
|
+ (telegram-send-message chat-id message)
|
|
|
|
|
+ (save-settings)))
|
|
|
|
|
|
|
|
(defvar *akb-max-count* 5 "Max number of tweets to return per run")
|
|
(defvar *akb-max-count* 5 "Max number of tweets to return per run")
|
|
|
(defvar *akb-last-id* 0 "id of last AKB tweet")
|
|
(defvar *akb-last-id* 0 "id of last AKB tweet")
|
|
@@ -137,7 +139,8 @@
|
|
|
(let ((id (aget "id" post)))
|
|
(let ((id (aget "id" post)))
|
|
|
(when (> id *akb-last-id*)
|
|
(when (> id *akb-last-id*)
|
|
|
(send-akb (format-akb post))
|
|
(send-akb (format-akb post))
|
|
|
- (setf *akb-last-id* id))))
|
|
|
|
|
|
|
+ (setf *akb-last-id* id)
|
|
|
|
|
+ (save-settings))))
|
|
|
(error (e) (log:error e))))
|
|
(error (e) (log:error e))))
|
|
|
|
|
|
|
|
(defun send-akb (text)
|
|
(defun send-akb (text)
|
|
@@ -231,7 +234,8 @@
|
|
|
(progn
|
|
(progn
|
|
|
(push user users)
|
|
(push user users)
|
|
|
(telegram-send-message chat-id (format nil "Теперь палим ~A" username)))))))
|
|
(telegram-send-message chat-id (format nil "Теперь палим ~A" username)))))))
|
|
|
- (setf (gethash chat-id *fsq-send-to*) users))))
|
|
|
|
|
|
|
+ (setf (gethash chat-id *fsq-send-to*) users)
|
|
|
|
|
+ (save-settings))))
|
|
|
(error (e)
|
|
(error (e)
|
|
|
(log:error e)
|
|
(log:error e)
|
|
|
(telegram-send-message chat-id "Ошибочка вышла"))))
|
|
(telegram-send-message chat-id "Ошибочка вышла"))))
|
|
@@ -286,8 +290,23 @@
|
|
|
(telegram-send-message chat-id (format nil "~{~A~^~%~}" texts))))
|
|
(telegram-send-message chat-id (format nil "~{~A~^~%~}" texts))))
|
|
|
(error (e) (log:error e))))
|
|
(error (e) (log:error e))))
|
|
|
|
|
|
|
|
|
|
+(defun save-settings()
|
|
|
|
|
+ (with-open-file (s (merge-pathnames "settings.lisp"
|
|
|
|
|
+ (asdf:component-pathname
|
|
|
|
|
+ (asdf:find-system '#:chatikbot)))
|
|
|
|
|
+ :direction :output
|
|
|
|
|
+ :if-exists :supersede
|
|
|
|
|
+ :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*
|
|
|
|
|
+ *akb-send-to* ',*akb-send-to*
|
|
|
|
|
+ *akb-last-id* ,*akb-last-id*)
|
|
|
|
|
+ :stream s)))
|
|
|
|
|
|
|
|
(defun start ()
|
|
(defun start ()
|
|
|
|
|
+ ;; Clear prev threads
|
|
|
(mapc #'trivial-timers:unschedule-timer (trivial-timers:list-all-timers))
|
|
(mapc #'trivial-timers:unschedule-timer (trivial-timers:list-all-timers))
|
|
|
(let ((old-updates (find "process-updates"
|
|
(let ((old-updates (find "process-updates"
|
|
|
(bordeaux-threads:all-threads)
|
|
(bordeaux-threads:all-threads)
|
|
@@ -295,6 +314,13 @@
|
|
|
:test #'equal)))
|
|
:test #'equal)))
|
|
|
(when old-updates
|
|
(when old-updates
|
|
|
(bordeaux-threads:destroy-thread old-updates)))
|
|
(bordeaux-threads:destroy-thread old-updates)))
|
|
|
|
|
+ ;; Load settings file
|
|
|
|
|
+ (alexandria:when-let (file (probe-file
|
|
|
|
|
+ (merge-pathnames "settings.lisp"
|
|
|
|
|
+ (asdf:component-pathname
|
|
|
|
|
+ (asdf:find-system '#:chatikbot)))))
|
|
|
|
|
+ (load file))
|
|
|
|
|
+ ;; Start timers
|
|
|
(clon:schedule-function
|
|
(clon:schedule-function
|
|
|
(lambda () (process-latest-akb))
|
|
(lambda () (process-latest-akb))
|
|
|
(clon:make-scheduler
|
|
(clon:make-scheduler
|
|
@@ -307,6 +333,7 @@
|
|
|
(clon:make-typed-cron-schedule :minute '* :hour '*)
|
|
(clon:make-typed-cron-schedule :minute '* :hour '*)
|
|
|
:allow-now-p t)
|
|
:allow-now-p t)
|
|
|
:thread t)
|
|
:thread t)
|
|
|
|
|
+ ;; Start getUpdates thread
|
|
|
(bordeaux-threads:make-thread
|
|
(bordeaux-threads:make-thread
|
|
|
(lambda ()
|
|
(lambda ()
|
|
|
(in-package #:chatikbot)
|
|
(in-package #:chatikbot)
|