aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-04-26 21:02:02 -0700
committerZeyla Hellyer <[email protected]>2018-05-27 19:21:18 -0700
commit309eee7ba66de7870011825a9130828e9b49e83c (patch)
tree202559d698f927b0f8840804b7b5ccc83cb325f0 /src/framework
parentRemove user account relation docs/functions (diff)
downloadserenity-309eee7ba66de7870011825a9130828e9b49e83c.tar.xz
serenity-309eee7ba66de7870011825a9130828e9b49e83c.zip
Make builders mutably borrowed
Change the builders so that they are now mutably borrowed, accepting `&mut self` instead of `self`. Their methods now return `()` instead of `Self`. Upgrade path: Change code such as the following: ```rust channel.send_message(|m| m .embed(|e| e .description("test") .title("title"))); ``` to the following style: ```rust channel.send_message(|mut m| { m.embed(|mut e| { e.description("test"); e.title("title"); e }); m }); ``` Closes #159.
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/help_commands.rs72
1 files changed, 44 insertions, 28 deletions
diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs
index 8c0e1b4..7f6ca72 100644
--- a/src/framework/standard/help_commands.rs
+++ b/src/framework/standard/help_commands.rs
@@ -49,8 +49,15 @@ use super::{
use utils::Colour;
fn error_embed(channel_id: &ChannelId, input: &str, colour: Colour) {
- let _ = channel_id.send_message(|m| {
- m.embed(|e| e.colour(colour).description(input))
+ let _ = channel_id.send_message(|mut m| {
+ m.embed(|mut e| {
+ e.colour(colour);
+ e.description(input);
+
+ e
+ });
+
+ m
});
}
@@ -167,34 +174,36 @@ pub fn with_embeds<H: BuildHasher>(
return Ok(());
}
- let _ = msg.channel_id.send_message(|m| {
- m.embed(|e| {
- let mut embed = e.colour(help_options.embed_success_colour).title(command_name);
+ let _ = msg.channel_id.send_message(|mut m| {
+ m.embed(|mut embed| {
+ embed.colour(help_options.embed_success_colour);
+
+ embed.title(command_name.clone());
if let Some(ref desc) = command.desc {
- embed = embed.description(desc);
+ embed.description(desc);
}
if let Some(ref usage) = command.usage {
let value = format!("`{} {}`", command_name, usage);
- embed = embed.field(&help_options.usage_label, value, true);
+ embed.field(&help_options.usage_label, value, true);
}
if let Some(ref example) = command.example {
let value = format!("`{} {}`", command_name, example);
- embed = embed.field(&help_options.usage_sample_label, value, true);
+ embed.field(&help_options.usage_sample_label, value, true);
}
if group_name != "Ungrouped" {
- embed = embed.field(&help_options.grouped_label, group_name, true);
+ embed.field(&help_options.grouped_label, group_name, true);
}
if !command.aliases.is_empty() {
let aliases = command.aliases.join(", ");
- embed = embed.field(&help_options.aliases_label, aliases, true);
+ embed.field(&help_options.aliases_label, aliases, true);
}
let available = if command.dm_only {
@@ -205,10 +214,12 @@ pub fn with_embeds<H: BuildHasher>(
&help_options.dm_and_guild_text
};
- embed = embed.field(&help_options.available_text, available, true);
+ embed.field(&help_options.available_text, available, true);
embed
- })
+ });
+
+ m
});
return Ok(());
@@ -221,22 +232,24 @@ pub fn with_embeds<H: BuildHasher>(
return Ok(());
}
- let _ = msg.channel_id.send_message(|m| {
- m.embed(|mut e| {
+ let _ = msg.channel_id.send_message(|mut m| {
+ m.embed(|mut embed| {
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 {
- e = e.colour(help_options.embed_success_colour).description(
- format!("{}\n{}", &help_options.individual_command_tip, striked_command_text),
- );
+ &help_options.striked_commands_tip_in_guild
} else {
- e = e.colour(help_options.embed_success_colour).description(
+ &help_options.striked_commands_tip_in_dm
+ };
+
+ if let Some(ref striked_command_text) = striked_command_tip{
+ embed.colour(help_options.embed_success_colour);
+ embed.description(format!(
+ "{}\n{}",
&help_options.individual_command_tip,
- );
+ &striked_command_text,
+ ));
+ } else {
+ embed.colour(help_options.embed_success_colour);
+ embed.description(&help_options.individual_command_tip);
}
let mut group_names = groups.keys().collect::<Vec<_>>();
@@ -302,11 +315,14 @@ pub fn with_embeds<H: BuildHasher>(
}
if has_commands {
- e = e.field(&group_name[..], &desc[..], true);
+ embed.field(&group_name[..], &desc[..], true);
}
}
- e
- })
+
+ embed
+ });
+
+ m
});
Ok(())