|
@@ -4,7 +4,9 @@
|
|
|
(:export :*admins*
|
|
(:export :*admins*
|
|
|
:*bot-name*
|
|
:*bot-name*
|
|
|
:*hooks*
|
|
:*hooks*
|
|
|
|
|
+ :+hour+
|
|
|
:+day+
|
|
:+day+
|
|
|
|
|
+ :*chat-default-timezone*
|
|
|
:run-hooks
|
|
:run-hooks
|
|
|
:add-hook
|
|
:add-hook
|
|
|
:remove-hook
|
|
:remove-hook
|
|
@@ -45,6 +47,9 @@
|
|
|
:format-size
|
|
:format-size
|
|
|
:format-interval
|
|
:format-interval
|
|
|
:symbol-append
|
|
:symbol-append
|
|
|
|
|
+ :get-chat-location
|
|
|
|
|
+ :get-chat-timezone
|
|
|
|
|
+ :same-gmt-time-in-chat
|
|
|
:message-id
|
|
:message-id
|
|
|
:from-id
|
|
:from-id
|
|
|
:chat-id
|
|
:chat-id
|
|
@@ -74,6 +79,7 @@
|
|
|
(defvar *admins* nil "Admins chat-ids")
|
|
(defvar *admins* nil "Admins chat-ids")
|
|
|
(defvar *bot-name* nil "bot name to properly handle text input")
|
|
(defvar *bot-name* nil "bot name to properly handle text input")
|
|
|
(defvar *hooks* (make-hash-table) "Hooks storage")
|
|
(defvar *hooks* (make-hash-table) "Hooks storage")
|
|
|
|
|
+(defparameter +hour+ (* 60 60) "Seconds in an hour")
|
|
|
(defparameter +day+ (* 24 60 60) "Seconds in day")
|
|
(defparameter +day+ (* 24 60 60) "Seconds in day")
|
|
|
|
|
|
|
|
(defun run-hooks (event &rest arguments)
|
|
(defun run-hooks (event &rest arguments)
|
|
@@ -113,6 +119,7 @@
|
|
|
(defmacro defsetting (var &optional val doc)
|
|
(defmacro defsetting (var &optional val doc)
|
|
|
`(progn (defvar ,var ,val ,doc)
|
|
`(progn (defvar ,var ,val ,doc)
|
|
|
(push ',var *settings*)))
|
|
(push ',var *settings*)))
|
|
|
|
|
+(defsetting *chat-default-timezone* -3 "Default timezone for chat users. GMT+3")
|
|
|
|
|
|
|
|
(defvar *backoff-start* 1 "Initial back-off")
|
|
(defvar *backoff-start* 1 "Initial back-off")
|
|
|
(defvar *backoff-max* 64 "Maximum back-off delay")
|
|
(defvar *backoff-max* 64 "Maximum back-off delay")
|
|
@@ -387,6 +394,23 @@ is replaced with replacement."
|
|
|
(intern (apply #'concatenate 'string
|
|
(intern (apply #'concatenate 'string
|
|
|
(mapcar #'symbol-name symbols))))
|
|
(mapcar #'symbol-name symbols))))
|
|
|
|
|
|
|
|
|
|
+(defun get-chat-location (chat-id)
|
|
|
|
|
+ (let* ((forecast-package (find-package :chatikbot.plugins.forecast))
|
|
|
|
|
+ (chat-locations-sym (when forecast-package
|
|
|
|
|
+ (intern "*CHAT-LOCATIONS*" forecast-package)))
|
|
|
|
|
+ (chat-locations (when (and chat-locations-sym (boundp chat-locations-sym))
|
|
|
|
|
+ (symbol-value chat-locations-sym))))
|
|
|
|
|
+ (when chat-locations (aget chat-id chat-locations))))
|
|
|
|
|
+
|
|
|
|
|
+(defun get-chat-timezone (chat-id)
|
|
|
|
|
+ (or (let ((chat-loc (get-chat-location chat-id)))
|
|
|
|
|
+ (when chat-loc
|
|
|
|
|
+ (round (- 7.5 (aget "latitude" chat-loc)) 15))) ;; Nautical time
|
|
|
|
|
+ *chat-default-timezone*))
|
|
|
|
|
+
|
|
|
|
|
+(defun same-gmt-time-in-chat (ut chat-id)
|
|
|
|
|
+ (let ((tz (get-chat-timezone chat-id)))
|
|
|
|
|
+ (+ ut (* tz +hour+))))
|
|
|
|
|
|
|
|
;; Fix bug in local-time (following symlinks in /usr/share/zoneinfo/
|
|
;; Fix bug in local-time (following symlinks in /usr/share/zoneinfo/
|
|
|
;; leads to bad cutoff)
|
|
;; leads to bad cutoff)
|