comments: add anti-bot measure

This commit is contained in:
2025-07-03 23:52:15 -07:00
4 changed files with 27 additions and 10 deletions

View File

@ -5,6 +5,7 @@
(import bleach [clean]) (import bleach [clean])
(import validators [domain :as domain?]) (import validators [domain :as domain?])
(require hyrule.destructure [setv+]) (require hyrule.destructure [setv+])
(import subprocess [check-output])
(defn create-comment [request] (defn create-comment [request]
(setv now (datetime.now)) (setv now (datetime.now))
@ -20,7 +21,13 @@
(when (not (dir? f"./www/data/comments/{url-comment-dir}")) (when (not (dir? f"./www/data/comments/{url-comment-dir}"))
(mkdir f"./www/data/comments/{url-comment-dir}")) (mkdir f"./www/data/comments/{url-comment-dir}"))
(setv+ {{comment "comment" name "name" site "site"} "body"} request) (setv+ {{comment "comment" name "name" site "site" commit "commit"} "body"} request)
(when (!= (. (check-output "git log -1 --format=%h" :shell True :executable "/bin/bash") (decode) (strip)) commit)
(print (. (check-output "git log -1 --format=%h" :shell True :executable "/bin/bash") (decode) (strip)) commit)
(return (dict
:code 303
:headers {"Location" (. request (get "headers") (get "Referer"))})))
(when (.startswith site "//") (when (.startswith site "//")
(setv site (.replace site "//" ""))) (setv site (.replace site "//" "")))

View File

@ -248,7 +248,7 @@ section.comments {
flex-direction: column; flex-direction: column;
gap: 2ch; gap: 2ch;
> form { div > form {
display: grid; display: grid;
grid-template-rows: 12ch 20px; grid-template-rows: 12ch 20px;
grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
@ -256,7 +256,7 @@ section.comments {
> textarea { > textarea {
resize: none; resize: none;
grid-row: 1; grid-row: 1;
grid-column: 1 / 4; grid-column: 1 / 5;
} }
> #name { > #name {
@ -271,6 +271,10 @@ section.comments {
grid-row: 2 grid-row: 2
} }
> #commit {
grid-row: 2
}
> * { > * {
border-radius: 0; border-radius: 0;
background: var(--alt-bg); background: var(--alt-bg);

View File

@ -2,11 +2,16 @@
(defn comments [route] (defn comments [route]
`(section (:class comments) `(section (:class comments)
(h2 comments) (div
(form (:id comment :method post :action ~f"/comment?route={route}" :autocomplete off) (h2 comments)
(textarea (:id comment :name comment :placeholder comment :required True :maxlength 2048)) (p "as an anti-bot measure, in order for $VIEWER's comment to be stored on the server, $VIEWER" (span (:style "font-weight: bold") " MUST ")
(input (:id name :type text :name name :placeholder username :required True :maxlength 32)) "enter the commit hash of the current deployment found in the bottom right of the page footer. failure to do so will result in the comment being disregarded.")
(input (:id website :type text :name site :placeholder "website (not required)" :maxlength 256))
(input (:id submit :type submit :value post))) (form (:id comment :method post :action ~f"/comment?route={route}" :autocomplete off)
(textarea (:id comment :name comment :placeholder comment :required True :maxlength 2048))
(input (:id name :type text :name name :placeholder username :required True :maxlength 32))
(input (:id website :type text :name site :placeholder "website (not required)" :maxlength 256))
(input (:id commit :type text :name commit :placeholder "commit" :maxlength 8))
(input (:id submit :type submit :value post))))
(~f"$[ls -r ./www/data/comments/{(quote-plus route :safe "")} | xargs -I# cat ./www/data/comments/{(quote-plus route :safe "")}/#]"))) (~f"$[ls -r ./www/data/comments/{(quote-plus route :safe "")} | xargs -I# cat ./www/data/comments/{(quote-plus route :safe "")}/#]")))

View File

@ -18,4 +18,5 @@
(div (:style "flex-direction: row; width: 14ch; gap: 2ch; margin-right: 5px;") (div (:style "flex-direction: row; width: 14ch; gap: 2ch; margin-right: 5px;")
(a (:href "https://stellophiliac.github.io/roboring/0x6e6174/previous") "<-") (a (:href "https://stellophiliac.github.io/roboring/0x6e6174/previous") "<-")
(a (:href "https://stellophiliac.github.io/roboring") "roboring") (a (:href "https://stellophiliac.github.io/roboring") "roboring")
(a (:href "https://stellophiliac.github.io/roboring/0x6e6174/next") "->")))))) (a (:href "https://stellophiliac.github.io/roboring/0x6e6174/next") "->"))))
(span ~(run "git log -1 --format=%h"))))