initial commit

master
not manx 4 years ago
commit 13424d3939
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

2
.gitignore vendored

@ -0,0 +1,2 @@
config.lisp
loli.service

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body style="text-align:center;max-width:75em;margin:auto;">
<h1>plum.moe/loli</h1>
<p>Gets a random loli from lolibooru, converts it to base64 and displays it in the browser.</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>Made by <a href="mailto:boku@plum.moe">Manx</a></p>
</p>
</body>
</html>

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

@ -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

@ -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)

@ -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~
Loading…
Cancel
Save