1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{core::handler::Handler, types::Command};

#[cfg(test)]
mod tests;

/// Allows to run a handler only for a specific command.
#[derive(Clone)]
pub struct CommandPredicate {
    name: String,
}

impl CommandPredicate {
    /// Creates a new `CommandPredicate`.
    ///
    /// # Arguments
    ///
    /// * `name` - A name of a command with leading `/`.
    pub fn new<S: Into<String>>(name: S) -> Self {
        Self { name: name.into() }
    }
}

impl Handler<Command> for CommandPredicate {
    type Output = bool;

    async fn handle(&self, input: Command) -> Self::Output {
        input.get_name() == self.name
    }
}