aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2018-05-25 19:58:04 +0200
committerAlex M. M <[email protected]>2018-05-25 19:58:04 +0200
commit89a18aa919d8c08cf9fba9a98ebe32c9fd59d5d4 (patch)
tree95104f88f6745c28d5470453136687ca88fd68d0 /src/framework
parentAdd an option for a bot to work only in certain channels (#318) (diff)
downloadserenity-89a18aa919d8c08cf9fba9a98ebe32c9fd59d5d4.tar.xz
serenity-89a18aa919d8c08cf9fba9a98ebe32c9fd59d5d4.zip
help: differentiate whether a command is unavailable in dms or guilds (#319)
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/command.rs15
-rw-r--r--src/framework/standard/create_help_command.rs121
-rw-r--r--src/framework/standard/help_commands.rs27
3 files changed, 114 insertions, 49 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index 1dff57b..8c35451 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -161,10 +161,18 @@ pub struct HelpOptions {
pub command_not_found_text: String,
/// Explains the user on how to use access a single command's details.
pub individual_command_tip: String,
- /// Explains reasoning behind striked commands, see fields requiring `HelpBehaviour` for further information.
+ /// 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`.
- pub striked_commands_tip: Option<String>,
+ ///
+ /// **Note**: Text is only used in direct messages.
+ pub striked_commands_tip_in_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>,
/// 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.
@@ -213,7 +221,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: Some(String::new()),
+ striked_commands_tip_in_dm: Some(String::new()),
+ striked_commands_tip_in_guild: Some(String::new()),
lacking_role: HelpBehaviour::Strike,
lacking_permissions: HelpBehaviour::Strike,
wrong_channel: HelpBehaviour::Strike,
diff --git a/src/framework/standard/create_help_command.rs b/src/framework/standard/create_help_command.rs
index 3796139..8899a41 100644
--- a/src/framework/standard/create_help_command.rs
+++ b/src/framework/standard/create_help_command.rs
@@ -1,13 +1,13 @@
use super::command::{
- Help,
- HelpOptions,
+ Help,
+ HelpOptions,
HelpFunction
};
pub use super::{
- Args,
- CommandGroup,
- CommandOptions,
- CommandError,
+ Args,
+ CommandGroup,
+ CommandOptions,
+ CommandError,
HelpBehaviour
};
@@ -157,13 +157,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 striked,
+ /// 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
+ /// 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 = text;
+ self.0.striked_commands_tip_in_dm = text.clone();
+ self.0.striked_commands_tip_in_guild = text;
+
+ self
+ }
+
+ /// Sets the tip (or legend) explaining why some commands are striked,
+ /// 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;
+
+ self
+ }
+
+ /// Sets the tip (or legend) explaining why some commands are striked,
+ /// 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;
self
}
@@ -182,44 +218,53 @@ impl CreateHelpCommand {
self
}
- /// Finishes the creation of a help-command, returning `Help`.
- /// If `Some(String)` was set as `striked_commands_tip` and the `String` is empty,
- /// the creator will substitute content based on the `HelpBehaviour`-settings.
- #[cfg_attr(feature = "cargo-clippy", allow(useless_if_let_seq))]
- pub(crate) fn finish(self) -> Arc<Help> {
- if self.0.striked_commands_tip == Some(String::new()) {
- let mut strike_text = String::from("~~`Striked commands`~~ are unavailable because they");
-
- let mut concat_with_comma = if self.0.lacking_permissions == HelpBehaviour::Strike {
- let _ = write!(strike_text, " require permissions");
- true
- } else {
- false
- };
+ fn produce_strike_text(&self, dm_or_guild: &str) -> String {
+ let mut strike_text = String::from("~~`Strikethrough commands`~~ are unavailable because they");
+
+ let mut concat_with_comma = if self.0.lacking_permissions == HelpBehaviour::Strike {
+ let _ = write!(strike_text, " require permissions");
+ true
+ } else {
+ false
+ };
- if self.0.lacking_role == HelpBehaviour::Strike {
+ if self.0.lacking_role == HelpBehaviour::Strike {
- if concat_with_comma {
- let _ = write!(strike_text, ", require a specific role");
- } else {
- let _ = write!(strike_text, " require a specific role");
- concat_with_comma = true;
- }
+ if concat_with_comma {
+ let _ = write!(strike_text, ", require a specific role");
+ } else {
+ let _ = write!(strike_text, " require a specific role");
+ concat_with_comma = true;
}
+ }
- if self.0.wrong_channel == HelpBehaviour::Strike {
+ if self.0.wrong_channel == HelpBehaviour::Strike {
- if concat_with_comma {
- let _ = write!(strike_text, " or are limited to DM/guilds");
- } else {
- let _ = write!(strike_text, " are limited to DM/guilds");
- }
+ if concat_with_comma {
+ strike_text.push_str(&format!(", or are limited to {}", dm_or_guild));
+ } else {
+ strike_text.push_str(&format!(" are limited to {}", dm_or_guild));
}
+ }
+ let _ = write!(strike_text, ".");
+ strike_text
+ }
- let _ = write!(strike_text, ".");
- let CreateHelpCommand(options, function) = self.striked_commands_tip(Some(strike_text));
- return Arc::new(Help(function, Arc::new(options)))
+ /// Finishes the creation of a help-command, returning `Help`.
+ /// If `Some(String)` was set as `striked_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()) {
+ let strike_text = self.produce_strike_text("direct messages");
+ self.0.striked_commands_tip_in_dm = Some(strike_text);
+ }
+
+ 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);
}
+
let CreateHelpCommand(options, function) = self;
Arc::new(Help(function, Arc::new(options)))
diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs
index 3acc37b..28adb9f 100644
--- a/src/framework/standard/help_commands.rs
+++ b/src/framework/standard/help_commands.rs
@@ -38,12 +38,12 @@ use std::{
};
use super::command::InternalCommand;
use super::{
- Args,
- CommandGroup,
- CommandOrAlias,
- HelpOptions,
- CommandOptions,
- CommandError,
+ Args,
+ CommandGroup,
+ CommandOrAlias,
+ HelpOptions,
+ CommandOptions,
+ CommandError,
HelpBehaviour
};
use utils::Colour;
@@ -222,8 +222,13 @@ pub fn with_embeds<H: BuildHasher>(
let _ = msg.channel_id.send_message(|m| {
m.embed(|mut e| {
+ let striked_command_tip = if msg.is_private() {
+ &help_options.striked_commands_tip_in_guild
+ } else {
+ &help_options.striked_commands_tip_in_dm
+ };
- if let Some(ref striked_command_text) = help_options.striked_commands_tip {
+ if let Some(ref striked_command_text) = striked_command_tip {
e = e.colour(help_options.embed_success_colour).description(
format!("{}\n{}", &help_options.individual_command_tip, striked_command_text),
);
@@ -461,7 +466,13 @@ pub fn plain<H: BuildHasher>(
let mut result = "**Commands**\n".to_string();
- if let Some(ref striked_command_text) = help_options.striked_commands_tip {
+ let striked_command_tip = if msg.is_private() {
+ &help_options.striked_commands_tip_in_guild
+ } else {
+ &help_options.striked_commands_tip_in_dm
+ };
+
+ if let Some(ref striked_command_text) = striked_command_tip {
let _ = write!(result, "{}\n{}\n\n", &help_options.individual_command_tip, striked_command_text);
} else {
let _ = write!(result, "{}\n\n", &help_options.individual_command_tip);