From d0dafee2a6c7384e25587731fb85d6761ac41db1 Mon Sep 17 00:00:00 2001 From: mykola2312 Date: Sat, 2 Mar 2024 02:18:02 +0200 Subject: [PATCH] remove cmd db test --- src/bot/bot.rs | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/bot/bot.rs b/src/bot/bot.rs index 1735f96..eaafd33 100644 --- a/src/bot/bot.rs +++ b/src/bot/bot.rs @@ -15,6 +15,8 @@ use tracing::{event, Level}; use crate::dl::delete_if_exists; use crate::dl::download; +use crate::db; + type State = (); type MyDialogue = Dialogue>; @@ -37,8 +39,6 @@ where pub async fn bot_main(db: SqlitePool) -> anyhow::Result<()> { event!(Level::INFO, "start"); - // db_init - let bot = Bot::new(env::var("BOT_TOKEN")?); let listener = Polling::builder(bot.clone()) .timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT"))) @@ -83,42 +83,9 @@ enum Command { Download(String), } -#[derive(sqlx::FromRow, Debug)] -struct DbUser { - pub id: i64, - pub tg_id: i64, - pub username: Option, - pub first_name: String, - pub last_name: Option, - pub can_download: i64, - pub is_admin: i64, -} - async fn cmd_test(bot: Bot, msg: Message, db: SqlitePool) -> HandlerResult { bot.send_message(msg.chat.id, "test response").await?; - - let user = msg.from().unwrap(); - - sqlx::query( - "INSERT OR IGNORE INTO user - (tg_id, username, first_name, last_name, can_download, is_admin) - VALUES ($1, $2, $3, $4, $5, $6);", - ) - .bind(user.id.0 as i64) - .bind(&user.username) - .bind(&user.first_name) - .bind(&user.last_name) - .bind(0) - .bind(0) - .execute(&db) - .await - .expect("insert"); - - let db_user = sqlx::query_as!(DbUser, "SELECT * FROM user WHERE id = 1 LIMIT 1;") - .fetch_one(&db) - .await - .expect("fetch_one"); - dbg!(db_user); + Ok(()) }