Added @all handler for groups
Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
pub mod currency_converter;
|
||||
pub mod get_chat_id;
|
||||
pub mod help;
|
||||
pub mod notify_all;
|
||||
pub mod weather_forecaster;
|
||||
|
28
src/bot/handlers/basic/notify_all.rs
Normal file
28
src/bot/handlers/basic/notify_all.rs
Normal 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(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user