Skip to content

Commit

Permalink
delete message after some time
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Nov 22, 2023
1 parent 1c30b61 commit c43fc2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/functions/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ pub async fn trigger(bot: &Bot, msg: &Message) -> ResponseResult<()> {
.send_message(msg.chat.id, TEXT)
.parse_mode(ParseMode::Html);

if msg.thread_id.is_some() {
let message: Message = if msg.thread_id.is_some() {
message
.message_thread_id(msg.thread_id.unwrap())
.send()
.await?;
.await?
} else {
message.send().await?;
}
message.send().await?
};

let thread_bot = bot.clone();
tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(60 * 5)).await;
match thread_bot.delete_message(message.chat.id, message.id).await {
Ok(_) => {}
Err(_) => {}
};
});

Ok(())
}
17 changes: 16 additions & 1 deletion src/hooks/is_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ pub fn keyboard() -> InlineKeyboardMarkup {
}

pub async fn is_private(bot: &Bot, msg: &Message) -> ResponseResult<()> {
bot.send_message(msg.chat.id, TEXT)
match bot.delete_message(msg.chat.id, msg.id).await {
Ok(_) => {}
Err(_) => {}
};

let message = bot
.send_message(msg.chat.id, TEXT)
.parse_mode(ParseMode::Html)
.reply_markup(keyboard())
.await?;

let thread_bot = bot.clone();
tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
match thread_bot.delete_message(message.chat.id, message.id).await {
Ok(_) => {}
Err(_) => {}
};
});

Ok(())
}

0 comments on commit c43fc2f

Please sign in to comment.