Skip to content

Commit

Permalink
Remove action from PrefixContext
Browse files Browse the repository at this point in the history
This can be fetched from the command
  • Loading branch information
GnomedDev committed May 26, 2024
1 parent 9ce944f commit 7dd4904
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/dispatch/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,9 @@ pub async fn parse_invocation<'a, U: Send + Sync, E>(
trigger,
})?;

let action = match command.prefix_action {
Some(x) => x,
// This command doesn't have a prefix implementation
None => return Ok(None),
};
if command.prefix_action.is_none() {
return Ok(None);
}

Ok(Some(crate::PrefixContext {
msg,
Expand All @@ -279,7 +277,6 @@ pub async fn parse_invocation<'a, U: Send + Sync, E>(
command,
invocation_data,
trigger,
action,
__non_exhaustive: (),
}))
}
Expand All @@ -289,6 +286,12 @@ pub async fn parse_invocation<'a, U: Send + Sync, E>(
pub async fn run_invocation<U, E>(
ctx: crate::PrefixContext<'_, U, E>,
) -> Result<(), crate::FrameworkError<'_, U, E>> {
// This was already checked in parse_invocation, so this could be an unwrap,
// but this is public so we simply early return if there is no prefix action.
let Some(prefix_action) = ctx.command.prefix_action else {
return Ok(());
};

// Check if we should disregard this invocation if it was triggered by an edit
if ctx.trigger == crate::MessageDispatchTrigger::MessageEdit && !ctx.command.invoke_on_edit {
return Ok(());
Expand Down Expand Up @@ -334,7 +337,7 @@ pub async fn run_invocation<U, E>(
}

// Execute command
(ctx.action)(ctx).await?;
(prefix_action)(ctx).await?;

(ctx.framework.options.post_command)(crate::Context::Prefix(ctx)).await;

Expand Down
5 changes: 0 additions & 5 deletions src/structs/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ pub struct PrefixContext<'a, U, E> {
pub invocation_data: &'a tokio::sync::Mutex<Box<dyn std::any::Any + Send + Sync>>,
/// How this command invocation was triggered
pub trigger: MessageDispatchTrigger,
/// The function that is called to execute the actual command
#[derivative(Debug = "ignore")]
pub action: fn(
PrefixContext<'_, U, E>,
) -> crate::BoxFuture<'_, Result<(), crate::FrameworkError<'_, U, E>>>,

// #[non_exhaustive] forbids struct update syntax for ?? reason
#[doc(hidden)]
Expand Down

0 comments on commit 7dd4904

Please sign in to comment.