aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel/channel_id.rs12
-rw-r--r--src/model/channel/message.rs25
2 files changed, 37 insertions, 0 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index 66bbbf3..46b00c6 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -255,6 +255,11 @@ impl ChannelId {
#[inline]
pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> {
rest::get_message(self.0, message_id.into().0)
+ .map(|mut msg| {
+ msg.transform_content();
+
+ msg
+ })
}
/// Gets messages from the channel.
@@ -279,6 +284,13 @@ impl ChannelId {
}
rest::get_messages(self.0, &query)
+ .map(|msgs| msgs
+ .into_iter()
+ .map(|mut msg| {
+ msg.transform_content();
+
+ msg
+ }).collect::<Vec<Message>>())
}
/// Pins a [`Message`] to the channel.
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index d360975..593aa48 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -1,4 +1,5 @@
use std::mem;
+use time;
use ::constants;
use ::client::rest;
use ::model::*;
@@ -189,6 +190,28 @@ impl Message {
}
}
+ #[doc(hidden)]
+ pub fn transform_content(&mut self) {
+ match self.kind {
+ MessageType::PinsAdd => {
+ self.content = format!("{} pinned a message to this channel. See all the pins.", self.author);
+ },
+ MessageType::MemberJoin => {
+ if let Ok(tm) = time::strptime(&self.timestamp, "%Y-%m-%dT%H:%M:%S") {
+ let sec = tm.to_timespec().sec as usize;
+ let chosen = constants::JOIN_MESSAGES[sec % constants::JOIN_MESSAGES.len()];
+
+ self.content = if chosen.contains("$user") {
+ chosen.replace("$user", &self.author.mention())
+ } else {
+ chosen.to_owned()
+ };
+ }
+ },
+ _ => {},
+ }
+ }
+
/// Returns message content, but with user and role mentions replaced with
/// names and everyone/here mentions cancelled.
#[cfg(feature="cache")]
@@ -550,6 +573,8 @@ enum_number!(
GroupIconUpdate = 5,
/// An indicator that a message was pinned by the author.
PinsAdd = 6,
+ /// An indicator that a member joined the guild.
+ MemberJoin = 7,
}
);