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
30
31
32
33
34
35
36
37
38
39
use async_trait::async_trait;
#[cfg(feature = "daemons")]
pub mod daemon;
#[cfg(feature = "commands")]
pub mod command;
use crate::bot::Bot;
use crate::models::{Update, UpdateType};
use crate::state::BotState;
pub struct GenericHandler<T>
where
T: Sync,
{
pub rank: usize,
pub name: &'static str,
pub handler: Box<dyn Handler<T>>,
pub updates: Vec<UpdateType>,
}
#[async_trait]
pub trait Handler<T: Sync> {
async fn handle(&self, bot: &Bot, update: &Update, state: Option<&BotState<T>>) -> Result<(), HandlerError>;
}
#[derive(Debug)]
pub enum HandlerError {
Parse,
Runtime,
}