Small changes and things moved around

ご主人様
not manx 4 years ago
parent fd33fdd85b
commit 2eca0ddfb2
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -1,5 +1,7 @@
(in-package #:lolicore) (in-package #:lolicore)
(defparameter *boorus* '())
(defmacro make-ratings ((safe questionable explicit)) (defmacro make-ratings ((safe questionable explicit))
`(quote (("s" . ,safe) `(quote (("s" . ,safe)
("q" . ,questionable) ("q" . ,questionable)
@ -12,7 +14,7 @@
(defclass booru () (defclass booru ()
((name ((name
:initarg :name :initarg :name
:reader :name) :reader name)
(url (url
:initarg :url :initarg :url
:reader url) :reader url)
@ -23,6 +25,7 @@
:initarg :rating-posts :initarg :rating-posts
:reader rating-posts)) :reader rating-posts))
(:default-initargs (:default-initargs
:name (error "Need a name")
:url (error "Need a URL") :url (error "Need a URL")
:rating-table '(("s" . "s") :rating-table '(("s" . "s")
("q" . "q") ("q" . "q")
@ -30,7 +33,19 @@
:rating-posts (error "Need number of posts per rating"))) :rating-posts (error "Need number of posts per rating")))
(defmethod get-rating ((obj booru) rating) (defmethod get-rating ((obj booru) rating)
"Gets the `rating' from `rating-table' of `booru'"
(cdr (assoc rating (rating-table obj) :test 'string=))) (cdr (assoc rating (rating-table obj) :test 'string=)))
(defmethod get-posts ((obj booru) rating) (defmethod get-posts ((obj booru) rating)
"Gets the max posts for `rating' for `booru'"
(cdr (assoc rating (rating-posts obj) :test 'string=))) (cdr (assoc rating (rating-posts obj) :test 'string=)))
;; Built-in boorus
(add-booru :name 'lolibooru
:url "https://lolibooru.moe/post/index.json?tags=rating:~a+-3dcg+-rape&limit=1&page=~a"
:rating-posts (make-ratings (74000 53000 92000)))
(add-booru :name 'gelbooru
:url "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=rating:~a&limit=1&pid=~a"
:rating-posts (make-ratings (20000 20000 20000))
:rating-table ratings-full-words)

@ -1,27 +1,22 @@
(in-package #:lolicore) (in-package #:lolicore)
(defparameter *boorus* '())
(add-booru :name 'lolibooru
:url "https://lolibooru.moe/post/index.json?tags=rating:~a+-3dcg+-rape&limit=1&page=~a"
:rating-posts (make-ratings (74000 53000 92000)))
(add-booru :name 'gelbooru
:url "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=rating:~a&limit=1&pid=~a"
:rating-posts (make-ratings (20000 20000 20000))
:rating-table ratings-full-words)
(defun loli-link (rating ) (defun loli-link (rating )
"Generate a valid link to a loli image from a random booru"
(let ((booru (cl-rng:within *boorus*))) (let ((booru (cl-rng:within *boorus*)))
(format nil (url booru) (format nil (url booru)
(get-rating booru rating) (get-rating booru rating)
(cl-rng:crandom :limit (get-posts booru rating) :transform 'floor)))) (cl-rng:crandom :limit (get-posts booru rating) :transform 'floor))))
(defun loli-json (rating) (defun loli-json (rating)
"Get a link using `loli-link', download it and return parsed JSON"
(car (jsown:parse (dex:get (loli-link rating))))) (car (jsown:parse (dex:get (loli-link rating)))))
(defun loli-data (json &key tags file-url (defun loli-data (json &key tags file-url
&aux (lst '())) &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 (when tags
(push (add-data :tags "tags" json) lst)) (push (add-data :tags "tags" json) lst))
(when file-url (when file-url
@ -39,9 +34,3 @@
(declare (type string url)) (declare (type string url))
(str "data:image/jpeg;base64," (qbase64:encode-bytes (dex:get url)))) (str "data:image/jpeg;base64," (qbase64:encode-bytes (dex:get url))))
(export '(loli-link
based-loli
loli-data
loli-json
loli-get
*boorus*))

@ -1,3 +1,9 @@
(defpackage #:lolicore (defpackage #:lolicore
(:nicknames #:rori) (:nicknames #:rori)
(:use #:cl)) (:use #:cl)
(:export #:loli-link
#:based-loli
#:loli-data
#:loli-json
#:loli-get
#:*boorus*))

@ -9,3 +9,14 @@
(defmacro add-booru (&rest args) (defmacro add-booru (&rest args)
`(push (make-instance 'booru ,@args) *boorus*)) `(push (make-instance 'booru ,@args) *boorus*))
(defun list-boorus ()
"List all of the exported boorus"
(loop for booru in *boorus* collect (name booru)))
(defun get-booru (name)
"Get a specific `booru' from `*boorus*' by name"
(loop for booru in *boorus*
do (when (eql name (:name booru))
(return booru))
finally (error "No such booru")))

Loading…
Cancel
Save