fix: special case PMs

This commit is contained in:
Harsh Shandilya 2024-04-29 06:15:01 +05:30
parent 61928ddea7
commit 24f9a5243f
1 changed files with 9 additions and 1 deletions

View File

@ -50,7 +50,15 @@ pub(crate) enum Command {
}
async fn check_authorized(bot: &Bot, message: &Message) -> Result<bool, AsyncError> {
let admins = bot.get_chat_administrators(message.chat.id).await?;
let admins = bot.get_chat_administrators(message.chat.id).await;
let admins = match admins {
Ok(admins) => admins,
Err(e) => {
return Ok(e
.to_string()
.contains("there are no administrators in the private chat"));
}
};
let admins = admins.iter().map(|c| c.user.clone()).collect::<Vec<_>>();
let from = message.from().ok_or("No user found")?;
Ok(from.id == *BOT_OWNER || admins.contains(from))