safe-vk 1.2.0

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"(?si).*{}", regex::escape(command)),
        Filter::Sensitive => format!(
            r"(?si)[^\w\s]*({}?{})",
            regex::escape(&command[..1]),
            regex::escape(&command[1..])
        ),
    };

    Regex::new(&pattern).unwrap().is_match(message)
}