configurable max name/message length (0 for unlimited)

This commit is contained in:
Lewis Wynne 2026-04-09 14:48:48 +01:00
parent c3ceb39b71
commit 81d44da41c
3 changed files with 30 additions and 4 deletions

View file

@ -10,6 +10,8 @@ pub struct Config {
pub telegram_bot_token: String,
pub telegram_chat_id: i64,
pub honeypot: bool,
pub max_name_length: usize,
pub max_message_length: usize,
}
impl Config {
@ -37,6 +39,14 @@ impl Config {
honeypot: env::var("BOOK_HONEYPOT")
.map(|v| v != "false")
.unwrap_or(true),
max_name_length: env::var("BOOK_MAX_NAME_LENGTH")
.unwrap_or_else(|_| "50".into())
.parse()
.map_err(|_| "BOOK_MAX_NAME_LENGTH must be a number")?,
max_message_length: env::var("BOOK_MAX_MESSAGE_LENGTH")
.unwrap_or_else(|_| "1000".into())
.parse()
.map_err(|_| "BOOK_MAX_MESSAGE_LENGTH must be a number")?,
})
}
}