Newer
Older
mod xbasic;
use crate::handlers::joke::*;
use crate::handlers::react::*;
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
40
41
42
43
44
45
46
47
48
49
50
use crate::handlers::xbasic::*;
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::model::prelude::Ready;
use serenity::prelude::*;
#[async_trait]
pub(crate) trait LineHandler: Send + Sync {
async fn message(&self, ctx: &Context, msg: &Message) {
for line in msg.content.split('\n') {
self.line(ctx, msg, line).await
}
}
async fn line(&self, _ctx: &Context, _msg: &Message, _line: &str) {}
}
pub(crate) struct Dispatcher {
handlers: Vec<Box<dyn LineHandler>>,
}
#[async_trait]
impl EventHandler for Dispatcher {
async fn message(&self, ctx: Context, msg: Message) {
for h in &self.handlers {
h.message(&ctx, &msg).await;
}
}
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected", ready.user.name);
}
}
impl Default for Dispatcher {
fn default() -> Self {
Self {
handlers: vec![
Box::new(XbasicHandler::default()),
Box::new(JokeHandler::default()),
Box::new(ReactHandler::default()),