1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-22 19:14:20 +00:00
royalnet/src/main.rs

36 lines
938 B
Rust
Raw Normal View History

2024-07-04 01:15:39 +00:00
use anyhow::{Context, Result};
mod database;
mod telegram;
#[tokio::main]
async fn main() -> Result<()> {
let mut tg = telegram::connect();
teloxide::repl(tg, |tg: teloxide::Bot, msg: teloxide::types::Message| async move {
use teloxide::prelude::*;
let mut db = database::connect()
.expect("Failed to connect to the database");
let whoami = {
use diesel::prelude::*;
use database::schema::telegram::dsl::*;
use database::models::*;
telegram
.filter(telegram_id.eq(msg.chat.id.0))
.limit(1)
.select(TelegramUser::as_select())
.load(&mut db)
.expect("Failed to query")
.pop()
.expect("Failed to get object")
};
tg.send_message(msg.chat.id, format!("{whoami:?}")).await?;
Ok(())
}).await;
Ok(())
}