diff --git a/Cargo.lock b/Cargo.lock index f235adb..14b6a4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "allrisbot" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bot-utils", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 733ab98..c1bfb2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ [package] name = "allrisbot" description = "Telegram bot that notifies users about newly published documents in the Allris 4 council information system" -version = "0.1.0" +version = "0.1.1" edition = "2024" repository = "https://github.com/jdertmann/AllrisBot" license = "AGPL-3.0-or-later" diff --git a/src/bot/command_help.rs b/src/bot/command_help.rs index 1023842..a2ae87d 100644 --- a/src/bot/command_help.rs +++ b/src/bot/command_help.rs @@ -96,8 +96,9 @@ fn about_paragraph(owner: Option<&str>) -> impl WriteToMessage { write!( msg, - "Der Quellcode dieses Bots ist öffentlich zugänglich: {}", + "Der Quellcode dieses Bots ist öffentlich zugänglich: {} (Version {})", env!("CARGO_PKG_REPOSITORY"), + env!("CARGO_PKG_VERSION") )?; if let Some(owner) = owner { diff --git a/src/broadcasting.rs b/src/broadcasting.rs index bd0ce53..2092675 100644 --- a/src/broadcasting.rs +++ b/src/broadcasting.rs @@ -49,7 +49,7 @@ pub struct RedisBackend { impl RedisBackend { pub fn new(bot: crate::Bot, db: redis::Client) -> Self { - let db = DatabaseConnection::new(db, None).shared(); + let db = DatabaseConnection::new(db, None).into_shared(); let cache = LruCache::new(Lru::new(30)); Self { bot, db, cache } diff --git a/src/database.rs b/src/database.rs index fe4cd51..a99d309 100644 --- a/src/database.rs +++ b/src/database.rs @@ -145,7 +145,7 @@ impl DatabaseConnection { } } - pub fn shared(self) -> SharedDatabaseConnection { + pub fn into_shared(self) -> SharedDatabaseConnection { SharedDatabaseConnection { client: self.client.clone(), timeout: self.timeout, diff --git a/src/main.rs b/src/main.rs index a422256..0bc1bad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,12 +89,11 @@ struct Args { fn parse_redis_url(input: &str) -> Result { let url = Url::parse(input).map_err(|e| e.to_string())?; - let info = url.into_connection_info().map_err( + url.into_connection_info().map_err( // the `redis` crate implements no other way to get to a human-friendly error description #[allow(deprecated)] |e| e.description().to_string(), - )?; - Ok(info) + ) } fn parse_owner_username(mut input: &str) -> Result { @@ -146,7 +145,7 @@ async fn main() -> ExitCode { let handle = tokio::spawn(bot::run( bot.clone(), - DatabaseConnection::new(db_client.clone(), Some(Duration::from_secs(6))).shared(), + DatabaseConnection::new(db_client.clone(), Some(Duration::from_secs(6))).into_shared(), args.owner, rx, )); @@ -198,3 +197,22 @@ async fn main() -> ExitCode { ExitCode::SUCCESS } + +#[cfg(test)] +mod tests { + use crate::parse_owner_username; + + #[test] + fn test_parse_username() { + let test_cases = [ + ("@abcD123", Some("abcD123")), + ("dsgz_sfdnj", Some("dsgz_sfdnj")), + ("@@wrong", None), + ("abc!", None), + ]; + + for (input, expected) in test_cases { + assert_eq!(parse_owner_username(input).ok().as_deref(), expected) + } + } +}