Updated get_accounts to handle the errors of concatenating the accounts
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
use crate::{errors::NoUserInfo, markups::deletion_markup};
 | 
			
		||||
use entity::prelude::*;
 | 
			
		||||
use futures::TryStreamExt;
 | 
			
		||||
use futures::{future, TryStreamExt};
 | 
			
		||||
use sea_orm::DatabaseConnection;
 | 
			
		||||
use std::fmt::Write;
 | 
			
		||||
use teloxide::{adaptors::Throttle, prelude::*, types::ParseMode};
 | 
			
		||||
@@ -13,7 +13,7 @@ pub async fn get_accounts(
 | 
			
		||||
) -> crate::Result<()> {
 | 
			
		||||
    let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
 | 
			
		||||
    let mut account_names = Account::get_names(user_id, &db, true).await?;
 | 
			
		||||
    let mut result = match account_names.try_next().await? {
 | 
			
		||||
    let mut text = match account_names.try_next().await? {
 | 
			
		||||
        Some(name) => format!("Accounts:\n`{name}`"),
 | 
			
		||||
        None => {
 | 
			
		||||
            bot.send_message(msg.chat.id, "No accounts found")
 | 
			
		||||
@@ -23,12 +23,13 @@ pub async fn get_accounts(
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    account_names
 | 
			
		||||
        .map_err(crate::Error::from)
 | 
			
		||||
        .try_for_each(|name| {
 | 
			
		||||
            write!(result, "\n`{name}`").unwrap();
 | 
			
		||||
            async { Ok(()) }
 | 
			
		||||
            let result = write!(text, "\n`{name}`").map_err(Into::into);
 | 
			
		||||
            future::ready(result)
 | 
			
		||||
        })
 | 
			
		||||
        .await?;
 | 
			
		||||
    bot.send_message(msg.chat.id, result)
 | 
			
		||||
    bot.send_message(msg.chat.id, text)
 | 
			
		||||
        .parse_mode(ParseMode::MarkdownV2)
 | 
			
		||||
        .reply_markup(deletion_markup())
 | 
			
		||||
        .await?;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user