commit
fd33fdd85b
@ -0,0 +1,36 @@
|
|||||||
|
(in-package #:lolicore)
|
||||||
|
|
||||||
|
(defmacro make-ratings ((safe questionable explicit))
|
||||||
|
`(quote (("s" . ,safe)
|
||||||
|
("q" . ,questionable)
|
||||||
|
("e" . ,explicit))))
|
||||||
|
|
||||||
|
(defvar ratings-full-words '(("s" . "safe")
|
||||||
|
("q" . "questionable")
|
||||||
|
("e" . "explicit")))
|
||||||
|
|
||||||
|
(defclass booru ()
|
||||||
|
((name
|
||||||
|
:initarg :name
|
||||||
|
:reader :name)
|
||||||
|
(url
|
||||||
|
:initarg :url
|
||||||
|
:reader url)
|
||||||
|
(rating-table
|
||||||
|
:initarg :rating-table
|
||||||
|
:reader rating-table)
|
||||||
|
(rating-posts
|
||||||
|
:initarg :rating-posts
|
||||||
|
:reader rating-posts))
|
||||||
|
(:default-initargs
|
||||||
|
:url (error "Need a URL")
|
||||||
|
:rating-table '(("s" . "s")
|
||||||
|
("q" . "q")
|
||||||
|
("e" . "e"))
|
||||||
|
:rating-posts (error "Need number of posts per rating")))
|
||||||
|
|
||||||
|
(defmethod get-rating ((obj booru) rating)
|
||||||
|
(cdr (assoc rating (rating-table obj) :test 'string=)))
|
||||||
|
|
||||||
|
(defmethod get-posts ((obj booru) rating)
|
||||||
|
(cdr (assoc rating (rating-posts obj) :test 'string=)))
|
@ -0,0 +1,14 @@
|
|||||||
|
(asdf:defsystem #:lolicore
|
||||||
|
:description ""
|
||||||
|
:author "Manx <boku@plum.moe>"
|
||||||
|
:license "GPLv3"
|
||||||
|
:version "1.0.0"
|
||||||
|
:serial t
|
||||||
|
:depends-on (:qbase64
|
||||||
|
:dexador
|
||||||
|
:cl-rng
|
||||||
|
:jsown)
|
||||||
|
:Components ((:file "package")
|
||||||
|
(:file "utils")
|
||||||
|
(:file "booru")
|
||||||
|
(:file "lolicore")))
|
@ -0,0 +1,47 @@
|
|||||||
|
(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)
|
||||||
|
(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)
|
||||||
|
(car (jsown:parse (dex:get (loli-link rating)))))
|
||||||
|
|
||||||
|
(defun loli-data (json &key tags file-url
|
||||||
|
&aux (lst '()))
|
||||||
|
(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))))
|
||||||
|
|
||||||
|
(export '(loli-link
|
||||||
|
based-loli
|
||||||
|
loli-data
|
||||||
|
loli-json
|
||||||
|
loli-get
|
||||||
|
*boorus*))
|
@ -0,0 +1,3 @@
|
|||||||
|
(defpackage #:lolicore
|
||||||
|
(:nicknames #:rori)
|
||||||
|
(:use #:cl))
|
@ -0,0 +1,11 @@
|
|||||||
|
(in-package #:lolicore)
|
||||||
|
|
||||||
|
(defmacro str (&rest strs)
|
||||||
|
"Concatenate a list of strings `strs' to one string."
|
||||||
|
`(concatenate 'string ,@strs))
|
||||||
|
|
||||||
|
(defun add-data (keyword key json)
|
||||||
|
(cons keyword (jsown:val json key)))
|
||||||
|
|
||||||
|
(defmacro add-booru (&rest args)
|
||||||
|
`(push (make-instance 'booru ,@args) *boorus*))
|
Loading…
Reference in new issue