aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-05-28 16:42:41 -0500
committerZeyla Hellyer <[email protected]>2017-05-28 14:42:41 -0700
commit543b60421d1c6acd77e02cdd11c7dd2157399821 (patch)
tree42409b9fefabc7c6ec63a105ee2c7717ced8b73b /src/utils
parentMove CreateGroup docs to the struct (diff)
downloadserenity-543b60421d1c6acd77e02cdd11c7dd2157399821.tar.xz
serenity-543b60421d1c6acd77e02cdd11c7dd2157399821.zip
Add _line + _line_safe methods to MessageBuilder
Add new methods to MessageBuilder to push content similar to the other methods, except with the addition of appending a newline afterwards. This should help prettify some MessageBuilder usage.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/message_builder.rs250
1 files changed, 250 insertions, 0 deletions
diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs
index 3029226..164c856 100644
--- a/src/utils/message_builder.rs
+++ b/src/utils/message_builder.rs
@@ -341,6 +341,126 @@ impl MessageBuilder {
self
}
+ /// Pushes the given text with a newline appended to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "hello\nworld");
+ /// ```
+ pub fn push_line(mut self, content: &str) -> Self {
+ self = self.push(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes inlined monospace text with an added newline to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_mono_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "`hello`\nworld");
+ /// ```
+ pub fn push_mono_line(mut self, content: &str) -> Self {
+ self = self.push_mono(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an inlined italicized text with an added newline to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_italic_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "_hello_\nworld");
+ /// ```
+ pub fn push_italic_line(mut self, content: &str) -> Self {
+ self = self.push_italic(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an inline bold text with an added newline to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_bold_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "**hello**\nworld");
+ /// ```
+ pub fn push_bold_line(mut self, content: &str) -> Self {
+ self = self.push_bold(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an underlined inline text with an added newline to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_underline_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "__hello__\nworld");
+ /// ```
+ pub fn push_underline_line(mut self, content: &str) -> Self {
+ self = self.push_underline(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes a strikethrough inline text with a newline added to the content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_strike_line("hello").push("world").build();
+ ///
+ /// assert_eq!(content, "~~hello~~\nworld");
+ /// ```
+ pub fn push_strike_line(mut self, content: &str) -> Self {
+ self = self.push_strike(content);
+ self.0.push('\n');
+
+ self
+ }
+
/// Pushes text to your message, but normalizing content - that means
/// ensuring that there's no unwanted formatting, mention spam etc.
pub fn push_safe(mut self, content: &str) -> Self {
@@ -418,6 +538,136 @@ impl MessageBuilder {
self
}
+ /// Pushes text with a newline appended to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push_line_safe("Hello @everyone").push("How are you?").build();
+ ///
+ /// assert_eq!(content, "Hello @\u{200B}everyone\nHow are you?");
+ /// ```
+ pub fn push_line_safe(mut self, content: &str) -> Self {
+ self = self.push_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an inline monospaced text with added newline to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new()
+ /// .push_mono_line_safe("`hello @everyone`")
+ /// .push("world").build();
+ ///
+ /// assert_eq!(content, "`'hello @\u{200B}everyone'`\nworld");
+ /// ```
+ pub fn push_mono_line_safe(mut self, content: &str) -> Self {
+ self = self.push_mono_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an inline italicized text with added newline to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new()
+ /// .push_italic_line_safe("@everyone")
+ /// .push("Isn't a mention.").build();
+ ///
+ /// assert_eq!(content, "_@\u{200B}everyone_\nIsn't a mention.");
+ /// ```
+ pub fn push_italic_line_safe(mut self, content: &str) -> Self {
+ self = self.push_italic_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an inline bold text with added newline to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new()
+ /// .push_bold_line_safe("@everyone")
+ /// .push("Isn't a mention.").build();
+ ///
+ /// assert_eq!(content, "**@\u{200B}everyone**\nIsn't a mention.");
+ /// ```
+ pub fn push_bold_line_safe(mut self, content: &str) -> Self {
+ self = self.push_bold_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes an underlined inline text with added newline to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new()
+ /// .push_underline_line_safe("@everyone")
+ /// .push("Isn't a mention.").build();
+ ///
+ /// assert_eq!(content, "__@\u{200B}everyone__\nIsn't a mention.");
+ /// ```
+ pub fn push_underline_line_safe(mut self, content: &str) -> Self {
+ self = self.push_underline_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
+ /// Pushes a strikethrough inline text with added newline to the content normalizing content.
+ ///
+ /// # Examples
+ ///
+ /// Push content and then append a newline:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new()
+ /// .push_strike_line_safe("@everyone")
+ /// .push("Isn't a mention.").build();
+ ///
+ /// assert_eq!(content, "~~@\u{200B}everyone~~\nIsn't a mention.");
+ /// ```
+ pub fn push_strike_line_safe(mut self, content: &str) -> Self {
+ self = self.push_strike_safe(content);
+ self.0.push('\n');
+
+ self
+ }
+
/// Mentions the [`Role`] in the built message.
///
/// This accepts anything that converts _into_ a [`RoleId`]. Refer to