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