feat: petnames

This commit is contained in:
Pascal Engélibert 2022-12-04 10:41:54 +01:00
parent 7ee817de46
commit aec876233d
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
4 changed files with 27 additions and 11 deletions

18
Cargo.lock generated
View file

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

View file

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

View file

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

View file

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