Skip to content

Commit

Permalink
Improve Help Consistency (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakelezz authored Feb 17, 2019
1 parent cdbc52f commit c74fbb2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 103 deletions.
2 changes: 1 addition & 1 deletion examples/05_command_framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn main() {
.wrong_channel(HelpBehaviour::Strike)
// Serenity will automatically analyse and generate a hint/tip explaining the possible
// cases of ~~strikethrough-commands~~, but only if
// `striked_commands_tip(Some(""))` keeps `Some()` wrapping an empty `String`, which is the default value.
// `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.
})
Expand Down
15 changes: 6 additions & 9 deletions src/framework/standard/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<D: fmt::Display> From<D> for Error {

#[derive(Debug)]
pub struct CommandGroup {
pub prefixes: Option<Vec<String>>,
pub prefixes: Vec<String>,
pub commands: HashMap<String, CommandOrAlias>,
/// Some fields taken from Command
pub bucket: Option<String>,
Expand All @@ -94,7 +94,7 @@ pub struct CommandGroup {
impl Default for CommandGroup {
fn default() -> CommandGroup {
CommandGroup {
prefixes: None,
prefixes: Vec::new(),
commands: HashMap::new(),
bucket: None,
required_permissions: Permissions::empty(),
Expand Down Expand Up @@ -155,8 +155,6 @@ pub struct HelpOptions {
pub no_help_available_text: String,
/// How to use a command, `{usage_label}: {command_name} {args}`
pub usage_label: String,
/// Actual sample label, `{usage_sample_label}: {command_name} {args}`
pub usage_sample_label: String,
/// Text labeling ungrouped commands, `{ungrouped_label}: ...`
pub ungrouped_label: String,
/// Text labeling the start of the description.
Expand Down Expand Up @@ -186,13 +184,13 @@ pub struct HelpOptions {
/// inside of `CreateHelpCommand`.
///
/// **Note**: Text is only used in direct messages.
pub striked_commands_tip_in_dm: Option<String>,
pub strikethrough_commands_tip_dm: Option<String>,
/// Explains reasoning behind strikethrough-commands, see fields requiring `HelpBehaviour` for further information.
/// If `HelpBehaviour::Strike` is unused, this field will evaluate to `None` during creation
/// inside of `CreateHelpCommand`.
///
/// **Note**: Text is only used in guilds.
pub striked_commands_tip_in_guild: Option<String>,
pub strikethrough_commands_tip_guild: Option<String>,
/// Announcing a group's prefix as in: {group_prefix} {prefix}.
pub group_prefix: String,
/// If a user lacks required roles, this will treat how these commands will be displayed.
Expand Down Expand Up @@ -238,7 +236,6 @@ impl Default for HelpOptions {
suggestion_text: "Did you mean `{}`?".to_string(),
no_help_available_text: "**Error**: No help available.".to_string(),
usage_label: "Usage".to_string(),
usage_sample_label: "Sample usage".to_string(),
ungrouped_label: "Ungrouped".to_string(),
grouped_label: "Group".to_string(),
aliases_label: "Aliases".to_string(),
Expand All @@ -252,8 +249,8 @@ impl Default for HelpOptions {
individual_command_tip: "To get help with an individual command, pass its \
name as an argument to this command.".to_string(),
group_prefix: "Prefix".to_string(),
striked_commands_tip_in_dm: Some(String::new()),
striked_commands_tip_in_guild: Some(String::new()),
strikethrough_commands_tip_dm: Some(String::new()),
strikethrough_commands_tip_guild: Some(String::new()),
lacking_role: HelpBehaviour::Strike,
lacking_permissions: HelpBehaviour::Strike,
lacking_ownership: HelpBehaviour::Hide,
Expand Down
32 changes: 16 additions & 16 deletions src/framework/standard/create_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ impl CreateGroup {

for alias in &cmd.options().aliases {

if let Some(ref prefixes) = self.0.prefixes {
if self.0.prefixes.is_empty() {
self.0.commands.insert(
alias.to_string(),
CommandOrAlias::Alias(command_name.to_string()),
);

for prefix in prefixes {
} else {
for prefix in &self.0.prefixes {
self.0.commands.insert(
format!("{} {}", prefix, alias.to_string()),
CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())),
);
}
} else {
self.0.commands.insert(
alias.to_string(),
CommandOrAlias::Alias(command_name.to_string()),
);
}
}

Expand All @@ -99,19 +99,19 @@ impl CreateGroup {

for alias in &cmd.options().aliases {

if let Some(ref prefixes) = self.0.prefixes {
if self.0.prefixes.is_empty() {
self.0.commands.insert(
alias.to_string(),
CommandOrAlias::Alias(name.to_string()),
);

for prefix in prefixes {
} else {
for prefix in &self.0.prefixes {
self.0.commands.insert(
format!("{} {}", prefix, alias.to_string()),
CommandOrAlias::Alias(format!("{} {}", prefix, name.to_string())),
);
}
} else {
self.0.commands.insert(
alias.to_string(),
CommandOrAlias::Alias(name.to_string()),
);
}
}

Expand All @@ -132,7 +132,7 @@ impl CreateGroup {
///
/// **Note**: It's suggested to call this first when making a group.
pub fn prefix(mut self, prefix: &str) -> Self {
self.0.prefixes = Some(vec![prefix.to_string()]);
self.0.prefixes = vec![prefix.to_string()];

self
}
Expand All @@ -144,7 +144,7 @@ impl CreateGroup {
///
/// **Note**: It's suggested to call this first when making a group.
pub fn prefixes<T: ToString, I: IntoIterator<Item=T>>(mut self, prefixes: I) -> Self {
self.0.prefixes = Some(prefixes.into_iter().map(|prefix| prefix.to_string()).collect());
self.0.prefixes = prefixes.into_iter().map(|prefix| prefix.to_string()).collect();

self
}
Expand Down
45 changes: 19 additions & 26 deletions src/framework/standard/create_help_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ impl CreateHelpCommand {
self
}

/// Sets a label for the usage examples of a command.
pub fn usage_sample_label(mut self, text: &str) -> Self {
self.0.usage_sample_label = text.to_string();

self
}

/// Sets a label for ungrouped-commands
pub fn ungrouped_label(mut self, text: &str) -> Self {
self.0.ungrouped_label = text.to_string();
Expand Down Expand Up @@ -165,49 +158,49 @@ impl CreateHelpCommand {
self
}

/// Sets the tip (or legend) explaining why some commands are striked,
/// Sets the tip (or legend) explaining why some commands are in strikethrough-style,
/// given text will be used in guilds and direct messages.
///
/// By default this is `Some(String)` and the `String` is empty resulting
/// in an automated substitution based on your `HelpBehaviour`-settings.
/// If set to `None`, no tip will be given nor will it be substituted.
/// If set to a non-empty `Some(String)`, the `String` will be displayed as tip.
///
/// **Note**: [`CreateHelpCommand::striked_commands_tip_in_direct_message`] and
/// [`CreateHelpCommand::striked_commands_tip_in_guild`] can specifically set this text
/// **Note**: [`CreateHelpCommand::strikethrough_commands_tip_in_direct_message`] and
/// [`CreateHelpCommand::strikethrough_commands_tip_guild`] can specifically set this text
/// for direct messages and guilds.
///
/// [`CreateHelpCommand::striked_commands_tip_in_direct_message`]: #method.striked_commands_tip_in_direct_message
/// [`CreateHelpCommand::striked_commands_tip_in_guild`]: #method.striked_commands_tip_in_guild
pub fn striked_commands_tip(mut self, text: Option<String>) -> Self {
self.0.striked_commands_tip_in_dm = text.clone();
self.0.striked_commands_tip_in_guild = text;
/// [`CreateHelpCommand::strikethrough_commands_tip_in_direct_message`]: #method.strikethrough_commands_tip_in_direct_message
/// [`CreateHelpCommand::strikethrough_commands_tip_guild`]: #method.strikethrough_commands_tip_guild
pub fn strikethrough_commands_tip(mut self, text: Option<String>) -> Self {
self.0.strikethrough_commands_tip_dm = text.clone();
self.0.strikethrough_commands_tip_guild = text;

self
}

/// Sets the tip (or legend) explaining why some commands are striked,
/// Sets the tip (or legend) explaining why some commands are in strikethrough-style,
/// given text will be used in guilds.
///
/// By default this is `Some(String)` and the `String` is empty resulting
/// in an automated substitution based on your `HelpBehaviour`-settings.
/// If set to `None`, no tip will be given nor will it be substituted.
/// If set to a non-empty `Some(String)`, the `String` will be displayed as tip.
pub fn striked_commands_tip_in_guild(mut self, text: Option<String>) -> Self {
self.0.striked_commands_tip_in_guild = text;
pub fn strikethrough_commands_tip_guild(mut self, text: Option<String>) -> Self {
self.0.strikethrough_commands_tip_guild = text;

self
}

/// Sets the tip (or legend) explaining why some commands are striked,
/// Sets the tip (or legend) explaining why some commands are in strikethrough-style,
/// given text will be used in direct messages.
///
/// By default this is `Some(String)` and the `String` is empty resulting
/// in an automated substitution based on your `HelpBehaviour`-settings.
/// If set to `None`, no tip will be given nor will it be substituted.
/// If set to a non-empty `Some(String)`, the `String` will be displayed as tip.
pub fn striked_commands_tip_in_direct_message(mut self, text: Option<String>) -> Self {
self.0.striked_commands_tip_in_dm = text;
pub fn strikethrough_commands_tip_in_direct_message(mut self, text: Option<String>) -> Self {
self.0.strikethrough_commands_tip_dm = text;

self
}
Expand Down Expand Up @@ -288,15 +281,15 @@ impl CreateHelpCommand {
}

/// Finishes the creation of a help-command, returning `Help`.
/// If `Some(String)` was set as `striked_commands_tip` and the `String` is empty,
/// If `Some(String)` was set as `strikethrough_commands_tip` and the `String` is empty,
/// the creator will substitute content based on the `HelpBehaviour`-settings.
pub(crate) fn finish(mut self) -> Arc<Help> {
if self.0.striked_commands_tip_in_dm == Some(String::new()) {
self.0.striked_commands_tip_in_dm = self.produce_strike_text("direct messages");
if self.0.strikethrough_commands_tip_dm == Some(String::new()) {
self.0.strikethrough_commands_tip_dm = self.produce_strike_text("direct messages");
}

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

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

0 comments on commit c74fbb2

Please sign in to comment.