You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.3 KiB

(in-package #:lolisp)
(defmacro telegram-api-string (api-part)
`(str "https://api.telegram.org/bot" (config-item :loligram-url) ,api-part))
(defvar *send-loli* (telegram-api-string "/sendPhoto?chat_id=~a&photo=~a"))
(defvar *no-loli* (telegram-api-string "/sendMessage?chat_id=~a&text=Go away"))
(defvar *chats* (make-hash-table))
(defun configure-loligram ()
(setf *send-loli* (telegram-api-string "/sendPhoto?chat_id=~a&photo=~a"))
(setf *no-loli* (telegram-api-string "/sendMessage?chat_id=~a&text=Go away"))
(setf *chats* (make-hash-table))
(loop for chat in (config-item :loligram-chats)
do (setf (gethash chat *chats*) t)))
(toot:handle (loligram :get (str "/loli/" (config-item :loligram-url))
:acceptor 'lolisp
:content-type toot:@plain)
()
(when (null (tbnl:raw-post-data))
(tbnl:abort-request-handler))
(let* ((json (jsown:parse (babel:octets-to-string (tbnl:raw-post-data))))
(chat-id (json-value json "message" "chat" "id"))
(text (json-value json "message" "text")))
(cond
((not (gethash chat-id *chats*))
(dex:get (format nil *no-loli* chat-id)))
((string= text "/loli")
(dex:get (format nil *send-loli* chat-id (rori:loli-link "s"))))))
"mwee") ;; Return mwee