Use asdf:defsystem

master
not manx 4 years ago
parent f0441780af
commit 53ca0a271c
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

2
.gitignore vendored

@ -1,4 +1,4 @@
config.lisp config.lisp
loli.service lolisp.service
\#*# \#*#
*~ *~

@ -6,7 +6,7 @@
</head> </head>
<body style="text-align:center;max-width:75em;margin:auto;"> <body style="text-align:center;max-width:75em;margin:auto;">
<h1>plum.moe/loli</h1> <h1>plum.moe/loli</h1>
<p>Gets a random loli from lolibooru, converts it to base64 and displays it in the browser.</p> <p>Gets a random loli from lolibooru.</p>
<p>By default it only searches for images tagged as safe. You can pass <code>rating=q</code> or <code>rating=e</code> if you're feeling lewd.<br /> Passing <code>rating=-e</code> will randomly choose a non-explicit image and so fourth.</p> <p>By default it only searches for images tagged as safe. You can pass <code>rating=q</code> or <code>rating=e</code> if you're feeling lewd.<br /> Passing <code>rating=-e</code> will randomly choose a non-explicit image and so fourth.</p>
<p>Tring to query lolibooru via the URL otherwise will not work.</p> <p>Tring to query lolibooru via the URL otherwise will not work.</p>
<p>Made by <a href="mailto:boku@plum.moe">Manx</a>, source available on <a href="https://github.com/C-xC-c/lolisp">github</a>.</p> <p>Made by <a href="mailto:boku@plum.moe">Manx</a>, source available on <a href="https://github.com/C-xC-c/lolisp">github</a>.</p>

@ -1 +0,0 @@
(defparameter *host* "localhost")

@ -1,62 +1,63 @@
(ql:quickload :aserve) (in-package :lolisp)
(ql:quickload :dexador)
(ql:quickload :jsown) (defvar @html "text/html")
(ql:quickload :qbase64) (defparameter *serb* nil
(ql:quickload :cl-ppcre) "The hunchentoot acceptor (server) that will serve our handlers and
(ql:quickload :cl-rng) files.")
(ql:quickload :manx-utils)
(defmacro str (&rest strs)
(load #p"config.lisp") "Concatenate a list of strings `strs' to one string."
`(concatenate 'string ,@strs))
(when (null *host*)
(print "Host can't be nil") (defmacro config-item (thing &aux (item (gensym)))
(exit :code -1)) "Get `thing' from the alist `config', error if it doesn't exist"
`(let ((,item (assoc ,thing config)))
(defun get-loli (rating) (when (atom ,item)
(jsown:val (error "No such config item"))
(car ;; %parse-json returns a list of a list (cdr ,item)))
(jsown:parse
(dex:get (defun loli-link (rating)
(manx-utils:to-string "Extract file_url from the JSON returned by `dex:get' and replace
"https://lolibooru.moe/post/index.json?tags=rating:" rating "+-3dcg+-rape&limit=1&page=" escaped backslashes (\\\\/) with /.
(cl-rng:crandom :limit 25000 :transform 'floor)))))
"file_url")) Use cl-rng to pick a random page from the lolibooru API"
(cl-ppcre:register-groups-bind (url)
(defun main (&rest args) ("(?:file_url\":\")(.*?)(?:\",)"
(net.aserve:start :port 8080 :host *host*) (dex:get (str "https://lolibooru.moe/post/index.json?tags=rating:"
(or (cl-ppcre:scan-to-strings "-?[sqe]" rating) "s")
(net.aserve:publish "+-3dcg+-rape&limit=1&page="
:path "/loli" (write-to-string (cl-rng:crandom :limit 25000 :transform 'floor)))))
:content-type "text/html" (cl-ppcre:regex-replace-all "\\\\/" url "/")))
:function 'this-is-bad-code)
(defun based-loli (url)
(net.aserve:publish-file (str "data:image/jpeg;base64," (qbase64:encode-bytes (dex:get url))))
:path "/loli/about"
:file #p"about.html") (henh:handle :get (loli :uri "/loli/") @html
(rating)
(loop (sleep 10000))) (cl-who:with-html-output-to-string (x)
(defun loli-rating (rating)
(or (cl-ppcre:scan-to-strings "-?(s|q|e)" rating)
"s"))
(defun based-loli (req)
(manx-utils:to-string
"data:image/jpg;base64,"
(qbase64:encode-bytes
(dex:get (get-loli
(loli-rating (net.aserve:request-query-value "rating" req)))))))
(defun this-is-bad-code (req ent)
(net.aserve:with-http-response (req ent)
(net.aserve:with-http-body (req ent)
(net.html.generator:html
(:html (:html
(:head (:head
((:meta name "viewport" content "width=device-width, initial-scale=1"))) (:meta :charset "utf-8")
((:body :style "position:relative") (:meta :name "viewport" :content "width=device-width, initial-scale=1")
((:img :style "object-fit: contain; width: 100%; height:100%" (:title "lolisp")
:src (based-loli req))) (:style "body{position:relative;}img{object-fit:contain;width:100%;height:100%;}#about{position:absolute;top:8px;right:16px}"))
((:a :style "position:absolute;top:8px;right:16px;" href "/loli/about") "about")))))) (:body
(gc :full t)) ;; Removes downloaded files from memory (:img :src (based-loli (loli-link rating)))
(main) (:a :id "about" :href "/loli/about" "about")))
x))
(henh:host-file "/loli/about" "about.html" @html)
(defun configure ()
(setf *serb* (make-instance 'hunchentoot:easy-acceptor
:port (config-item :port)
:document-root (config-item :document-root))))
(defun start ()
(handler-case (configure)
(error (e) "Configuration failed: ~a" e))
(hunchentoot:start *serb*))
(export '(configure
start
*serb*))

@ -0,0 +1,16 @@
(asdf:defsystem :lolisp
:description "The worst lolibooru scraper you've ever seen"
:author "Manx (boku@plum.moe)"
:license "X11/MIT"
:version "1.0.0"
:serial t
:depends-on (:hunchentoot
:hunchenhelpers
:cl-who
:dexador
:qbase64
:cl-ppcre
:cl-rng)
:Components ((:file "package")
(:file "config")
(:file "loli")))

@ -0,0 +1,2 @@
(defpackage :lolisp
(:use :cl))

@ -8,15 +8,13 @@ This code is terrible because I am too.
I use SBCL. I use SBCL.
Most systems will be downloaded by quicklisp. You wll need to git Most systems will be downloaded by quicklisp. You wll need to git
clone [[https://github.com/C-xC-c/manx-utils][manx-utils]] and [[https://github.com/notflan/cl-rng][cl-rng]] manually and add them to your clone [[https://github.com/C-xC-c/manx-utils][manx-utils]], hunchenhelpers and [[https://github.com/notflan/cl-rng][cl-rng]] manually and add them to your
~local-projects~. ~local-projects~.
*** Hosting *** Hosting
- Clone the repo - Clone the repo
- Move ~loli.example.service~ to ~/etc/systemd/system/loli.service~ - Move ~loli.example.service~ to ~/etc/systemd/system/loli.service~
- Change ~workingdirectory~ in ~loli.service~ to wherever your lolisp - Change ~workingdirectory~ in ~loli.service~ to wherever your lolisp
is is
- Move ~config.example.lisp~ to ~config.lisp~ and change ~*host*~ to
your domain name
- Run ~systemctl daemon-reload~ - Run ~systemctl daemon-reload~
- Start lolisp with ~service loli start~ - Start lolisp with ~service loli start~
- View the page at ~*host*/loli~ - View the page at ~*host*/loli~

Loading…
Cancel
Save