Skip to content

Commit

Permalink
feat(bot): add the login in start args
Browse files Browse the repository at this point in the history
  • Loading branch information
i007c committed Apr 21, 2024
1 parent 452c80c commit 4e3d8ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 25 additions & 12 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use teloxide::dispatching::dialogue::{ErasedStorage, SqliteStorage, Storage};
use teloxide::dispatching::{HandlerExt, UpdateFilterExt};
use teloxide::payloads::SendMessageSetters;
use teloxide::prelude::*;
use tools::StartArg;
// use teloxide::types::ParseMode::MarkdownV2;
use teloxide::types::{
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, KeyboardMarkup,
Expand Down Expand Up @@ -79,9 +80,32 @@ async fn main() -> anyhow::Result<()> {
async fn handle_commands(
bot: Bot, chit: ChitChat, pool: &SqlitePool, msg: Message, cmd: Command,
) -> HR {
let login_keyboard =
InlineKeyboardMarkup::new([[InlineKeyboardButton::login(
"🪪 Login",
LoginUrl {
url: Url::parse(
"https://thora.dozar.bid/api/auth/login-telegram/",
)?,
forward_text: Some("some forward text".to_string()),
bot_username: None,
request_write_access: Some(true),
},
)]]);

match cmd {
Command::Start(arg) => {
let arg = tools::parse_start_args(&arg);
match arg {
StartArg::Login => {
bot.send_message(msg.chat.id, "ورود به سایت")
.reply_markup(login_keyboard)
.await?;

return Ok(());
}
_ => {}
}

bot.send_message(msg.chat.id, KeyData::Rent).await?;

Expand Down Expand Up @@ -126,19 +150,8 @@ async fn handle_commands(
.await?;
}
Command::Login => {
let keyboard = [[InlineKeyboardButton::login(
"🪪 Login",
LoginUrl {
url: Url::parse(
"https://thora.dozar.bid/api/auth/login-telegram/",
)?,
forward_text: Some("some forward text".to_string()),
bot_username: None,
request_write_access: Some(true),
},
)]];
bot.send_message(msg.chat.id, "Login to the site and buy")
.reply_markup(InlineKeyboardMarkup::new(keyboard))
.reply_markup(login_keyboard)
.await?;
}
}
Expand Down
2 changes: 2 additions & 0 deletions bot/src/tools.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[derive(Debug)]
pub enum StartArg {
Invite { id: i64 },
Login,
None,
}

Expand All @@ -13,6 +14,7 @@ pub fn parse_start_args(arg: &str) -> StartArg {
};

match key {
"login" => StartArg::Login,
"invite" => {
if let Some(id) = value.next() {
if let Ok(id) = id.parse::<i64>() {
Expand Down

0 comments on commit 4e3d8ac

Please sign in to comment.