Skip to content

Commit

Permalink
do not show the strikethrough-tip If no HelpBehaviour is Strike (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakelezz authored and arqunis committed May 27, 2018
1 parent 23c5398 commit 32c3bed
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/framework/standard/create_help_command.rs
Expand Up @@ -218,17 +218,21 @@ impl CreateHelpCommand {
self
}

fn produce_strike_text(&self, dm_or_guild: &str) -> String {
fn produce_strike_text(&self, dm_or_guild: &str) -> Option<String> {
let mut strike_text = String::from("~~`Strikethrough commands`~~ are unavailable because they");
let mut is_any_option_strike = false;

let mut concat_with_comma = if self.0.lacking_permissions == HelpBehaviour::Strike {
is_any_option_strike = true;
let _ = write!(strike_text, " require permissions");

true
} else {
false
};

if self.0.lacking_role == HelpBehaviour::Strike {
is_any_option_strike = true;

if concat_with_comma {
let _ = write!(strike_text, ", require a specific role");
Expand All @@ -239,6 +243,7 @@ impl CreateHelpCommand {
}

if self.0.wrong_channel == HelpBehaviour::Strike {
is_any_option_strike = true;

if concat_with_comma {
strike_text.push_str(&format!(", or are limited to {}", dm_or_guild));
Expand All @@ -247,7 +252,12 @@ impl CreateHelpCommand {
}
}
let _ = write!(strike_text, ".");
strike_text

if is_any_option_strike {
Some(strike_text)
} else {
None
}
}

/// Finishes the creation of a help-command, returning `Help`.
Expand All @@ -256,13 +266,11 @@ impl CreateHelpCommand {
pub(crate) fn finish(mut self) -> Arc<Help> {

if &self.0.striked_commands_tip_in_dm == &Some(String::new()) {
let strike_text = self.produce_strike_text("direct messages");
self.0.striked_commands_tip_in_dm = Some(strike_text);
self.0.striked_commands_tip_in_dm = self.produce_strike_text("direct messages");
}

if self.0.striked_commands_tip_in_guild == Some(String::new()) {
let strike_text = self.produce_strike_text("guild messages");
self.0.striked_commands_tip_in_guild = Some(strike_text);
self.0.striked_commands_tip_in_guild = self.produce_strike_text("guild messages");
}

let CreateHelpCommand(options, function) = self;
Expand Down

0 comments on commit 32c3bed

Please sign in to comment.