summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3b11a48..d24d386 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,11 @@
mod labwatch;
+mod quit_twitter;
use serenity::{
- all::{ChannelId, Context, EventHandler, Ready},
+ all::{ChannelId, Context, EventHandler, Message, Ready},
async_trait,
};
-use std::{path::PathBuf, sync::Arc};
+use std::{ops::ControlFlow, path::PathBuf, sync::Arc};
pub struct Handler(Arc<HandlerConfig>);
@@ -24,4 +25,20 @@ impl EventHandler for Handler {
async fn ready(&self, ctx: Context, _data_about_bot: Ready) {
tokio::spawn(labwatch::start(self.0.clone(), ctx));
}
+
+ async fn message(&self, ctx: Context, msg: Message) {
+ // Apologies for the macro, but Rust does some control-flow analysis on async functions
+ // that it's much easier to pass when all your calls are direct calls.
+ macro_rules! handlers {
+ ($($handler:expr),* $(,)?) => {
+ $(match $handler(&self.0, &ctx, &msg).await {
+ Ok(ControlFlow::Break(())) => return,
+ Ok(ControlFlow::Continue(())) => (),
+ Err(err) => log::error!("{err:?}"),
+ })*
+ };
+ }
+
+ handlers![quit_twitter::on_message];
+ }
}