aboutsummaryrefslogtreecommitdiff
path: root/src/model/misc.rs
diff options
context:
space:
mode:
authorIllia <[email protected]>2016-12-06 23:51:42 +0200
committerzeyla <[email protected]>2016-12-06 13:51:42 -0800
commit13de5c2e50410c3a68435dc774537b490bb7115c (patch)
tree798c633e9e06e520083b29fa4417f089f476d0e0 /src/model/misc.rs
parentFix changelog header (diff)
downloadserenity-13de5c2e50410c3a68435dc774537b490bb7115c.tar.xz
serenity-13de5c2e50410c3a68435dc774537b490bb7115c.zip
Improve Mentions, fix MessageBuilder
Remove the obsolete Mention struct as well as related methods, improve the way mentioning works, fix the message builder, add a test for all this.
Diffstat (limited to 'src/model/misc.rs')
-rw-r--r--src/model/misc.rs51
1 files changed, 18 insertions, 33 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs
index ebf1979..6e208bf 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -1,4 +1,3 @@
-use std::fmt;
use super::{
ChannelId,
Channel,
@@ -19,73 +18,59 @@ pub trait Mentionable {
impl Mentionable for ChannelId {
fn mention(&self) -> String {
- format!("{}", self)
+ format!("<#{}>", self.0)
}
}
impl Mentionable for Channel {
fn mention(&self) -> String {
- format!("{}", self)
+ match *self {
+ Channel::Guild(ref x) => {
+ format!("<#{}>", x.id.0)
+ },
+ Channel::Private(ref x) => {
+ format!("<#{}>", x.id.0)
+ },
+ Channel::Group(ref x) => {
+ format!("<#{}>", x.channel_id.0)
+ }
+ }
}
}
impl Mentionable for Emoji {
fn mention(&self) -> String {
- format!("{}", self)
+ format!("<:{}:{}>", self.name, self.id.0)
}
}
impl Mentionable for Member {
fn mention(&self) -> String {
- format!("{}", self.user)
+ format!("<@{}>", self.user.id.0)
}
}
impl Mentionable for RoleId {
fn mention(&self) -> String {
- format!("{}", self)
+ format!("<@&{}>", self.0)
}
}
impl Mentionable for Role {
fn mention(&self) -> String {
- format!("{}", self)
+ format!("<@&{}>", self.id.0)
}
}
impl Mentionable for UserId {
fn mention(&self) -> String {
- format!("{}", self)
+ format!("<@{}>", self.0)
}
}
impl Mentionable for User {
fn mention(&self) -> String {
- format!("{}", self)
- }
-}
-
-/// A mention targeted at a certain model.
-///
-/// A mention can be created by calling `.mention()` on anything that is
-/// mentionable - or an item's Id - and can be formatted into a string using
-/// [`format!`]:
-///
-/// ```rust,ignore
-/// let message = format!("Mentioning {}", user.mention());
-/// ```
-///
-/// If a `String` is required, call `mention.to_string()`.
-pub struct Mention {
- pub prefix: &'static str,
- pub id: u64,
-}
-
-impl fmt::Display for Mention {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- try!(f.write_str(self.prefix));
- try!(fmt::Display::fmt(&self.id, f));
- fmt::Write::write_char(f, '>')
+ format!("<@{}>", self.id.0)
}
}