Skip to content

Commit

Permalink
Make Message::reply take a content implementing std::fmt::Display (
Browse files Browse the repository at this point in the history
…#909)

This is to stay consistent with the various `say()` methods.
  • Loading branch information
vicky5124 committed Jul 8, 2020
1 parent 21a5d8e commit 00683ef
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/model/channel/message.rs
Expand Up @@ -3,6 +3,7 @@
use chrono::{DateTime, FixedOffset};
use crate::model::prelude::*;
use serde_json::Value;
use std::fmt::Display;

#[cfg(all(feature = "model", feature = "utils"))]
use crate::builder::{CreateEmbed, EditMessage};
Expand Down Expand Up @@ -529,10 +530,8 @@ impl Message {
/// [`ModelError::InvalidPermissions`]: ../error/enum.Error.html#variant.InvalidPermissions
/// [`ModelError::MessageTooLong`]: ../error/enum.Error.html#variant.MessageTooLong
/// [Send Messages]: ../permissions/struct.Permissions.html#associatedconstant.SEND_MESSAGES
pub fn reply(&self, cache_http: impl CacheHttp, content: impl AsRef<str>) -> Result<Message> {
let content = content.as_ref();

if let Some(length_over) = Message::overflow_length(content) {
pub fn reply(&self, cache_http: impl CacheHttp, content: impl Display) -> Result<Message> {
if let Some(length_over) = Message::overflow_length(&content.to_string()) {
return Err(Error::Model(ModelError::MessageTooLong(length_over)));
}

Expand All @@ -550,9 +549,7 @@ impl Message {
}
}

let mut gen = self.author.mention();
gen.push_str(": ");
gen.push_str(content);
let gen = format!("{}: {}", self.author.mention(), content);

let map = json!({
"content": gen,
Expand Down

0 comments on commit 00683ef

Please sign in to comment.