|
|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
|
(defvar *telegram-last-update* nil "Telegram last update_id")
|
|
|
+(defvar *admins* nil "Admins chat-ids")
|
|
|
|
|
|
(defun process-updates ()
|
|
|
(handler-case
|
|
|
@@ -41,6 +42,11 @@
|
|
|
(defun random-choice (messages)
|
|
|
(nth (random (length messages)) messages))
|
|
|
|
|
|
+(defun send-response (chat-id response &optional reply-id)
|
|
|
+ (case (car response)
|
|
|
+ (:text (telegram-send-message chat-id (cdr response) :reply-to reply-id))
|
|
|
+ (:sticker (telegram-send-sticker chat-id (cdr response) :reply-to reply-id))))
|
|
|
+
|
|
|
(defun send-dont-understand (chat-id &optional text reply-id)
|
|
|
(if (and text (zerop (random 5)))
|
|
|
;; Reply to "пидор" with "сам пидор" in 20%
|
|
|
@@ -53,10 +59,7 @@
|
|
|
"@chatikbot" ""))
|
|
|
:reply-to reply-id)
|
|
|
;; Reply with predefined responses
|
|
|
- (let ((r (random-choice *responses*)))
|
|
|
- (case (car r)
|
|
|
- (:text (telegram-send-message chat-id (cdr r) :reply-to reply-id))
|
|
|
- (:sticker (telegram-send-sticker chat-id (cdr r) :reply-to reply-id))))))
|
|
|
+ (send-response chat-id (random-choice *responses*))))
|
|
|
|
|
|
(defvar *chat-locations* nil "ALIST of chat->location")
|
|
|
|
|
|
@@ -82,20 +85,44 @@
|
|
|
(:hourly (handle-cmd-weather chat-id id '("hourly")))
|
|
|
(:daily (handle-cmd-weather chat-id id '("daily")))
|
|
|
(:help (handle-cmd-help chat-id id args))
|
|
|
- (otherwise (send-dont-understand chat-id text))))
|
|
|
+ (otherwise (handle-admin-cmd chat-id text cmd args))))
|
|
|
(send-dont-understand chat-id text)))
|
|
|
(when location
|
|
|
(push (cons chat-id location) *chat-locations*)
|
|
|
(telegram-send-message chat-id "Взял на карандаш"))
|
|
|
(when sticker
|
|
|
;; Save incoming stickers in 20% of the cases if it's not already there
|
|
|
- (if (and (zerop (random 5))
|
|
|
+ (if (and (or (find chat-id *admins*)
|
|
|
+ (zerop (random 5)))
|
|
|
(not (find sticker *responses* :key #'cdr :test #'equal)))
|
|
|
(progn
|
|
|
(push (cons :sticker sticker) *responses*)
|
|
|
(telegram-send-message chat-id "Припомним"))
|
|
|
(send-dont-understand chat-id)))))
|
|
|
|
|
|
+(defun %admin-send-responses (chat-id)
|
|
|
+ (telegram-send-message
|
|
|
+ chat-id
|
|
|
+ (format nil "~{~A~^~%~}"
|
|
|
+ (loop for (type . text) in *responses*
|
|
|
+ for i = 1 then (1+ i)
|
|
|
+ collect (format nil "~D. ~A [~A]" i text type)))))
|
|
|
+
|
|
|
+(defun handle-admin-cmd (chat-id text cmd args)
|
|
|
+ (if (find chat-id *admins*)
|
|
|
+ (case cmd
|
|
|
+ (:addresponse
|
|
|
+ (push (cons :text (format nil "~{~A~^ ~}" args)) *responses*)
|
|
|
+ (%admin-send-responses chat-id))
|
|
|
+ (:showresponses
|
|
|
+ (%admin-send-responses chat-id))
|
|
|
+ (:delresponse
|
|
|
+ (setf *responses* (delete (nth (1- (parse-integer (car args))) *responses*) *responses*))
|
|
|
+ (%admin-send-responses chat-id))
|
|
|
+ (:sendresponse (send-response chat-id (nth (1- (parse-integer (car args))) *responses*)))
|
|
|
+ (otherwise (send-dont-understand chat-id text)))
|
|
|
+ (send-dont-understand chat-id text)))
|
|
|
+
|
|
|
(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")
|
|
|
|