safe-vk 1.2.2

A simple library to create your own vk bot for conversations
Documentation
use regex::Regex;

/// This filter is responsible how sensitive command will be
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Filter {
    /// Must be exactly same command
    Strict,
    /// Can have some spaces, and can be uppercase, but still must be same command
    Flexible,
    /// Can be triggered without any symbol, and also can be uppercase
    Sensitive,
}

pub fn matchit(message: &str, command: &str, filter: &Filter) -> bool {
    let pattern = match filter {
        Filter::Strict => format!(r"^{}$", regex::escape(command)),
        Filter::Flexible => format!(r"(?i)^\s*[^\w\s]?{}\s*$", regex::escape(command)),
        Filter::Sensitive => format!(
            r"(?i)(?:^|[\W_]){}(?:[\W_]|$)",
            regex::escape(&command.trim_start_matches(|c: char| !c.is_alphanumeric()))
        ),
    };
    Regex::new(&pattern).unwrap().is_match(message)
}