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.

29 lines
1.3 KiB

(in-package #:lolisp)
(defvar *send-loli* (str "https://api.telegram.org/bot" (config-item :loligram-url) "/sendPhoto?chat_id=~a&photo=~a"))
(defvar *no-loli* (str "https://api.telegram.org/bot" (config-item :loligram-url) "/sendMessage?chat_id=~a&text=Go away"))
(defvar *chats* (make-hash-table))
(defun configure-loligram ()
(setf *send-loli* (str "https://api.telegram.org/bot" (config-item :loligram-url) "/sendPhoto?chat_id=~a&photo=~a"))
(setf *no-loli* (str "https://api.telegram.org/bot" (config-item :loligram-url) "/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)) :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 (jsown:val (jsown:val (jsown:val json "message") "chat") "id"))
(text (jsown:val (jsown:val 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")