From aec876233db6a77fa9e3ff0e0fcbe85d35b63805 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Sun, 4 Dec 2022 10:41:54 +0100 Subject: [PATCH] feat: petnames --- Cargo.lock | 18 +++++++++++------- Cargo.toml | 5 ++++- README.md | 3 ++- src/server.rs | 12 ++++++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d16440..fc4464c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1846,6 +1846,16 @@ dependencies = [ "sha1 0.10.5", ] +[[package]] +name = "petname" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fce4164d60963550beb856b011fdf32b03b0e8bc0c3fce023c7b0ccecddf7950" +dependencies = [ + "itertools", + "rand 0.8.5", +] + [[package]] name = "phf" version = "0.11.1" @@ -2611,12 +2621,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "static-rc" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91d0104a7b28aeda24b30919f83222570111ac0bf1aab23aaffb8f59330e654" - [[package]] name = "stdweb" version = "0.4.20" @@ -3355,13 +3359,13 @@ dependencies = [ "intl-memoizer", "log", "matrix-sdk", + "petname", "rand 0.8.5", "rand_core 0.6.4", "rpassword", "serde", "sha2 0.10.6", "sled", - "static-rc", "tera", "tide", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 3a4fdc7..8bc43e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,16 +18,19 @@ fluent-langneg = "0.13.0" intl-memoizer = "0.5.1" log = "0.4.17" matrix-sdk = { version = "0.6.2", default-features = false, features = ["rustls-tls"] } +petname = { version = "1.1.3", optional = true, default-features = false, features = ["std_rng", "default_dictionary"] } rand = "0.8.5" rand_core = { version = "0.6.4", features = ["std"] } rpassword = "7.2.0" serde = { version = "1.0.148", features = ["derive", "rc"] } sha2 = "0.10.6" sled = "0.34.7" -static-rc = "0.6.1" tera = { version = "1.17.1", features = ["builtins", "date-locale"] } tide = { version = "0.16.0", default-features = false, features = ["h1-server", "cookies", "logger"] } tokio = { version = "1.22.0", features = ["macros", "rt-multi-thread"] } toml_edit = { version = "0.15.0", features = ["easy"] } typed-sled = "0.2.0" unic-langid = { version = "0.9.1", features = ["macros"] } + +[features] +default = ["petname"] diff --git a/README.md b/README.md index 7c119de..9c6ad6a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Rust webserver for comments, that you can easily embed in a website. * Customizable [Tera](https://github.com/Keats/tera) templates * Comment frequency limit per IP * i18n +* Petnames! (anonymous comment authors get a funny random name) ## Use @@ -37,7 +38,7 @@ The account must have joined the room for Webcomment to be able to send messages ## License -CopyLeft 2022 Pascal Engélibert [(why copyleft?)](//txmn.tk/blog/why-copyleft/) +CopyLeft 2022 Pascal Engélibert [(why copyleft?)](https://txmn.tk/blog/why-copyleft/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License. diff --git a/src/server.rs b/src/server.rs index ddb0030..8e19fa6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -322,7 +322,11 @@ async fn handle_post_comments( let comment = Comment { topic_hash, - author: query.comment.author, + author: if query.comment.author.is_empty() { + petname::Petnames::large().generate_one(2, " ") + } else { + query.comment.author + }, email: if query.comment.email.is_empty() { None } else { @@ -395,7 +399,11 @@ async fn handle_post_comments( .unwrap() .as_secs(); - comment.author = query.comment.author; + comment.author = if query.comment.author.is_empty() { + petname::Petnames::large().generate_one(2, " ") + } else { + query.comment.author + }; comment.email = if query.comment.email.is_empty() { None } else {