Skip to content

Commit

Permalink
Adds Framework::dispatch_automatically
Browse files Browse the repository at this point in the history
Makes client::dispatch::update_cache_with_event public, so it can be called manually by developers
  • Loading branch information
TheCataliasTNT2k committed Apr 28, 2024
1 parent 83ba59e commit a52e915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ pub(crate) async fn dispatch_model(

#[cfg(feature = "framework")]
if let Some(framework) = framework {
if let Some(extra_event) = &extra_event {
framework.dispatch(&context, extra_event).await;
}
if framework.dispatch_automatically() {
if let Some(extra_event) = &extra_event {
framework.dispatch(&context, extra_event).await;
}

framework.dispatch(&context, &full_event).await;
framework.dispatch(&context, &full_event).await;
}
}

if let Some(handler) = handler {
Expand All @@ -89,7 +91,7 @@ pub(crate) async fn dispatch_model(
///
/// Can return `None` if an event is unknown.
#[cfg_attr(not(feature = "cache"), allow(unused_mut))]
fn update_cache_with_event(
pub fn update_cache_with_event(
#[cfg(feature = "cache")] cache: &Cache,
event: Event,
) -> (FullEvent, Option<FullEvent>) {
Expand Down
8 changes: 8 additions & 0 deletions src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub trait Framework: Send + Sync {
}
/// Called on every incoming event.
async fn dispatch(&self, ctx: &Context, event: &FullEvent);
/// If [`Framework::dispatch`] should be called
/// automatically (`true`) or manually by the developer (`false`)
///
/// This allows the developer to make checks and call other functions before commands are
/// handled at all.
fn dispatch_automatically(&self) -> bool {
true
}
}

#[async_trait]
Expand Down

0 comments on commit a52e915

Please sign in to comment.