|
@@ -11,30 +11,38 @@
|
|
|
(defvar *telegram-last-update* nil "Telegram last update_id")
|
|
(defvar *telegram-last-update* nil "Telegram last update_id")
|
|
|
|
|
|
|
|
(defun process-updates ()
|
|
(defun process-updates ()
|
|
|
- (loop for update in (telegram-get-updates :offset (and *telegram-last-update*
|
|
|
|
|
- (1+ *telegram-last-update*))
|
|
|
|
|
- :timeout 300)
|
|
|
|
|
- do (handle-message (aget "message" update))
|
|
|
|
|
- do (setf *telegram-last-update*
|
|
|
|
|
- (max (or *telegram-last-update* 0)
|
|
|
|
|
- (aget "update_id" update)))))
|
|
|
|
|
|
|
+ (handler-case
|
|
|
|
|
+ (loop for update in (telegram-get-updates :offset (and *telegram-last-update*
|
|
|
|
|
+ (1+ *telegram-last-update*))
|
|
|
|
|
+ :timeout 300)
|
|
|
|
|
+ do (handle-message (aget "message" update))
|
|
|
|
|
+ do (setf *telegram-last-update*
|
|
|
|
|
+ (max (or *telegram-last-update* 0)
|
|
|
|
|
+ (aget "update_id" update))))
|
|
|
|
|
+ (error (e)
|
|
|
|
|
+ (log:error e))))
|
|
|
|
|
|
|
|
(defvar *responses*
|
|
(defvar *responses*
|
|
|
'("И чё?" "Сам-то понял?" "Ну хуй знает" "Бля..." "В душе не ебу" "Мне похуй")
|
|
'("И чё?" "Сам-то понял?" "Ну хуй знает" "Бля..." "В душе не ебу" "Мне похуй")
|
|
|
"Unknown command respond strings")
|
|
"Unknown command respond strings")
|
|
|
|
|
|
|
|
|
|
+(defun random-choice (messages)
|
|
|
|
|
+ (nth (random (length messages)) messages))
|
|
|
|
|
+
|
|
|
(defun send-dont-understand (chat-id &optional text reply-id)
|
|
(defun send-dont-understand (chat-id &optional text reply-id)
|
|
|
(telegram-send-message chat-id
|
|
(telegram-send-message chat-id
|
|
|
(if (and text (zerop (random 5)))
|
|
(if (and text (zerop (random 5)))
|
|
|
(format nil "Сам ~A"
|
|
(format nil "Сам ~A"
|
|
|
(replace-all text "@chatikbot" ""))
|
|
(replace-all text "@chatikbot" ""))
|
|
|
- (nth (random (length *responses*)) *responses*))
|
|
|
|
|
|
|
+ (random-choice *responses*))
|
|
|
:reply-to reply-id))
|
|
:reply-to reply-id))
|
|
|
|
|
+(defvar *chat-locations* nil "ALIST of chat->location")
|
|
|
|
|
|
|
|
(defun handle-message (message)
|
|
(defun handle-message (message)
|
|
|
(let ((id (aget "message_id" message))
|
|
(let ((id (aget "message_id" message))
|
|
|
(chat-id (aget "id" (aget "chat" message)))
|
|
(chat-id (aget "id" (aget "chat" message)))
|
|
|
- (text (aget "text" message)))
|
|
|
|
|
|
|
+ (text (aget "text" message))
|
|
|
|
|
+ (location (aget "location" message)))
|
|
|
(log:info "handle-message" message)
|
|
(log:info "handle-message" message)
|
|
|
(when text
|
|
(when text
|
|
|
(if (equal #\/ (char text 0))
|
|
(if (equal #\/ (char text 0))
|
|
@@ -47,8 +55,13 @@
|
|
|
(case cmd
|
|
(case cmd
|
|
|
(:postakb (handle-cmd-post-akb chat-id id args))
|
|
(:postakb (handle-cmd-post-akb chat-id id args))
|
|
|
(:akb (handle-cmd-akb chat-id id args))
|
|
(:akb (handle-cmd-akb chat-id id args))
|
|
|
|
|
+ (:weather (handle-cmd-weather chat-id id args))
|
|
|
|
|
+ (:help (handle-cmd-help chat-id id args))
|
|
|
(otherwise (send-dont-understand chat-id text))))
|
|
(otherwise (send-dont-understand chat-id text))))
|
|
|
- (send-dont-understand chat-id text)))))
|
|
|
|
|
|
|
+ (send-dont-understand chat-id text)))
|
|
|
|
|
+ (when location
|
|
|
|
|
+ (push (cons chat-id location) *chat-locations*)
|
|
|
|
|
+ (telegram-send-message chat-id "Взял на карандаш"))))
|
|
|
|
|
|
|
|
(defparameter +akb-vk-domain+ "baneks" "VK.com username of 'B-category anekdotes'")
|
|
(defparameter +akb-vk-domain+ "baneks" "VK.com username of 'B-category anekdotes'")
|
|
|
(defvar *akb-send-to* nil "List of chat-id's to send AKBs to")
|
|
(defvar *akb-send-to* nil "List of chat-id's to send AKBs to")
|
|
@@ -103,8 +116,36 @@
|
|
|
(error (e) (log:error e))))))
|
|
(error (e) (log:error e))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+(defvar *help-responses*
|
|
|
|
|
+ (list "Сам себе помоги, нахуй!" "Вот заняться мне больше нечем" "Нахуй пошел!"
|
|
|
|
|
+ "Хэлп, ай нид самбади, хелп нот джаст энибади."))
|
|
|
|
|
+
|
|
|
|
|
+(defun handle-cmd-help (chat-id message-id args)
|
|
|
|
|
+ (log:info "handle-cmd-help" chat-id message-id args)
|
|
|
|
|
+ (telegram-send-message chat-id (random-choice *help-responses*)))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+(defun handle-cmd-weather (chat-id message-id args)
|
|
|
|
|
+ (log:info "handle-cmd-weather" chat-id message-id args)
|
|
|
|
|
+ (let ((location (cdr (assoc chat-id *chat-locations*))))
|
|
|
|
|
+ (telegram-send-message
|
|
|
|
|
+ chat-id
|
|
|
|
|
+ (if location
|
|
|
|
|
+ (forecast-format (forecast
|
|
|
|
|
+ (aget "latitude" location)
|
|
|
|
|
+ (aget "longitude" location)
|
|
|
|
|
+ :hourly (find "hourly" args :key #'string-downcase :test #'equal)
|
|
|
|
|
+ :daily (find "daily" args :key #'string-downcase :test #'equal)))
|
|
|
|
|
+ "Так а ты чьих будешь?"))))
|
|
|
|
|
+
|
|
|
(defun start ()
|
|
(defun start ()
|
|
|
(mapc #'sb-ext:unschedule-timer (trivial-timers:list-all-timers))
|
|
(mapc #'sb-ext:unschedule-timer (trivial-timers:list-all-timers))
|
|
|
|
|
+ (let ((old-updates (find "process-updates"
|
|
|
|
|
+ (bordeaux-threads:all-threads)
|
|
|
|
|
+ :key #'bordeaux-threads:thread-name
|
|
|
|
|
+ :test #'equal)))
|
|
|
|
|
+ (when old-updates
|
|
|
|
|
+ (bordeaux-threads:destroy-thread old-updates)))
|
|
|
(clon:schedule-function
|
|
(clon:schedule-function
|
|
|
(lambda () (process-latest-akb))
|
|
(lambda () (process-latest-akb))
|
|
|
(clon:make-scheduler
|
|
(clon:make-scheduler
|