Added @all handler for groups

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2023-02-26 20:49:03 +04:00
parent 579b1daf02
commit 8b5a588770
4 changed files with 51 additions and 13 deletions

View File

@ -1,4 +1,5 @@
pub mod currency_converter;
pub mod get_chat_id;
pub mod help;
pub mod notify_all;
pub mod weather_forecaster;

View File

@ -0,0 +1,28 @@
use grammers_client::{types::Chat, Client, Update};
use crate::{bot::handlers::Handler, utils::messages::get_message};
#[derive(Clone)]
pub struct NotifyAll;
#[async_trait::async_trait]
impl Handler for NotifyAll {
async fn react(&self, client: &Client, update: &Update) -> anyhow::Result<()> {
let Some(message) = get_message(update) else {return Ok(());};
let Chat::Group(group) = message.chat() else {
return Ok(());
};
let mut participats_iter = client.iter_participants(group);
let mut response = String::new();
while let Some(participant) = participats_iter.next().await? {
if participant.user.is_bot() {
continue;
}
if let Some(username) = participant.user.username() {
response.push_str(format!("@{username} ").as_str());
}
}
message.reply(response).await?;
Ok(())
}
}