Function tbot::compositors::filter

source ·
pub fn filter<C, P, PF, H, HF>(
    predicate: P,
    handler: H
) -> impl Fn(Arc<C>) -> BoxFuture<'static, ()>where
    C: Context,
    P: Fn(Arc<C>) -> PF + Send + Sync + 'static,
    PF: Future<Output = bool> + Send + 'static,
    H: Fn(Arc<C>) -> HF + Send + Sync + 'static,
    HF: Future<Output = ()> + Send + 'static,
Expand description

Filters updates: executes handler only if predicate returns true.

Example

use tbot::{Bot, contexts::Text, compositors::filter, predicates::chat::is_group};
use std::sync::Arc;

let mut bot = Bot::from_env("BOT_TOKEN").event_loop();
bot.text(filter(is_group, |context: Arc<Text>| async move {
    // Do something assuming we're in a group
}));