Initial commit.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2023-02-20 01:20:41 +04:00
parent 9a04acd753
commit faae5e4898
39 changed files with 3420 additions and 2 deletions

View File

@ -0,0 +1,31 @@
use async_trait::async_trait;
use grammers_client::{Client, Update};
use rand::seq::IteratorRandom;
use crate::bot::handlers::base::Handler;
#[derive(Clone)]
pub struct Greeter;
#[async_trait]
impl Handler for Greeter {
async fn react(&self, client: &Client, update: &Update) -> anyhow::Result<()> {
let Update::NewMessage(message) = update else {return Ok(())};
// Check if chat has less than 100 participants.
let participants = client.iter_participants(message.chat()).total().await?;
if participants >= 100 {
return Ok(());
}
let reply_text = ["Привет!", "Добрый день!", "Здравствуйте.", "Приетствую"]
.into_iter()
.choose(&mut rand::thread_rng());
if let Some(text) = reply_text {
message.reply(text).await?;
}
Ok(())
}
}