Skip to content

Commit

Permalink
Use one macro instead of the same code twice, avoid seperated changes. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakelezz committed Aug 11, 2018
1 parent 7b0cff6 commit 516ede3
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/framework/standard/mod.rs
Expand Up @@ -147,6 +147,17 @@ macro_rules! command {
};
}

macro_rules! command_and_help_args {
($message_content:expr, $position:expr, $command_length:expr, $delimiters:expr) => {
{
let content = $message_content.chars().skip($position).skip_while(|x| x.is_whitespace())
.skip($command_length).collect::<String>();

Args::new(&content.trim(), $delimiters)
}
};
}

/// An enum representing all possible fail conditions under which a command won't
/// be executed.
#[derive(Debug)]
Expand Down Expand Up @@ -1072,15 +1083,7 @@ impl Framework for StandardFramework {

if let Some(help) = help {
let groups = self.groups.clone();

// `Args`-construction here inside help-dispatch and the command-dispatch-section
// shall stay identical, please update accordingly upon change.
let mut args = {
let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace())
.skip(command_length).collect::<String>();

Args::new(&content.trim(), &self.configuration.delimiters)
};
let mut args = command_and_help_args!(&message.content, position, command_length, &self.configuration.delimiters);

threadpool.execute(move || {

Expand All @@ -1106,15 +1109,7 @@ impl Framework for StandardFramework {
if let Some(&CommandOrAlias::Command(ref command)) =
group.commands.get(&to_check) {
let command = Arc::clone(command);

// `Args`-construction here inside command-dispatch and the help-dispatch
// shall stay identical, please update accordingly upon change.
let mut args = {
let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace())
.skip(command_length).collect::<String>();

Args::new(&content.trim(), &self.configuration.delimiters)
};
let mut args = command_and_help_args!(&message.content, position, command_length, &self.configuration.delimiters);

if let Some(error) = self.should_fail(
&mut context,
Expand Down

0 comments on commit 516ede3

Please sign in to comment.