diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 1f5f2b252a1..578299b473f 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -50,13 +50,18 @@ pub(crate) async fn dispatch_model( #[cfg(feature = "framework")] framework: Option>, event_handler: Option, ) { - let handler = match event_handler { - Some(InternalEventHandler::Normal(handler)) => Some(handler), - Some(InternalEventHandler::Raw(raw_handler)) => { - return raw_handler.raw_event(context, event).await; - }, - None => None, + let (handler, raw_handler) = match event_handler { + Some(InternalEventHandler::Normal(handler)) => (Some(handler), None), + Some(InternalEventHandler::Both { + raw, + normal, + }) => (Some(normal), Some(raw)), + Some(InternalEventHandler::Raw(raw_handler)) => (None, Some(raw_handler)), + None => (None, None), }; + if let Some(raw_handler) = raw_handler { + raw_handler.raw_event(context.clone(), &event).await; + } let (full_event, extra_event) = update_cache_with_event( #[cfg(feature = "cache")] diff --git a/src/client/event_handler.rs b/src/client/event_handler.rs index 318893f881b..ef622d391bd 100644 --- a/src/client/event_handler.rs +++ b/src/client/event_handler.rs @@ -513,7 +513,7 @@ event_handler! { #[async_trait] pub trait RawEventHandler: Send + Sync { /// Dispatched when any event occurs - async fn raw_event(&self, _ctx: Context, _ev: Event) {} + async fn raw_event(&self, _ctx: Context, _ev: &Event) {} /// Checks if the `event` should be dispatched (`true`) or ignored (`false`). /// @@ -540,4 +540,5 @@ pub trait RawEventHandler: Send + Sync { pub enum InternalEventHandler { Raw(Arc), Normal(Arc), + Both { raw: Arc, normal: Arc }, } diff --git a/src/client/mod.rs b/src/client/mod.rs index a8c5e7f779a..9d4c5c83afd 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -296,7 +296,10 @@ impl IntoFuture for ClientBuilder { let http = self.http; let event_handler = match (self.event_handler, self.raw_event_handler) { - (Some(_), Some(_)) => panic!("Cannot provide both a normal and raw event handlers"), + (Some(normal), Some(raw)) => Some(InternalEventHandler::Both { + normal, + raw, + }), (Some(h), None) => Some(InternalEventHandler::Normal(h)), (None, Some(h)) => Some(InternalEventHandler::Raw(h)), (None, None) => None, diff --git a/src/gateway/bridge/shard_runner.rs b/src/gateway/bridge/shard_runner.rs index f384a4e1ecb..b5ead15a5f1 100644 --- a/src/gateway/bridge/shard_runner.rs +++ b/src/gateway/bridge/shard_runner.rs @@ -178,6 +178,12 @@ impl ShardRunner { Some(InternalEventHandler::Raw(handler)) => { handler.filter_event(&context, &event) }, + Some(InternalEventHandler::Both { + raw, + normal, + }) => { + raw.filter_event(&context, &event) && normal.filter_event(&context, &event) + }, None => true, };