commit 13424d3939834c58a9040a17e347d2ffd2f775db Author: not manx Date: Sat May 2 15:14:49 2020 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c730c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.lisp +loli.service \ No newline at end of file diff --git a/about.html b/about.html new file mode 100644 index 0000000..bec67ae --- /dev/null +++ b/about.html @@ -0,0 +1,15 @@ + + + + + + + +

plum.moe/loli

+

Gets a random loli from lolibooru, converts it to base64 and displays it in the browser.

+

By default it only searches for images tagged as safe. You can pass rating=q or rating=e if you're feeling lewd.
Passing rating=-e will randomly choose a non-explicit image and so fourth.

+

Tring to query lolibooru via the URL otherwise will not work.

+

Made by Manx

+

+ + diff --git a/config.example.lisp b/config.example.lisp new file mode 100644 index 0000000..9ce889e --- /dev/null +++ b/config.example.lisp @@ -0,0 +1 @@ +(defparameter *host* "localhost") diff --git a/loli.example.service b/loli.example.service new file mode 100644 index 0000000..8da86a8 --- /dev/null +++ b/loli.example.service @@ -0,0 +1,15 @@ +[Unit] +Description=lolis + +[Service] +WorkingDirectory=/path/to/your/lolisp +ExecStart=/bin/env sbcl --non-interactive --load loli.lisp +Restart=always +# restarts 10 seconds after it goes bang +RestartSec=10 +KillSignal=SIGINT +SyslogIdentifier=loli +User=www-data + +[Install] +WantedBy=multi-user.target diff --git a/loli.lisp b/loli.lisp new file mode 100644 index 0000000..43c53d5 --- /dev/null +++ b/loli.lisp @@ -0,0 +1,62 @@ +(asdf:load-system :cl-rng) +(asdf:load-system :manx-utils) +(asdf:load-system :cl-ppcre) +(asdf:load-system :aserve) +(asdf:load-system :dexador) +(asdf:load-system :jsown) +(asdf:load-system :qbase64) + +(load #p"config.lisp") + +(when (null *host*) + (print "Can't have null host") + (exit :code -1)) + +(defun get-loli (rating) + (jsown:val + (car ;; %parse-json returns a list of a list + (jsown:parse + (dex:get + (manx-utils:to-string + "https://lolibooru.moe/post/index.json?tags=rating:" rating "+-3dcg+-rape&limit=1&page=" + (cl-rng:crandom :limit 25000 :transform 'floor))))) + "file_url")) + +(defun main (&rest args) + (net.aserve:start :port 8080 :host *host*) + + (net.aserve:publish + :path "/loli" + :content-type "text/html" + :function 'this-is-bad-code) + + (net.aserve:publish-file + :path "/loli/about" + :file #p"about.html") + + (loop (sleep 10000))) + +(defun loli-rating (req) + (let ((rating (net.aserve:request-query-value "rating" req))) + (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 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 + (:head + ((:meta name "viewport" content "width=device-width, initial-scale=1"))) + ((:body :style "position:relative") + ((:img :style "object-fit: contain; width: 100%; height:100%" + :src (based-loli req))) + ((:a :style "position:absolute;top:8px;right:16px;" href "/loli/about") "about"))))))) + +(main) diff --git a/readme.org b/readme.org new file mode 100644 index 0000000..aac35b6 --- /dev/null +++ b/readme.org @@ -0,0 +1,16 @@ +* lolisp +Grab a random image from lolibooru, convert it to base64 and display +it on a web page. + +This code is terrible because I am too. +** Setup +- Clone the repo +- Move ~loli.example.service~ to ~/etc/systemd/system/~ and rename it + to ~loli.service~ +- Change ~workingdirectory~ in ~loli.service~ to wherever your lolisp + is +- Move ~config.example.lisp~ to ~config.lisp~ and change ~*host*~ to + your domain name +- Run ~systemctl daemon-reload~ +- Start lolisp with ~service loli start~ +- View the page at ~*host*/loli~