From d1fd0e4cf47470a36e735d0a730c62b72cce7bd1 Mon Sep 17 00:00:00 2001 From: Johannes Dertmann Date: Sun, 4 May 2025 14:53:44 +0200 Subject: [PATCH 1/3] minor stuff --- src/broadcasting.rs | 2 +- src/database.rs | 2 +- src/main.rs | 26 ++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) 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) + } + } +} From d7d7d70a5de00c3fe142f7ebc1781c7943c1eaa2 Mon Sep 17 00:00:00 2001 From: Johannes Dertmann Date: Mon, 5 May 2025 16:01:15 +0200 Subject: [PATCH 2/3] add version to help message --- src/bot/command_help.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 { From a0916fcc89f3672adb497f5138c39d573f94e465 Mon Sep 17 00:00:00 2001 From: Johannes Dertmann Date: Mon, 5 May 2025 16:01:45 +0200 Subject: [PATCH 3/3] Release version 0.1.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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"