use super::{Handler, Matcher, PreMatcher, Rule};
use std::sync::Arc;
use tokio::sync::RwLock;
impl<E> Matcher<E>
where
E: Clone,
{
pub fn build(&self, bot: crate::bot::Bot) -> Matcher<E> {
let mut m = self.clone();
if let None = &m.bot {
m.bot = Some(bot);
}
m
}
pub fn set_action_sender(&mut self, action_sender: super::matchers::ActionSender) {
self.action_sender = Some(action_sender);
}
pub fn set_priority(&mut self, priority: i8) -> Matcher<E> {
self.priority = priority;
self.clone()
}
pub fn add_pre_matcher(&mut self, pre_matcher: Arc<PreMatcher<E>>) -> Matcher<E> {
self.pre_matchers.push(pre_matcher);
self.clone()
}
pub fn add_rule(&mut self, rule: Rule<E>) -> Matcher<E> {
self.rules.push(rule);
self.clone()
}
pub fn set_block(&mut self, block: bool) -> Matcher<E> {
self.block = block;
self.clone()
}
pub fn get_handler(&self) -> &Arc<RwLock<dyn Handler<E> + Sync + Send>> {
&self.handler
}
pub fn set_handler(
&mut self,
handler: Arc<RwLock<dyn Handler<E> + Sync + Send>>,
) -> Matcher<E> {
self.handler = handler;
self.clone()
}
pub fn set_disable(&mut self, disable: bool) -> Matcher<E> {
self.disable = disable;
self.clone()
}
#[doc(hidden)]
pub fn set_event(&mut self, event: &E) -> Matcher<E> {
self.event = Some(event.clone());
self.clone()
}
pub fn is_block(&self) -> bool {
self.block
}
pub fn is_temp(&self) -> bool {
self.temp
}
pub fn set_temp(&mut self, temp: bool) -> Matcher<E> {
self.temp = temp;
self.clone()
}
pub fn set_timeout(&mut self, timeout: i64) -> Matcher<E> {
self.timeout = Some(timeout);
self.clone()
}
}