Skip to content

Commit

Permalink
Expose CustomisedHelpData fields, improve help strikethrough message …
Browse files Browse the repository at this point in the history
…attributes. (#904)
  • Loading branch information
jmgao authored Jul 5, 2020
1 parent 0a287e4 commit 0d72b6e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 42 deletions.
17 changes: 1 addition & 16 deletions command_attr/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,7 @@ impl AttributeOption for Option<String> {
fn parse(values: Values) -> Result<Self> {
validate(&values, &[ValueKind::Name, ValueKind::Equals, ValueKind::SingleList])?;

Ok(if values.literals.is_empty() {
Some(String::new())
} else if let Lit::Bool(b) = &values.literals[0] {
if b.value {
Some(String::new())
} else {
None
}
} else {
let s = values.literals[0].to_str();
match &s[..] {
"true" => Some(String::new()),
"false" => None,
_ => Some(s),
}
})
Ok(values.literals.get(0).map(|l| l.to_str()))
}
}

Expand Down
8 changes: 4 additions & 4 deletions command_attr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
/// | `#[available_text(s)]` </br> `#[available_text = s]` | When a command is available. | `s` is a string |
/// | `#[command_not_found_text(s)]` </br> `#[command_not_found_text = s]` | When a command wasn't found. | `s` is a string |
/// | `#[individual_command_tip(s)]` </br> `#[individual_command_tip = s]` | How the user should access a command's details. | `s` is a string |
/// | `#[strikethrough_commands_tip_in_dm]` </br> `#[strikethrough_commands_tip_in_dm(s)]` </br>`#[strikethrough_commands_tip_in_dm = s]` | Reasoning behind strikethrough-commands.</br> *Only used in dms.* | `s` is a string. If there wasn't any text passed, default text will be used instead. |
/// | `#[strikethrough_commands_tip_in_guild]` </br>`#[strikethrough_commands_tip_in_guild(s)]` </br> `#[strikethrough_commands_tip_in_guild = s]` | Reasoning behind strikethrough-commands.</br> *Only used in guilds.* | `s` is a string. If there wasn't any text passed, default text will be used instead. |
/// | `#[strikethrough_commands_tip_in_dm(s)]` </br> `#[strikethrough_commands_tip_in_dm = s]` | Reasoning behind strikethrough-commands.</br> *Only used in dms.* | `s` is a string. If not provided, default text will be used instead. |
/// | `#[strikethrough_commands_tip_in_guild(s)]` </br> `#[strikethrough_commands_tip_in_guild = s]` | Reasoning behind strikethrough-commands.</br> *Only used in guilds.* | `s` is a string. If not provided, default text will be used instead. |
/// | `#[group_prefix(s)]` </br> `#[group_prefix = s]` | For introducing a group's prefix | `s` is a string |
/// | `#[lacking_role(s)]` </br> `#[lacking_role = s]` | If a user lacks required roles, this will treat how commands will be displayed. | `s` is a string. Accepts `strike` (strikethroughs), `hide` (will not be listed) or `nothing`(leave be). |
/// | `#[lacking_ownership(s)]` </br> `#[lacking_ownership = s]` | If a user lacks ownership, this will treat how these commands will be displayed. | `s` is a string. Accepts `strike` (strikethroughs), `hide` (will not be listed) or `nothing`(leave be). |
Expand Down Expand Up @@ -386,11 +386,11 @@ pub fn help(attr: TokenStream, input: TokenStream) -> TokenStream {
}
}

if options.strikethrough_commands_tip_in_dm == Some(String::new()) {
if options.strikethrough_commands_tip_in_dm == None {
options.strikethrough_commands_tip_in_dm = produce_strike_text(&options, "direct messages");
}

if options.strikethrough_commands_tip_in_guild == Some(String::new()) {
if options.strikethrough_commands_tip_in_guild == None {
options.strikethrough_commands_tip_in_guild =
produce_strike_text(&options, "guild messages");
}
Expand Down
4 changes: 2 additions & 2 deletions command_attr/src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ impl Default for HelpOptions {
name as an argument to this command."
.to_string(),
group_prefix: "Prefix".to_string(),
strikethrough_commands_tip_in_dm: Some(String::new()),
strikethrough_commands_tip_in_guild: Some(String::new()),
strikethrough_commands_tip_in_dm: None,
strikethrough_commands_tip_in_guild: None,
lacking_role: HelpBehaviour::Strike,
lacking_permissions: HelpBehaviour::Strike,
lacking_ownership: HelpBehaviour::Hide,
Expand Down
5 changes: 2 additions & 3 deletions examples/e05_command_framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ If you want more information about a specific command, just pass the command as
#[wrong_channel = "Strike"]
// Serenity will automatically analyse and generate a hint/tip explaining the possible
// cases of ~~strikethrough-commands~~, but only if
// `strikethrough_commands_tip(Some(""))` keeps `Some()` wrapping an empty `String`, which is the default value.
// If the `String` is not empty, your given `String` will be used instead.
// If you pass in a `None`, no hint will be displayed at all.
// `strikethrough_commands_tip_{dm, guild}` aren't specified.
// If you pass in a value, it will be displayed instead.
fn my_help(
context: &Context,
msg: &Message,
Expand Down
36 changes: 19 additions & 17 deletions src/framework/standard/help_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,39 @@ macro_rules! warn_about_failed_send {
/// in relation of help-settings measured to the user.
#[derive(Clone, Debug, Default)]
pub struct GroupCommandsPair {
name: &'static str,
prefixes: Vec<&'static str>,
command_names: Vec<String>,
sub_groups: Vec<GroupCommandsPair>,
pub name: &'static str,
pub prefixes: Vec<&'static str>,
pub command_names: Vec<String>,
pub sub_groups: Vec<GroupCommandsPair>,
}

/// A single suggested command containing its name and Levenshtein distance
/// to the actual user's searched command name.
#[derive(Clone, Debug, Default)]
struct SuggestedCommandName {
name: String,
levenshtein_distance: usize,
pub struct SuggestedCommandName {
pub name: String,
pub levenshtein_distance: usize,
}

/// A single command containing all related pieces of information.
#[derive(Clone, Debug)]
pub struct Command<'a> {
name: &'static str,
group_name: &'static str,
group_prefixes: &'a [&'static str],
aliases: Vec<&'static str>,
availability: &'a str,
description: Option<&'static str>,
usage: Option<&'static str>,
usage_sample: Vec<&'static str>,
checks: Vec<String>,
pub name: &'static str,
pub group_name: &'static str,
pub group_prefixes: &'a [&'static str],
pub aliases: Vec<&'static str>,
pub availability: &'a str,
pub description: Option<&'static str>,
pub usage: Option<&'static str>,
pub usage_sample: Vec<&'static str>,
pub checks: Vec<String>,
pub(crate) _nonexhaustive: (),
}

/// Contains possible suggestions in case a command could not be found
/// but are similar enough.
#[derive(Clone, Debug, Default)]
pub struct Suggestions(Vec<SuggestedCommandName>);
pub struct Suggestions(pub Vec<SuggestedCommandName>);

#[cfg(all(feature = "cache", feature = "http"))]
impl Suggestions {
Expand Down Expand Up @@ -552,6 +553,7 @@ fn nested_group_command_search<'a>(
availability: available_text,
usage: options.usage,
usage_sample: options.examples.to_vec(),
_nonexhaustive: (),
},
});
}
Expand Down

0 comments on commit 0d72b6e

Please sign in to comment.