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.
lolicore/lolicore.lisp

37 lines
1.1 KiB

(in-package #:lolicore)
(defun loli-link (rating)
"Generate a valid link to a loli image from a random booru"
(let ((booru (cl-rng:within *boorus*)))
(format nil (url booru)
(get-rating booru rating)
(cl-rng:crandom :limit (get-posts booru rating) :transform 'floor))))
(defun loli-json (rating)
"Get a link using `loli-link', download it and return parsed JSON"
(car (jsown:parse (dex:get (loli-link rating)))))
(defun loli-data (json &key tags file-url
&aux (lst '()))
"Takes input `json' from `loli-json' and a set of keys to return
data from
Passing `:tags' will return the images tags, and so fourth."
(when tags
(push (add-data :tags "tags" json) lst))
(when file-url
(push (add-data :file-url "file_url" json) lst))
lst)
(defun loli-get (rating)
"Identical to calling `loli-data' with all keys"
(loli-data (loli-json rating)
:tags t
:file-url t))
(defun based-loli (url)
"I got told off for trying to inline this."
(declare (type string url))
(str "data:image/jpeg;base64," (qbase64:encode-bytes (dex:get url))))