Sfoglia il codice sorgente

Repond with stickers, remember it sometimes

Innocenty Enikeew 10 anni fa
parent
commit
0751c5b860
2 ha cambiato i file con 42 aggiunte e 8 eliminazioni
  1. 34 8
      chatikbot.lisp
  2. 8 0
      telegram.lisp

+ 34 - 8
chatikbot.lisp

@@ -23,31 +23,49 @@
       (log:error e))))
 
 (defvar *responses*
-  '("И чё?" "Сам-то понял?" "Ну хуй знает" "Бля..." "В душе не ебу" "Мне похуй"
-    "Eбаный ты нахуй" "Отъебись")
+  '((:text . "И чё?")
+    (:text . "Сам-то понял?")
+    (:text . "Ну хуй знает")
+    (:text . "Бля...")
+    (:text . "В душе не ебу")
+    (:text . "Мне похуй")
+    (:text . "Eбаный ты нахуй")
+    (:text . "Отъебись")
+    (:sticker . "BQADAgADFAADOoERAAGoLKS_Vgs6GgI") ;; ЭЭ епта Чо
+    (:sticker . "BQADAgADGQADOoERAAFDXJisD4fClgI") ;; Ну чё ты несёшь
+    (:sticker . "BQADAgADFwADOoERAAHCw-fBiFjACgI") ;; А у меня собака, я не могу
+    (:sticker . "BQADAgADEgADOoERAAFtU3uF9HvtQgI") ;; Бухнём?
+    (:sticker . "BQADBAADQAEAAnscSQABqWydSKTnASoC")) ;; Trollface
   "Unknown command respond strings")
 
 (defun random-choice (messages)
   (nth (random (length messages)) messages))
 
 (defun send-dont-understand (chat-id &optional text reply-id)
-  (telegram-send-message chat-id
-                         (if (and text (zerop (random 5)))
+  (if (and text (zerop (random 5)))
+      ;; Reply to "пидор" with "сам пидор" in 20%
+      (telegram-send-message chat-id
                              (format nil "Сам ~A"
                                      (replace-all
                                       (if (equal (char text 0) #\/)
                                           (subseq text 1)
                                           text)
                                       "@chatikbot" ""))
-                             (random-choice *responses*))
-                         :reply-to reply-id))
+                             :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))))))
+
 (defvar *chat-locations* nil "ALIST of chat->location")
 
 (defun handle-message (message)
   (let ((id (aget "message_id" message))
         (chat-id (aget "id" (aget "chat" message)))
         (text (aget "text" message))
-        (location (aget "location" message)))
+        (location (aget "location" message))
+        (sticker (aget "file_id" (aget "sticker" message))))
     (log:info "handle-message" message)
     (when text
       (if (equal #\/ (char text 0))
@@ -68,7 +86,15 @@
           (send-dont-understand chat-id text)))
     (when location
       (push (cons chat-id location) *chat-locations*)
-      (telegram-send-message chat-id "Взял на карандаш"))))
+      (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))
+               (not (find sticker *responses* :key #'cdr :test #'equal)))
+          (progn
+            (push (cons :sticker sticker) *responses*)
+            (telegram-send-message chat-id "Припомним"))
+          (send-dont-understand chat-id)))))
 
 (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")

+ 8 - 0
telegram.lisp

@@ -34,3 +34,11 @@
          (cons "disable_web_page_preview" disable-web-preview)
          (cons "reply_to_message_id" reply-to)
          (cons "reply_markup" reply-markup))))
+
+(defun telegram-send-sticker (chat-id sticker &key reply-to reply-markup)
+  (%telegram-api-call
+   "sendSticker"
+   (list (cons "chat_id" chat-id)
+         (cons "sticker" sticker)
+         (cons "reply_to_message_id" reply-to)
+         (cons "reply_markup" reply-markup))))