Added midlewares.

This commit is contained in:
2023-02-24 09:27:32 +00:00
parent 65fb93510f
commit 27906a1684
10 changed files with 106 additions and 12 deletions

View File

@ -20,17 +20,11 @@ pub struct Greeter;
#[async_trait]
impl Handler for Greeter {
async fn react(&self, client: &Client, update: &Update) -> anyhow::Result<()> {
async fn react(&self, _: &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(());
}
// Choose random greeting from the list of greetings.
let reply_text = GREETINGS.iter().choose(&mut rand::thread_rng()).copied();
let reply_text = GREETINGS.iter().choose(&mut rand::rngs::OsRng).copied();
if let Some(text) = reply_text {
message.reply(text).await?;