|
|
@@ -67,6 +67,7 @@
|
|
|
(:hourly (handle-cmd-weather chat-id id '("hourly")))
|
|
|
(:daily (handle-cmd-weather chat-id id '("daily")))
|
|
|
(:rates (handle-cmd-rates chat-id id args))
|
|
|
+ (:charts (handle-cmd-charts chat-id id args))
|
|
|
(:postcheckins (handle-cmd-post-checkins chat-id id args))
|
|
|
(:friends (handle-cmd-fsq-friends chat-id id args))
|
|
|
(:checkins (handle-cmd-checkins chat-id id args))
|
|
|
@@ -170,11 +171,31 @@
|
|
|
(telegram-send-message chat-id "Ошибочка вышла"))))
|
|
|
|
|
|
;; Finance
|
|
|
+(defvar *per-minute-rates* (make-circular (make-list 1440))
|
|
|
+ "Circular list for 24h per minute rates")
|
|
|
+
|
|
|
+(defun process-rates ()
|
|
|
+ (handler-case
|
|
|
+ (push-circular (cons (local-time:timestamp-to-unix (local-time:now))
|
|
|
+ (get-rates))
|
|
|
+ *per-minute-rates*)
|
|
|
+ (error (e) (log:error e))))
|
|
|
+
|
|
|
(defun handle-cmd-rates (chat-id message-id args)
|
|
|
(log:info "handle-cmd-rates" chat-id message-id args)
|
|
|
- (let ((rates (get-rates)))
|
|
|
+ (let ((rates (rest (peek-circular *per-minute-rates*))))
|
|
|
(telegram-send-message chat-id
|
|
|
- (format nil "Зеленый ~A, гейро ~A, британец ~A" (cdar rates) (cdadr rates) (cdaddr rates)))))
|
|
|
+ (format nil "Зеленый ~A, гейро ~A, британец ~A"
|
|
|
+ (cdar rates) (cdadr rates) (cdaddr rates)))))
|
|
|
+
|
|
|
+(defun handle-cmd-charts (chat-id message-id args)
|
|
|
+ (log:info "handle-cmd-charts" chat-id message-id args)
|
|
|
+ (telegram-send-chat-action chat-id "upload_photo")
|
|
|
+ (let ((chart (make-chart *per-minute-rates*))
|
|
|
+ (rates (rest (peek-circular *per-minute-rates*))))
|
|
|
+ (telegram-send-photo chat-id chart
|
|
|
+ :caption (format nil "Зеленый ~A, гейро ~A, британец ~A"
|
|
|
+ (cdar rates) (cdadr rates) (cdaddr rates)))))
|
|
|
|
|
|
;; Weather
|
|
|
(defun handle-cmd-weather (chat-id message-id args)
|
|
|
@@ -290,6 +311,7 @@
|
|
|
(telegram-send-message chat-id (format nil "~{~A~^~%~}" texts))))
|
|
|
(error (e) (log:error e))))
|
|
|
|
|
|
+
|
|
|
(defun save-settings()
|
|
|
(with-open-file (s (merge-pathnames "settings.lisp"
|
|
|
(asdf:component-pathname
|
|
|
@@ -333,6 +355,12 @@
|
|
|
(clon:make-typed-cron-schedule :minute '* :hour '*)
|
|
|
:allow-now-p t)
|
|
|
:thread t)
|
|
|
+ (clon:schedule-function
|
|
|
+ (lambda () (process-rates))
|
|
|
+ (clon:make-scheduler
|
|
|
+ (clon:make-typed-cron-schedule :minute '* :hour '*)
|
|
|
+ :allow-now-p t)
|
|
|
+ :thread t)
|
|
|
;; Start getUpdates thread
|
|
|
(bordeaux-threads:make-thread
|
|
|
(lambda ()
|