diff options
author | Keuin <[email protected]> | 2022-03-28 10:17:22 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-03-28 10:17:22 +0800 |
commit | c8f197bf58f198e1cb70d6ea3ae49fc51434b718 (patch) | |
tree | 8007dc2885e39c8a0d26314601bbc2328961b285 /src/bot.rs | |
parent | 52013d1fde52360694f7ef5d8eed43585c8f4337 (diff) |
Replace Arc<DbPool> with DbPool::clone.
Diffstat (limited to 'src/bot.rs')
-rw-r--r-- | src/bot.rs | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -1,6 +1,4 @@ use std::error::Error; -use std::ops::Deref; -use std::sync::Arc; use teloxide::{prelude2::*, types::MessageKind, utils::command::BotCommand}; use tracing::{debug, error, info}; @@ -17,7 +15,7 @@ enum Command { Start, } -async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: Arc<DbPool>) +async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: DbPool) -> Result<(), Box<dyn Error + Send + Sync>> { debug!("Answering telegram message: {:?}", message); match command { @@ -36,7 +34,6 @@ async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: Arc< return Ok(()); // ignore messages from channel } let from = msg.from.unwrap(); - let db = db.deref(); let chat_id = message.chat.id; let user = User { id: from.id as u64, @@ -44,7 +41,7 @@ async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: Arc< token: token::generate(), chat_id: chat_id as u64, }; - if let Err(why) = database::create_user(db, &user).await { + if let Err(why) = database::create_user(&db, &user).await { if format!("{:?}", why).contains("UNIQUE constraint failed") { info!("User exists: {}", user); } else { @@ -54,7 +51,7 @@ async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: Arc< info!("Created user {}.", user); } let message = - match database::get_user_by_chat_id(db, chat_id as u64).await { + match database::get_user_by_chat_id(&db, chat_id as u64).await { Ok(u) => match u { Some(user) => format!("Your token is `{}`. Treat it as a secret!", user.token), _ => String::from("Error: cannot fetch token.") @@ -73,7 +70,7 @@ async fn answer(bot: AutoSend<Bot>, message: Message, command: Command, db: Arc< Ok(()) } -pub async fn repl(bot: Bot, db: Arc<database::DbPool>) { +pub async fn repl(bot: Bot, db: database::DbPool) { teloxide::repls2::commands_repl( bot.auto_send(), move |bot, msg, cmd| |