async fn remove_aliases(
    cx: &TransitionIn<AutoSend<Bot>>,
    text: &str,
    db: Arc<Mutex<RedisConnection>>,
) -> Result<(), teloxide::RequestError> {
    use std::collections::HashSet;
    // HashSet lets us omit repeating removals
    let aliases: HashSet<&str> = text.split_whitespace().collect();
    let mut db = db.lock().await;

    let mut n_removed: i64 = 0;
    let mut fails: Vec<&str> = vec![];

    for &alias in &aliases {
        let res = db.remove_alias(cx.chat_id(), alias).await;
        match res {
            Ok(()) => {
                n_removed += 1;
            }
            Err(_) => {
                fails.push(alias);
            }
        }
    }
    cx.answer(format!(
        "Removed {removed}/{total} (duplicates are omitted)",
        removed = n_removed,
        total = aliases.len()
    ))
    .await?;

    // Display failed aliases if needed
    match i64::try_from(aliases.len()) {
        Ok(n_aliases) => {
            if n_removed < n_aliases {
                let mut fails_str = String::new();
                for fail in fails {
                    fails_str.push_str(fail);
                    fails_str.push(' ');
                }
                cx.answer(format!("Aliases that were not removed: {}", fails_str))
                    .await?;
            }
        }
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!("Failed converting usize to i64: {}", e),
                    cx.chat_id()
                )
            );
        }
    }
    Ok(())
}
/// Remove aliases received in `text` from database.
///
/// Handle the removal, report the result to `cx`.
Remove aliases received in `text` from database.
Handle the removal, report the result to `cx`.
Remove aliases received in ` text ` from database . Handle the removal report the result to ` cx ` .
async fn remove_aliases(
    cx: &TransitionIn<AutoSend<Bot>>,
    text: &str,
    db: Arc<Mutex<RedisConnection>>,
) -> Result<(), teloxide::RequestError> {
    use std::collections::HashSet;
    // HashSet lets us omit repeating removals
    let aliases: HashSet<&str> = text.split_whitespace().collect();
    let mut db = db.lock().await;
    let mut n_removed: i64 = 0;
    let mut fails: Vec<&str> = vec![];
    for &alias in &aliases {
        let res = db.remove_alias(cx.chat_id(), alias).await;
        match res {
            Ok(()) => {
                n_removed += 1;
            }
            Err(_) => {
                fails.push(alias);
            }
        }
    }
    cx.answer(format!(
        "Removed {removed}/{total} (duplicates are omitted)",
        removed = n_removed,
        total = aliases.len()
    ))
    .await?;
    // Display failed aliases if needed
    match i64::try_from(aliases.len()) {
        Ok(n_aliases) => {
            if n_removed < n_aliases {
                let mut fails_str = String::new();
                for fail in fails {
                    fails_str.push_str(fail);
                    fails_str.push(' ');
                }
                cx.answer(format!("Aliases that were not removed: {}", fails_str))
                    .await?;
            }
        }
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!("Failed converting usize to i64: {}", e),
                    cx.chat_id()
                )
            );
        }
    }
    Ok(())
}
async fn remove_aliases ( cx : & TransitionIn < AutoSend < Bot > > , text : & str , db : Arc < Mutex < RedisConnection > > , ) -> Result < ( ) , teloxide :: RequestError > { use std :: collections :: HashSet ; // HashSet lets us omit repeating removals let aliases : HashSet < & str > = text . split_whitespace ( ) . collect ( ) ; let mut db = db . lock ( ) . await ; let mut n_removed : i64 = 0 ; let mut fails : Vec < & str > = vec ! [ ] ; for & alias in & aliases { let res = db . remove_alias ( cx . chat_id ( ) , alias ) . await ; match res { Ok ( ( ) ) => { n_removed += 1 ; } Err ( _ ) => { fails . push ( alias ) ; } } } cx . answer ( format ! ( " " removed n_removed total aliases len ( ) ) ) . await ? ; // Display failed aliases if needed match i64 :: try_from ( aliases . len ( ) ) { Ok ( n_aliases ) => { if n_removed < n_aliases { let mut fails_str = String :: new ( ) ; for fail in fails { fails_str . push_str ( fail ) ; fails_str . push ( ' ' ) ; } cx . answer ( format ! ( " " fails_str ) ) . await ? ; } } Err ( e ) => { log :: error ! ( " " format_log_chat ( format ( " " e ) cx chat_id ( ) ) ) ; } } Ok ( ( ) ) }
Remove aliases received in `text` from database.
Remove aliases received in ` text ` from database .
cx
&TransitionIn<AutoSend<Bot>>
text
&str
db
Arc<Mutex<RedisConnection>>