Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/bot/command_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/broadcasting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 22 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ struct Args {

fn parse_redis_url(input: &str) -> Result<ConnectionInfo, String> {
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<String, String> {
Expand Down Expand Up @@ -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,
));
Expand Down Expand Up @@ -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)
}
}
}
Loading