aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-13 21:39:26 -0700
committerZeyla Hellyer <[email protected]>2017-05-22 16:44:46 -0700
commit3062981bfc1412e93450b30fa9405e555624ce1e (patch)
treea24f896e0b212afc31d4f135b9cc72788238b6e7 /src
parentAdd GuildChannel::permissions_for (diff)
downloadserenity-3062981bfc1412e93450b30fa9405e555624ce1e.tar.xz
serenity-3062981bfc1412e93450b30fa9405e555624ce1e.zip
Add `Invite::url()`, `RichInvite::url()`
Add helper methods to easily produce invite URLs, such as `"https://discord.gg/WxZumR"`.
Diffstat (limited to 'src')
-rw-r--r--src/model/invite.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/model/invite.rs b/src/model/invite.rs
index f7e8e48..054bece 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -103,6 +103,36 @@ impl Invite {
pub fn get(code: &str, stats: bool) -> Result<Invite> {
rest::get_invite(utils::parse_invite(code), stats)
}
+
+ /// Returns a URL to use for the invite.
+ ///
+ /// # Examples
+ ///
+ /// Retrieve the URL for an invite with the code `WxZumR`:
+ ///
+ /// ```rust
+ /// # use serenity::model::*;
+ /// #
+ /// # let invite = Invite {
+ /// # code: "WxZumR".to_owned(),
+ /// # channel: InviteChannel {
+ /// # id: ChannelId(1),
+ /// # name: "foo".to_owned(),
+ /// # kind: ChannelType::Text,
+ /// # },
+ /// # guild: InviteGuild {
+ /// # id: GuildId(2),
+ /// # icon: None,
+ /// # name: "bar".to_owned(),
+ /// # splash_hash: None,
+ /// # },
+ /// # };
+ /// #
+ /// assert_eq!(invite.url(), "https://discord.gg/WxZumR");
+ /// ```
+ pub fn url(&self) -> String {
+ format!("https://discord.gg/{}", self.code)
+ }
}
/// A inimal information about the channel an invite points to.
@@ -240,4 +270,46 @@ impl RichInvite {
rest::delete_invite(&self.code)
}
+
+ /// Returns a URL to use for the invite.
+ ///
+ /// # Examples
+ ///
+ /// Retrieve the URL for an invite with the code `WxZumR`:
+ ///
+ /// ```rust
+ /// # use serenity::model::*;
+ /// #
+ /// # let invite = RichInvite {
+ /// # code: "WxZumR".to_owned(),
+ /// # channel: InviteChannel {
+ /// # id: ChannelId(1),
+ /// # name: "foo".to_owned(),
+ /// # kind: ChannelType::Text,
+ /// # },
+ /// # created_at: "bar".to_owned(),
+ /// # guild: InviteGuild {
+ /// # id: GuildId(2),
+ /// # icon: None,
+ /// # name: "baz".to_owned(),
+ /// # splash_hash: None,
+ /// # },
+ /// # inviter: User {
+ /// # avatar: None,
+ /// # bot: false,
+ /// # discriminator: 3,
+ /// # id: UserId(4),
+ /// # name: "qux".to_owned(),
+ /// # },
+ /// # max_age: 5,
+ /// # max_uses: 6,
+ /// # temporary: true,
+ /// # uses: 7,
+ /// # };
+ /// #
+ /// assert_eq!(invite.url(), "https://discord.gg/WxZumR");
+ /// ```
+ pub fn url(&self) -> String {
+ format!("https://discord.gg/{}", self.code)
+ }
}