summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-11-24 11:04:29 -0600
committerNathan Ringo <nathan@remexre.com>2024-11-24 11:04:29 -0600
commit6704dcb51c9de5c66102600d06ffe637fd2db7c1 (patch)
tree15c9e68f9ee32146bbb007a355f4d911616db784 /src/lib.rs
parentdd0e6e45c35133ec8a3e2886b7b050484b388d03 (diff)
Adds plugin to encourage the quitting of Twitter. Eh, it's a tradition at this point.
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];
+ }
}