diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-04 20:32:25 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-06 10:12:13 -0700 |
| commit | 990e611a56f37f64fbce74fbc487c7dcc4aa4e28 (patch) | |
| tree | 399c69583bd256d31668affc227f235386814552 /src/model/channel/message.rs | |
| parent | Add CurrentUser::face(), User::face() (diff) | |
| download | serenity-990e611a56f37f64fbce74fbc487c7dcc4aa4e28.tar.xz serenity-990e611a56f37f64fbce74fbc487c7dcc4aa4e28.zip | |
Use chrono for struct timestamp fields
Chrono is easier to use than timestamped strings, so they should be
automatically deserialized and available for the user, instead of having
the user deserialize the strings themselves.
These fields have been changed to use a type of `DateTime<FixedOffset>`:
- `ChannelPinsUpdateEvent.last_pin_timestamp`
- `Group.last_pin_timestamp`
- `Guild.joined_at`
- `GuildChannel.last_pin_timestamp`
- `Invite.created_at`
- `Member.joined_at`
- `Message.edited_timestamp
- `Message.timestamp`
- `MessageUpdateEvent.edited_timestamp`
- `MessageUpdateEvent.timestamp`
- `PrivateChannel.last_pin_timestamp`
`Member.joined_at` is now also an `Option`. Previously, if a Guild
Member Update was received for a member not in the cache, a new Member
would be instantiated with a default String value. This is incorrect
behaviour, and has now been replaced with being set to `None` in that
case.
Id methods' `created_at()` method now return a `chrono::NaiveDateTime`
instead of a `time::Timespec`, and `User::created_at` has been updated
to reflect that.
Additionally, drop `time` as a direct dependency and use chrono for
internals.
Diffstat (limited to 'src/model/channel/message.rs')
| -rw-r--r-- | src/model/channel/message.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 8b9f0af..612113d 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, FixedOffset}; use ::model::*; #[cfg(feature="cache")] @@ -5,8 +6,6 @@ use std::fmt::Write; #[cfg(feature="model")] use std::mem; #[cfg(feature="model")] -use time; -#[cfg(feature="model")] use ::builder::{CreateEmbed, CreateMessage}; #[cfg(feature="model")] use ::constants; @@ -33,7 +32,7 @@ pub struct Message { /// The content of the message. pub content: String, /// The timestamp of the last time the message was updated, if it was. - pub edited_timestamp: Option<String>, + pub edited_timestamp: Option<DateTime<FixedOffset>>, /// Array of embeds sent with the message. pub embeds: Vec<Embed>, /// Indicator of the type of message this is, i.e. whether it is a regular @@ -56,7 +55,7 @@ pub struct Message { #[serde(default)] pub reactions: Vec<MessageReaction>, /// Initial message creation timestamp, calculated from its Id. - pub timestamp: String, + pub timestamp: DateTime<FixedOffset>, /// Indicator of whether the command is to be played back via /// text-to-speech. /// @@ -240,16 +239,14 @@ impl Message { 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() - }; - } + let sec = self.timestamp.timestamp() 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() + }; }, _ => {}, } |