remove cmd db test
This commit is contained in:
parent
073800eb61
commit
d0dafee2a6
1 changed files with 3 additions and 36 deletions
|
|
@ -15,6 +15,8 @@ use tracing::{event, Level};
|
||||||
use crate::dl::delete_if_exists;
|
use crate::dl::delete_if_exists;
|
||||||
use crate::dl::download;
|
use crate::dl::download;
|
||||||
|
|
||||||
|
use crate::db;
|
||||||
|
|
||||||
type State = ();
|
type State = ();
|
||||||
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
|
|
||||||
|
|
@ -37,8 +39,6 @@ where
|
||||||
pub async fn bot_main(db: SqlitePool) -> anyhow::Result<()> {
|
pub async fn bot_main(db: SqlitePool) -> anyhow::Result<()> {
|
||||||
event!(Level::INFO, "start");
|
event!(Level::INFO, "start");
|
||||||
|
|
||||||
// db_init
|
|
||||||
|
|
||||||
let bot = Bot::new(env::var("BOT_TOKEN")?);
|
let bot = Bot::new(env::var("BOT_TOKEN")?);
|
||||||
let listener = Polling::builder(bot.clone())
|
let listener = Polling::builder(bot.clone())
|
||||||
.timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT")))
|
.timeout(Duration::from_secs(parse_env("POLLING_TIMEOUT")))
|
||||||
|
|
@ -83,42 +83,9 @@ enum Command {
|
||||||
Download(String),
|
Download(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(sqlx::FromRow, Debug)]
|
|
||||||
struct DbUser {
|
|
||||||
pub id: i64,
|
|
||||||
pub tg_id: i64,
|
|
||||||
pub username: Option<String>,
|
|
||||||
pub first_name: String,
|
|
||||||
pub last_name: Option<String>,
|
|
||||||
pub can_download: i64,
|
|
||||||
pub is_admin: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn cmd_test(bot: Bot, msg: Message, db: SqlitePool) -> HandlerResult {
|
async fn cmd_test(bot: Bot, msg: Message, db: SqlitePool) -> HandlerResult {
|
||||||
bot.send_message(msg.chat.id, "test response").await?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue