Skip to content

Commit

Permalink
Do not emit dispatch errors when ignoring bots or webhooks (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis authored Sep 19, 2020
1 parent a3f9186 commit 41698b6
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/framework/standard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ pub enum DispatchError {
NotEnoughArguments { min: u16, given: usize },
/// When there are too many arguments.
TooManyArguments { max: u16, given: usize },
/// When the command was requested by a bot user when they are set to be
/// ignored.
IgnoredBot,
/// When the bot ignores webhooks and a command was issued by one.
WebhookAuthor,
}

type DispatchHook = for<'fut> fn(&'fut Context, &'fut Message, DispatchError) -> BoxFuture<'fut , ()>;
Expand Down Expand Up @@ -229,16 +224,10 @@ impl StandardFramework {
self
}

fn should_fail_common(&self, msg: &Message) -> Option<DispatchError> {
if self.config.ignore_bots && msg.author.bot {
return Some(DispatchError::IgnoredBot);
}

if self.config.ignore_webhooks && msg.webhook_id.is_some() {
return Some(DispatchError::WebhookAuthor);
}

None
/// Whether the message should be ignored because it is from a bot or webhook.
fn should_ignore(&self, msg: &Message) -> bool {
(self.config.ignore_bots && msg.author.bot) ||
(self.config.ignore_webhooks && msg.webhook_id.is_some())
}

async fn should_fail<'a>(
Expand Down Expand Up @@ -616,11 +605,7 @@ impl StandardFramework {
impl Framework for StandardFramework {
#[instrument(skip(self, ctx))]
async fn dispatch(&self, mut ctx: Context, msg: Message) {
if let Some(error) = self.should_fail_common(&msg) {
if let Some(dispatch) = &self.dispatch {
dispatch(&mut ctx, &msg, error).await;
}

if self.should_ignore(&msg) {
return;
}

Expand Down

0 comments on commit 41698b6

Please sign in to comment.