aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-04-13 20:45:56 -0700
committerZeyla Hellyer <[email protected]>2017-04-19 14:53:32 -0700
commit3f03f9adc97315bb61a5c71f52365306cb8e2d1a (patch)
tree8fe0b518d1450b0657cfb75f56251fd90120807e /src/model/guild
parentUpdate the way errors are handled in dispatch (diff)
downloadserenity-3f03f9adc97315bb61a5c71f52365306cb8e2d1a.tar.xz
serenity-3f03f9adc97315bb61a5c71f52365306cb8e2d1a.zip
Deprecate methods prefixed with `get_`
A lot of structs - such as `Guild` or `ChannelId` - have methods with prefixes of `get_`, which are generally discouraged. To fix this, deprecate them and remove them in v0.3.0.
Diffstat (limited to 'src/model/guild')
-rw-r--r--src/model/guild/guild_id.rs261
-rw-r--r--src/model/guild/mod.rs306
-rw-r--r--src/model/guild/partial_guild.rs245
3 files changed, 543 insertions, 269 deletions
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index e5a0686..f219659 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -50,6 +50,29 @@ impl GuildId {
rest::ban_user(self.0, user.into().0, delete_message_days)
}
+ /// Gets a list of the guild's bans.
+ ///
+ /// Requires the [Ban Members] permission.
+ ///
+ /// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[inline]
+ pub fn bans(&self) -> Result<Vec<Ban>> {
+ rest::get_bans(self.0)
+ }
+
+ /// Gets all of the guild's channels over the REST API.
+ ///
+ /// [`Guild`]: struct.Guild.html
+ pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ let mut channels = HashMap::new();
+
+ for channel in rest::get_channels(self.0)? {
+ channels.insert(channel.id, channel);
+ }
+
+ Ok(channels)
+ }
+
/// Creates a [`GuildChannel`] in the the guild.
///
/// Refer to [`rest::create_channel`] for more information.
@@ -267,51 +290,13 @@ impl GuildId {
rest::edit_role(self.0, role_id.into().0, &f(EditRole::default()).0)
}
- /// Search the cache for the guild.
- #[cfg(feature="cache")]
- pub fn find(&self) -> Option<Arc<RwLock<Guild>>> {
- CACHE.read().unwrap().get_guild(*self)
- }
-
- /// Requests the guild over REST.
- ///
- /// Note that this will not be a complete guild, as REST does not send
- /// all data with a guild retrieval.
- #[inline]
- pub fn get(&self) -> Result<PartialGuild> {
- rest::get_guild(self.0)
- }
-
- /// Gets a list of the guild's bans.
- ///
- /// Requires the [Ban Members] permission.
- ///
- /// [Ban Members]: permissions/constant.BAN_MEMBERS.html
- #[inline]
- pub fn get_bans(&self) -> Result<Vec<Ban>> {
- rest::get_bans(self.0)
- }
-
- /// Gets all of the guild's channels over the REST API.
- ///
- /// [`Guild`]: struct.Guild.html
- pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
- let mut channels = HashMap::new();
-
- for channel in rest::get_channels(self.0)? {
- channels.insert(channel.id, channel);
- }
-
- Ok(channels)
- }
-
/// Gets an emoji in the guild by Id.
///
/// Requires the [Manage Emojis] permission.
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
rest::get_emoji(self.0, emoji_id.into().0)
}
@@ -321,15 +306,30 @@ impl GuildId {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
+ pub fn emojis(&self) -> Result<Vec<Emoji>> {
rest::get_emojis(self.0)
}
+ /// Search the cache for the guild.
+ #[cfg(feature="cache")]
+ pub fn find(&self) -> Option<Arc<RwLock<Guild>>> {
+ CACHE.read().unwrap().guild(*self)
+ }
+
+ /// Requests the guild over REST.
+ ///
+ /// Note that this will not be a complete guild, as REST does not send
+ /// all data with a guild retrieval.
+ #[inline]
+ pub fn get(&self) -> Result<PartialGuild> {
+ rest::get_guild(self.0)
+ }
+
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn get_integrations(&self) -> Result<Vec<Integration>> {
+ pub fn integrations(&self) -> Result<Vec<Integration>> {
rest::get_guild_integrations(self.0)
}
@@ -339,16 +339,33 @@ impl GuildId {
///
/// [Manage Guild]: permissions/struct.MANAGE_GUILD.html
#[inline]
- pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
+ pub fn invites(&self) -> Result<Vec<RichInvite>> {
rest::get_guild_invites(self.0)
}
+ /// Kicks a [`Member`] from the guild.
+ ///
+ /// Requires the [Kick Members] permission.
+ ///
+ /// [`Member`]: struct.Member.html
+ /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
+ #[inline]
+ pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
+ rest::kick_member(self.0, user_id.into().0)
+ }
+
+ /// Leaves the guild.
+ #[inline]
+ pub fn leave(&self) -> Result<PartialGuild> {
+ rest::leave_guild(self.0)
+ }
+
/// Gets a user's [`Member`] for the guild by Id.
///
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
#[inline]
- pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
rest::get_member(self.0, user_id.into().0)
}
@@ -360,11 +377,24 @@ impl GuildId {
///
/// [`User`]: struct.User.html
#[inline]
- pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
-> Result<Vec<Member>> where U: Into<UserId> {
rest::get_guild_members(self.0, limit, after.map(|x| x.into().0))
}
+ /// Moves a member to a specific voice channel.
+ ///
+ /// Requires the [Move Members] permission.
+ ///
+ /// [Move Members]: permissions/constant.MOVE_MEMBERS.html
+ pub fn move_member<C, U>(&self, user_id: U, channel_id: C)
+ -> Result<()> where C: Into<ChannelId>, U: Into<UserId> {
+ let mut map = Map::new();
+ map.insert("channel_id".to_owned(), Value::Number(Number::from(channel_id.into().0)));
+
+ rest::edit_member(self.0, user_id.into().0, &map)
+ }
+
/// Gets the number of [`Member`]s that would be pruned with the given
/// number of days.
///
@@ -372,7 +402,7 @@ impl GuildId {
///
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
- pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
+ pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
let map = json!({
"days": days,
});
@@ -380,46 +410,6 @@ impl GuildId {
rest::get_guild_prune_count(self.0, &map)
}
- /// Retrieves the guild's webhooks.
- ///
- /// **Note**: Requires the [Manage Webhooks] permission.
- ///
- /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
- #[inline]
- pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
- rest::get_guild_webhooks(self.0)
- }
-
- /// Kicks a [`Member`] from the guild.
- ///
- /// Requires the [Kick Members] permission.
- ///
- /// [`Member`]: struct.Member.html
- /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
- #[inline]
- pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- rest::kick_member(self.0, user_id.into().0)
- }
-
- /// Leaves the guild.
- #[inline]
- pub fn leave(&self) -> Result<PartialGuild> {
- rest::leave_guild(self.0)
- }
-
- /// Moves a member to a specific voice channel.
- ///
- /// Requires the [Move Members] permission.
- ///
- /// [Move Members]: permissions/constant.MOVE_MEMBERS.html
- pub fn move_member<C, U>(&self, user_id: U, channel_id: C)
- -> Result<()> where C: Into<ChannelId>, U: Into<UserId> {
- let mut map = Map::new();
- map.insert("channel_id".to_owned(), Value::Number(Number::from(channel_id.into().0)));
-
- rest::edit_member(self.0, user_id.into().0, &map)
- }
-
/// Returns the Id of the shard associated with the guild.
///
/// When the cache is enabled this will automatically retrieve the total
@@ -501,6 +491,107 @@ impl GuildId {
pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
rest::remove_ban(self.0, user_id.into().0)
}
+
+ /// Retrieves the guild's webhooks.
+ ///
+ /// **Note**: Requires the [Manage Webhooks] permission.
+ ///
+ /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[inline]
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> {
+ rest::get_guild_webhooks(self.0)
+ }
+
+ /// Alias of [`bans`].
+ ///
+ /// [`bans`]: #method.bans
+ #[deprecated(since="0.1.5", note="Use `bans` instead.")]
+ #[inline]
+ pub fn get_bans(&self) -> Result<Vec<Ban>> {
+ self.bans()
+ }
+
+ /// Alias of [`channels`].
+ ///
+ /// [`channels`]: #method.channels
+ #[deprecated(since="0.1.5", note="Use `channels` instead.")]
+ #[inline]
+ pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ self.channels()
+ }
+
+ /// Alias of [`emoji`].
+ ///
+ /// [`emoji`]: #method.emoji
+ #[deprecated(since="0.1.5", note="Use `emoji` instead.")]
+ #[inline]
+ pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ self.emoji(emoji_id)
+ }
+
+ /// Alias of [`emojis`].
+ ///
+ /// [`emojis`]: #method.emojis
+ #[deprecated(since="0.1.5", note="Use `emojis` instead.")]
+ #[inline]
+ pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
+ self.emojis()
+ }
+
+ /// Alias of [`integrations`].
+ ///
+ /// [`integrations`]: #method.integrations
+ #[deprecated(since="0.1.5", note="Use `integrations` instead.")]
+ #[inline]
+ pub fn get_integrations(&self) -> Result<Vec<Integration>> {
+ self.integrations()
+ }
+
+ /// Alias of [`invites`].
+ ///
+ /// [`invites`]: #method.invites
+ #[deprecated(since="0.1.5", note="Use `invites` instead.")]
+ #[inline]
+ pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
+ self.invites()
+ }
+
+ /// Alias of [`member`].
+ ///
+ /// [`member`]: #method.member
+ #[deprecated(since="0.1.5", note="Use `member` instead.")]
+ #[inline]
+ pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ self.member(user_id)
+ }
+
+ /// Alias of [`members`].
+ ///
+ /// [`members`]: #method.members
+ #[deprecated(since="0.1.5", note="Use `members` instead.")]
+ #[inline]
+ pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ -> Result<Vec<Member>> where U: Into<UserId> {
+ self.members(limit, after)
+ }
+
+ /// Alias of [`prune_count`].
+ ///
+ /// [`prune_count`]: #method.prune_count
+ #[deprecated(since="0.1.5", note="Use `prune_count` instead.")]
+ #[inline]
+ pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
+ self.prune_count(days)
+ }
+
+ /// Alias of [`webhooks`].
+ ///
+ /// [`webhooks`]: #method.webhooks
+ #[deprecated(since="0.1.5", note="Use `webhooks` instead.")]
+ #[inline]
+ pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
+ self.webhooks()
+ }
}
impl Display for GuildId {
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index bbf8ecc..c270fe2 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -201,7 +201,15 @@ impl Guild {
}
}
- self.id.get_bans()
+ self.id.bans()
+ }
+
+ /// Gets all of the guild's channels over the REST API.
+ ///
+ /// [`Guild`]: struct.Guild.html
+ #[inline]
+ pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ self.id.channels()
}
/// Creates a guild with the data provided.
@@ -548,38 +556,14 @@ impl Guild {
self.id.edit_role(role_id, f)
}
- /// Gets a partial amount of guild data by its Id.
- ///
- /// Requires that the current user be in the guild.
- #[inline]
- pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
- guild_id.into().get()
- }
-
- /// Gets a list of the guild's bans.
- ///
- /// Requires the [Ban Members] permission.
- #[inline]
- pub fn get_bans(&self) -> Result<Vec<Ban>> {
- self.id.get_bans()
- }
-
- /// Gets all of the guild's channels over the REST API.
- ///
- /// [`Guild`]: struct.Guild.html
- #[inline]
- pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
- self.id.get_channels()
- }
-
/// Gets an emoji in the guild by Id.
///
/// Requires the [Manage Emojis] permission.
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
- self.id.get_emoji(emoji_id)
+ pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ self.id.emoji(emoji_id)
}
/// Gets a list of all of the guild's emojis.
@@ -588,16 +572,30 @@ impl Guild {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
- self.id.get_emojis()
+ pub fn emojis(&self) -> Result<Vec<Emoji>> {
+ self.id.emojis()
+ }
+
+ /// Gets a partial amount of guild data by its Id.
+ ///
+ /// Requires that the current user be in the guild.
+ #[inline]
+ pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
+ guild_id.into().get()
+ }
+
+ /// Returns the formatted URL of the guild's icon, if one exists.
+ pub fn icon_url(&self) -> Option<String> {
+ self.icon.as_ref().map(|icon|
+ format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn get_integrations(&self) -> Result<Vec<Integration>> {
- self.id.get_integrations()
+ pub fn integrations(&self) -> Result<Vec<Integration>> {
+ self.id.integrations()
}
/// Retrieves the active invites for the guild.
@@ -611,7 +609,7 @@ impl Guild {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
- pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
+ pub fn invites(&self) -> Result<Vec<RichInvite>> {
#[cfg(feature="cache")]
{
let req = permissions::MANAGE_GUILD;
@@ -621,7 +619,31 @@ impl Guild {
}
}
- self.id.get_invites()
+ self.id.invites()
+ }
+
+ /// Checks if the guild is 'large'. A guild is considered large if it has
+ /// more than 250 members.
+ #[inline]
+ pub fn is_large(&self) -> bool {
+ self.members.len() > LARGE_THRESHOLD as usize
+ }
+
+ /// Kicks a [`Member`] from the guild.
+ ///
+ /// Requires the [Kick Members] permission.
+ ///
+ /// [`Member`]: struct.Member.html
+ /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
+ #[inline]
+ pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
+ self.id.kick(user_id)
+ }
+
+ /// Leaves the guild.
+ #[inline]
+ pub fn leave(&self) -> Result<PartialGuild> {
+ self.id.leave()
}
/// Gets a user's [`Member`] for the guild by Id.
@@ -629,8 +651,8 @@ impl Guild {
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
#[inline]
- pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
- self.id.get_member(user_id)
+ pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ self.id.member(user_id)
}
/// Gets a list of the guild's members.
@@ -641,9 +663,9 @@ impl Guild {
///
/// [`User`]: struct.User.html
#[inline]
- pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
-> Result<Vec<Member>> where U: Into<UserId> {
- self.id.get_members(limit, after)
+ self.id.members(limit, after)
}
/// Retrieves the first [`Member`] found that matches the name - with an
@@ -663,7 +685,7 @@ impl Guild {
/// - **nickname**: "zeyla" or "zeylas#nick"
///
/// [`Member`]: struct.Member.html
- pub fn get_member_named(&self, name: &str) -> Option<&Member> {
+ pub fn member_named(&self, name: &str) -> Option<&Member> {
let hash_pos = name.find('#');
let (name, discrim) = if let Some(pos) = hash_pos {
@@ -689,75 +711,6 @@ impl Guild {
}))
}
- /// Retrieves the count of the number of [`Member`]s that would be pruned
- /// with the number of given days.
- ///
- /// See the documentation on [`GuildPrune`] for more information.
- ///
- /// **Note**: Requires the [Kick Members] permission.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a [`ClientError::InvalidPermissions`]
- /// if the current user does not have permission to perform bans.
- ///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
- /// [`GuildPrune`]: struct.GuildPrune.html
- /// [`Member`]: struct.Member.html
- /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
- pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
- #[cfg(feature="cache")]
- {
- let req = permissions::KICK_MEMBERS;
-
- if !self.has_perms(req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
- }
- }
-
- self.id.get_prune_count(days)
- }
-
- /// Retrieves the guild's webhooks.
- ///
- /// **Note**: Requires the [Manage Webhooks] permission.
- ///
- /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
- #[inline]
- pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
- self.id.get_webhooks()
- }
-
- /// Returns the formatted URL of the guild's icon, if one exists.
- pub fn icon_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
- }
-
- /// Checks if the guild is 'large'. A guild is considered large if it has
- /// more than 250 members.
- #[inline]
- pub fn is_large(&self) -> bool {
- self.members.len() > LARGE_THRESHOLD as usize
- }
-
- /// Kicks a [`Member`] from the guild.
- ///
- /// Requires the [Kick Members] permission.
- ///
- /// [`Member`]: struct.Member.html
- /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
- #[inline]
- pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- self.id.kick(user_id)
- }
-
- /// Leaves the guild.
- #[inline]
- pub fn leave(&self) -> Result<PartialGuild> {
- self.id.leave()
- }
-
/// Moves a member to a specific voice channel.
///
/// Requires the [Move Members] permission.
@@ -887,6 +840,35 @@ impl Guild {
permissions
}
+ /// Retrieves the count of the number of [`Member`]s that would be pruned
+ /// with the number of given days.
+ ///
+ /// See the documentation on [`GuildPrune`] for more information.
+ ///
+ /// **Note**: Requires the [Kick Members] permission.
+ ///
+ /// # Errors
+ ///
+ /// If the `cache` is enabled, returns a [`ClientError::InvalidPermissions`]
+ /// if the current user does not have permission to perform bans.
+ ///
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`GuildPrune`]: struct.GuildPrune.html
+ /// [`Member`]: struct.Member.html
+ /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
+ pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
+ #[cfg(feature="cache")]
+ {
+ let req = permissions::KICK_MEMBERS;
+
+ if !self.has_perms(req)? {
+ return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ }
+ }
+
+ self.id.prune_count(days)
+ }
+
/// Returns the Id of the shard associated with the guild.
///
/// When the cache is enabled this will automatically retrieve the total
@@ -997,6 +979,116 @@ impl Guild {
self.id.unban(user_id)
}
+
+ /// Retrieves the guild's webhooks.
+ ///
+ /// **Note**: Requires the [Manage Webhooks] permission.
+ ///
+ /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[inline]
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> {
+ self.id.webhooks()
+ }
+
+ /// Alias of [`bans`].
+ ///
+ /// [`bans`]: #method.bans
+ #[deprecated(since="0.1.5", note="Use `bans` instead.")]
+ #[inline]
+ pub fn get_bans(&self) -> Result<Vec<Ban>> {
+ self.bans()
+ }
+
+ /// Alias of [`channels`].
+ ///
+ /// [`channels`]: #method.channels
+ #[deprecated(since="0.1.5", note="Use `channels` instead.")]
+ #[inline]
+ pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ self.channels()
+ }
+
+ /// Alias of [`emoji`].
+ ///
+ /// [`emoji`]: #method.emoji
+ #[deprecated(since="0.1.5", note="Use `emoji` instead.")]
+ #[inline]
+ pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ self.emoji(emoji_id)
+ }
+
+ /// Alias of [`emojis`].
+ ///
+ /// [`emojis`]: #method.emojis
+ #[deprecated(since="0.1.5", note="Use `emojis` instead.")]
+ #[inline]
+ pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
+ self.emojis()
+ }
+
+ /// Alias of [`integrations`].
+ ///
+ /// [`integrations`]: #method.integrations
+ #[deprecated(since="0.1.5", note="Use `integrations` instead.")]
+ #[inline]
+ pub fn get_integrations(&self) -> Result<Vec<Integration>> {
+ self.integrations()
+ }
+
+ /// Alias of [`invites`].
+ ///
+ /// [`invites`]: #method.invites
+ #[deprecated(since="0.1.5", note="Use `invites` instead.")]
+ #[inline]
+ pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
+ self.invites()
+ }
+
+ /// Alias of [`member`].
+ ///
+ /// [`member`]: #method.member
+ #[deprecated(since="0.1.5", note="Use `member` instead.")]
+ #[inline]
+ pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ self.member(user_id)
+ }
+
+ /// Alias of [`members`].
+ ///
+ /// [`members`]: #method.members
+ #[deprecated(since="0.1.5", note="Use `members` instead.")]
+ #[inline]
+ pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ -> Result<Vec<Member>> where U: Into<UserId> {
+ self.members(limit, after)
+ }
+
+ /// Alias of [`member_named`].
+ ///
+ /// [`member_named`]: #method.member_named
+ #[deprecated(since="0.1.5", note="Use `member_named` instead.")]
+ #[inline]
+ pub fn get_member_named(&self, name: &str) -> Option<&Member> {
+ self.member_named(name)
+ }
+
+ /// Alias of [`prune_count`].
+ ///
+ /// [`prune_count`]: #method.prune_count
+ #[deprecated(since="0.1.5", note="Use `prune_count` instead.")]
+ #[inline]
+ pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
+ self.prune_count(days)
+ }
+
+ /// Alias of [`webhooks`].
+ ///
+ /// [`webhooks`]: #method.webhooks
+ #[deprecated(since="0.1.5", note="Use `webhooks` instead.")]
+ #[inline]
+ pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
+ self.webhooks()
+ }
}
impl Deserialize for Guild {
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index b6d027a..2be0ae2 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -57,6 +57,24 @@ impl PartialGuild {
self.id.ban(user, delete_message_days)
}
+ /// Gets a list of the guild's bans.
+ ///
+ /// Requires the [Ban Members] permission.
+ ///
+ /// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[inline]
+ pub fn bans(&self) -> Result<Vec<Ban>> {
+ self.id.bans()
+ }
+
+ /// Gets all of the guild's channels over the REST API.
+ ///
+ /// [`Guild`]: struct.Guild.html
+ #[inline]
+ pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ self.id.channels()
+ }
+
/// Creates a [`GuildChannel`] in the guild.
///
/// Refer to [`rest::create_channel`] for more information.
@@ -264,58 +282,57 @@ impl PartialGuild {
self.id.edit_nickname(new_nickname)
}
- /// Gets a partial amount of guild data by its Id.
+ /// Gets an emoji in the guild by Id.
///
- /// Requires that the current user be in the guild.
+ /// Requires the [Manage Emojis] permission.
+ ///
+ /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
- guild_id.into().get()
+ pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ self.id.emoji(emoji_id)
}
- /// Gets a list of the guild's bans.
+ /// Gets a list of all of the guild's emojis.
///
- /// Requires the [Ban Members] permission.
+ /// Requires the [Manage Emojis] permission.
///
- /// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn get_bans(&self) -> Result<Vec<Ban>> {
- self.id.get_bans()
+ pub fn emojis(&self) -> Result<Vec<Emoji>> {
+ self.id.emojis()
}
- /// Gets all of the guild's channels over the REST API.
+ /// Gets a partial amount of guild data by its Id.
///
- /// [`Guild`]: struct.Guild.html
+ /// Requires that the current user be in the guild.
#[inline]
- pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
- self.id.get_channels()
+ pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
+ guild_id.into().get()
}
- /// Gets an emoji in the guild by Id.
+ /// Kicks a [`Member`] from the guild.
///
- /// Requires the [Manage Emojis] permission.
+ /// Requires the [Kick Members] permission.
///
- /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
+ /// [`Member`]: struct.Member.html
+ /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
#[inline]
- pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
- self.id.get_emoji(emoji_id)
+ pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
+ self.id.kick(user_id)
}
- /// Gets a list of all of the guild's emojis.
- ///
- /// Requires the [Manage Emojis] permission.
- ///
- /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
- #[inline]
- pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
- self.id.get_emojis()
+ /// Returns a formatted URL of the guild's icon, if the guild has an icon.
+ pub fn icon_url(&self) -> Option<String> {
+ self.icon.as_ref().map(|icon|
+ format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn get_integrations(&self) -> Result<Vec<Integration>> {
- self.id.get_integrations()
+ pub fn integrations(&self) -> Result<Vec<Integration>> {
+ self.id.integrations()
}
/// Gets all of the guild's invites.
@@ -324,16 +341,22 @@ impl PartialGuild {
///
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
- pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
- self.id.get_invites()
+ pub fn invites(&self) -> Result<Vec<RichInvite>> {
+ self.id.invites()
+ }
+
+ /// Leaves the guild.
+ #[inline]
+ pub fn leave(&self) -> Result<PartialGuild> {
+ self.id.leave()
}
/// Gets a user's [`Member`] for the guild by Id.
///
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
- pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
- self.id.get_member(user_id)
+ pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ self.id.member(user_id)
}
/// Gets a list of the guild's members.
@@ -343,65 +366,32 @@ impl PartialGuild {
/// [`User`]'s Id.
///
/// [`User`]: struct.User.html
- pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
-> Result<Vec<Member>> where U: Into<UserId> {
- self.id.get_members(limit, after)
- }
-
- /// Gets the number of [`Member`]s that would be pruned with the given
- /// number of days.
- ///
- /// Requires the [Kick Members] permission.
- ///
- /// [`Member`]: struct.Member.html
- /// [Kick Members]: permissions/constant.KICK_MEMBERS.html
- #[inline]
- pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
- self.id.get_prune_count(days)
+ self.id.members(limit, after)
}
- /// Retrieves the guild's webhooks.
+ /// Moves a member to a specific voice channel.
///
- /// **Note**: Requires the [Manage Webhooks] permission.
+ /// Requires the [Move Members] permission.
///
- /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ /// [Move Members]: permissions/constant.MOVE_MEMBERS.html
#[inline]
- pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
- self.id.get_webhooks()
+ pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()>
+ where C: Into<ChannelId>, U: Into<UserId> {
+ self.id.move_member(user_id, channel_id)
}
- /// Kicks a [`Member`] from the guild.
+ /// Gets the number of [`Member`]s that would be pruned with the given
+ /// number of days.
///
/// Requires the [Kick Members] permission.
///
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
#[inline]
- pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- self.id.kick(user_id)
- }
-
- /// Returns a formatted URL of the guild's icon, if the guild has an icon.
- pub fn icon_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
- }
-
- /// Leaves the guild.
- #[inline]
- pub fn leave(&self) -> Result<PartialGuild> {
- self.id.leave()
- }
-
- /// Moves a member to a specific voice channel.
- ///
- /// Requires the [Move Members] permission.
- ///
- /// [Move Members]: permissions/constant.MOVE_MEMBERS.html
- #[inline]
- pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()>
- where C: Into<ChannelId>, U: Into<UserId> {
- self.id.move_member(user_id, channel_id)
+ pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
+ self.id.prune_count(days)
}
/// Returns the Id of the shard associated with the guild.
@@ -472,4 +462,105 @@ impl PartialGuild {
pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
self.id.unban(user_id)
}
+
+ /// Retrieves the guild's webhooks.
+ ///
+ /// **Note**: Requires the [Manage Webhooks] permission.
+ ///
+ /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[inline]
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> {
+ self.id.webhooks()
+ }
+
+ /// Alias of [`bans`].
+ ///
+ /// [`bans`]: #method.bans
+ #[deprecated(since="0.1.5", note="Use `bans` instead.")]
+ #[inline]
+ pub fn get_bans(&self) -> Result<Vec<Ban>> {
+ self.bans()
+ }
+
+ /// Alias of [`channels`].
+ ///
+ /// [`channels`]: #method.channels
+ #[deprecated(since="0.1.5", note="Use `channels` instead.")]
+ #[inline]
+ pub fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
+ self.channels()
+ }
+
+ /// Alias of [`emoji`].
+ ///
+ /// [`emoji`]: #method.emoji
+ #[deprecated(since="0.1.5", note="Use `emoji` instead.")]
+ #[inline]
+ pub fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
+ self.emoji(emoji_id)
+ }
+
+ /// Alias of [`emojis`].
+ ///
+ /// [`emojis`]: #method.emojis
+ #[deprecated(since="0.1.5", note="Use `emojis` instead.")]
+ #[inline]
+ pub fn get_emojis(&self) -> Result<Vec<Emoji>> {
+ self.emojis()
+ }
+
+ /// Alias of [`integrations`].
+ ///
+ /// [`integrations`]: #method.integrations
+ #[deprecated(since="0.1.5", note="Use `integrations` instead.")]
+ #[inline]
+ pub fn get_integrations(&self) -> Result<Vec<Integration>> {
+ self.integrations()
+ }
+
+ /// Alias of [`invites`].
+ ///
+ /// [`invites`]: #method.invites
+ #[deprecated(since="0.1.5", note="Use `invites` instead.")]
+ #[inline]
+ pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
+ self.invites()
+ }
+
+ /// Alias of [`member`].
+ ///
+ /// [`member`]: #method.member
+ #[deprecated(since="0.1.5", note="Use `member` instead.")]
+ #[inline]
+ pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
+ self.member(user_id)
+ }
+
+ /// Alias of [`members`].
+ ///
+ /// [`members`]: #method.members
+ #[deprecated(since="0.1.5", note="Use `members` instead.")]
+ #[inline]
+ pub fn get_members<U>(&self, limit: Option<u64>, after: Option<U>)
+ -> Result<Vec<Member>> where U: Into<UserId> {
+ self.members(limit, after)
+ }
+
+ /// Alias of [`prune_count`].
+ ///
+ /// [`prune_count`]: #method.prune_count
+ #[deprecated(since="0.1.5", note="Use `prune_count` instead.")]
+ #[inline]
+ pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> {
+ self.prune_count(days)
+ }
+
+ /// Alias of [`webhooks`].
+ ///
+ /// [`webhooks`]: #method.webhooks
+ #[deprecated(since="0.1.5", note="Use `webhooks` instead.")]
+ #[inline]
+ pub fn get_webhooks(&self) -> Result<Vec<Webhook>> {
+ self.webhooks()
+ }
}