diff options
| author | Zeyla Hellyer <[email protected]> | 2017-04-13 20:45:56 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-04-19 14:53:32 -0700 |
| commit | 3f03f9adc97315bb61a5c71f52365306cb8e2d1a (patch) | |
| tree | 8fe0b518d1450b0657cfb75f56251fd90120807e /src | |
| parent | Update the way errors are handled in dispatch (diff) | |
| download | serenity-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')
| -rw-r--r-- | src/client/dispatch.rs | 6 | ||||
| -rw-r--r-- | src/client/rest/ratelimiting.rs | 12 | ||||
| -rw-r--r-- | src/ext/cache/mod.rs | 84 | ||||
| -rw-r--r-- | src/ext/voice/connection.rs | 4 | ||||
| -rw-r--r-- | src/model/channel/channel_id.rs | 115 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 109 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 137 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 20 | ||||
| -rw-r--r-- | src/model/channel/mod.rs | 53 | ||||
| -rw-r--r-- | src/model/channel/private_channel.rs | 53 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 261 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 306 | ||||
| -rw-r--r-- | src/model/guild/partial_guild.rs | 245 | ||||
| -rw-r--r-- | src/model/user.rs | 2 | ||||
| -rw-r--r-- | src/model/utils.rs | 8 | ||||
| -rw-r--r-- | src/utils/colour.rs | 88 |
16 files changed, 1043 insertions, 460 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index b4b0302..45ac378 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -178,9 +178,7 @@ fn handle_event(event: Event, let context = context(Some(event.channel.id()), conn, data); feature_cache! {{ - let before = CACHE.read() - .unwrap() - .get_channel(event.channel.id()); + let before = CACHE.read().unwrap().channel(event.channel.id()); update!(update_with_channel_update, event); thread::spawn(move || (handler)(context, before, event.channel)); @@ -287,7 +285,7 @@ fn handle_event(event: Event, // that this could fail under any circumstance. let after = CACHE.read() .unwrap() - .get_member(event.guild_id, event.user.id) + .member(event.guild_id, event.user.id) .unwrap() .clone(); diff --git a/src/client/rest/ratelimiting.rs b/src/client/rest/ratelimiting.rs index c8849eb..d336e37 100644 --- a/src/client/rest/ratelimiting.rs +++ b/src/client/rest/ratelimiting.rs @@ -383,7 +383,7 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response> let redo = if response.headers.get_raw("x-ratelimit-global").is_some() { let _ = GLOBAL.lock().expect("global route lock poisoned"); - Ok(if let Some(retry_after) = get_header(&response.headers, "retry-after")? { + Ok(if let Some(retry_after) = parse_header(&response.headers, "retry-after")? { debug!("Ratelimited: {:?}ms", retry_after); thread::sleep(Duration::from_millis(retry_after as u64)); @@ -463,21 +463,21 @@ impl RateLimit { #[doc(hidden)] pub fn post_hook(&mut self, response: &Response) -> Result<bool> { - if let Some(limit) = get_header(&response.headers, "x-ratelimit-limit")? { + if let Some(limit) = parse_header(&response.headers, "x-ratelimit-limit")? { self.limit = limit; } - if let Some(remaining) = get_header(&response.headers, "x-ratelimit-remaining")? { + if let Some(remaining) = parse_header(&response.headers, "x-ratelimit-remaining")? { self.remaining = remaining; } - if let Some(reset) = get_header(&response.headers, "x-ratelimit-reset")? { + if let Some(reset) = parse_header(&response.headers, "x-ratelimit-reset")? { self.reset = reset; } Ok(if response.status != StatusCode::TooManyRequests { false - } else if let Some(retry_after) = get_header(&response.headers, "retry-after")? { + } else if let Some(retry_after) = parse_header(&response.headers, "retry-after")? { debug!("Ratelimited: {:?}ms", retry_after); thread::sleep(Duration::from_millis(retry_after as u64)); @@ -488,7 +488,7 @@ impl RateLimit { } } -fn get_header(headers: &Headers, header: &str) -> Result<Option<i64>> { +fn parse_header(headers: &Headers, header: &str) -> Result<Option<i64>> { match headers.get_raw(header) { Some(header) => match str::from_utf8(&header[0]) { Ok(v) => match v.parse::<i64>() { diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs index d3479da..59863aa 100644 --- a/src/ext/cache/mod.rs +++ b/src/ext/cache/mod.rs @@ -276,7 +276,7 @@ impl Cache { /// [`get_private_channel`]: #method.get_private_channel /// [`groups`]: #structfield.groups /// [`private_channels`]: #structfield.private_channels - pub fn get_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { + pub fn channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { let id = id.into(); if let Some(channel) = self.channels.get(&id) { @@ -301,7 +301,7 @@ impl Cache { /// /// [`GuildId`]: ../../model/struct.GuildId.html #[inline] - pub fn get_guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> { + pub fn guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> { self.guilds.get(&id.into()).cloned() } @@ -338,8 +338,7 @@ impl Cache { /// [`Guild`]: ../../model/struct.Guild.html /// [`get_channel`]: #method.get_channel #[inline] - pub fn get_guild_channel<C: Into<ChannelId>>(&self, id: C) - -> Option<Arc<RwLock<GuildChannel>>> { + pub fn guild_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<GuildChannel>>> { self.channels.get(&id.into()).cloned() } @@ -352,7 +351,7 @@ impl Cache { /// [`ChannelId`]: ../../model/struct.ChannelId.html /// [`Group`]: ../../model/struct.Group.html #[inline] - pub fn get_group<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<Group>>> { + pub fn group<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<Group>>> { self.groups.get(&id.into()).cloned() } @@ -401,7 +400,7 @@ impl Cache { /// [`Client::on_message`]: ../../client/struct.Client.html#method.on_message /// [`Guild`]: ../../model/struct.Guild.html /// [`members`]: ../../model/struct.Guild.html#structfield.members - pub fn get_member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member> + pub fn member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member> where G: Into<GuildId>, U: Into<UserId> { self.guilds .get(&guild_id.into()) @@ -414,7 +413,7 @@ impl Cache { /// The only advantage of this method is that you can pass in anything that /// is indirectly a [`ChannelId`]. #[inline] - pub fn get_private_channel<C: Into<ChannelId>>(&self, channel_id: C) + pub fn private_channel<C: Into<ChannelId>>(&self, channel_id: C) -> Option<Arc<RwLock<PrivateChannel>>> { self.private_channels.get(&channel_id.into()).cloned() } @@ -426,7 +425,7 @@ impl Cache { /// /// [`Guild`]: ../../model/struct.Guild.html /// [`roles`]: ../../model/struct.Guild.html#structfield.roles - pub fn get_role<G, R>(&self, guild_id: G, role_id: R) -> Option<Role> + pub fn role<G, R>(&self, guild_id: G, role_id: R) -> Option<Role> where G: Into<GuildId>, R: Into<RoleId> { self.guilds .get(&guild_id.into()) @@ -441,10 +440,77 @@ impl Cache { /// [`UserId`]: ../../model/struct.UserId.html /// [`users`]: #structfield.users #[inline] - pub fn get_user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> { + pub fn user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> { self.users.get(&user_id.into()).cloned() } + /// Alias of [`channel`]. + /// + /// [`channel`]: #method.channel + #[deprecated(since="0.1.5", note="Use `channel` instead.")] + #[inline] + pub fn get_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { + self.channel(id) + } + + /// Alias of [`guild`]. + /// + /// [`guild`]: #method.guild + #[deprecated(since="0.1.5", note="Use `guild` instead.")] + #[inline] + pub fn get_guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> { + self.guild(id) + } + + /// Alias of [`guild_channel`]. + /// + /// [`guild_channel`]: #method.guild_channel + #[deprecated(since="0.1.5", note="Use `guild_channel` instead.")] + #[inline] + pub fn get_guild_channel<C: Into<ChannelId>>(&self, id: C) + -> Option<Arc<RwLock<GuildChannel>>> { + self.guild_channel(id) + } + + /// Alias of [`member`]. + /// + /// [`member`]: #method.member + #[deprecated(since="0.1.5", note="Use `member` instead.")] + #[inline] + pub fn get_member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member> + where G: Into<GuildId>, U: Into<UserId> { + self.member(guild_id, user_id) + } + + /// Alias of [`private_channel`]. + /// + /// [`private_channel`]: #method.private_channel + #[deprecated(since="0.1.5", note="Use `private_channel` instead.")] + #[inline] + pub fn get_private_channel<C: Into<ChannelId>>(&self, id: C) + -> Option<Arc<RwLock<PrivateChannel>>> { + self.private_channel(id) + } + + /// Alias of [`role`]. + /// + /// [`role`]: #method.role + #[deprecated(since="0.1.5", note="Use `role` instead.")] + #[inline] + pub fn get_role<G, R>(&self, guild_id: G, role_id: R) -> Option<Role> + where G: Into<GuildId>, R: Into<RoleId> { + self.role(guild_id, role_id) + } + + /// Alias of [`user`]. + /// + /// [`user`]: #method.user + #[deprecated(since="0.1.5", note="Use `user` instead.")] + #[inline] + pub fn get_user<U: Into<UserId>>(&self, id: U) -> Option<Arc<RwLock<User>>> { + self.user(id) + } + #[doc(hidden)] pub fn update_with_channel_create(&mut self, event: &ChannelCreateEvent) -> Option<Channel> { match event.channel { diff --git a/src/ext/voice/connection.rs b/src/ext/voice/connection.rs index db254a4..698f469 100644 --- a/src/ext/voice/connection.rs +++ b/src/ext/voice/connection.rs @@ -137,7 +137,7 @@ impl Connection { sender.send_json(&payload::build_select_protocol(addr, port))?; } - let key = get_encryption_key(&mut receiver)?; + let key = encryption_key(&mut receiver)?; let thread_items = start_threads(receiver, &udp)?; @@ -388,7 +388,7 @@ fn generate_url(endpoint: &mut String) -> Result<WebsocketUrl> { } #[inline] -fn get_encryption_key(receiver: &mut WsReceiver<WebSocketStream>) +fn encryption_key(receiver: &mut WsReceiver<WebSocketStream>) -> Result<Key> { loop { match receiver.recv_json(VoiceEvent::decode)? { diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index f0834de..5b238b0 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -222,7 +222,7 @@ impl ChannelId { /// Search the cache for the channel with the Id. #[cfg(feature="cache")] pub fn find(&self) -> Option<Channel> { - CACHE.read().unwrap().get_channel(*self) + CACHE.read().unwrap().channel(*self) } /// Search the cache for the channel. If it can't be found, the channel is @@ -230,7 +230,7 @@ impl ChannelId { pub fn get(&self) -> Result<Channel> { #[cfg(feature="cache")] { - if let Some(channel) = CACHE.read().unwrap().get_channel(*self) { + if let Some(channel) = CACHE.read().unwrap().channel(*self) { return Ok(channel); } } @@ -243,7 +243,7 @@ impl ChannelId { /// Requires the [Manage Channels] permission. /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html #[inline] - pub fn get_invites(&self) -> Result<Vec<RichInvite>> { + pub fn invites(&self) -> Result<Vec<RichInvite>> { rest::get_channel_invites(self.0) } @@ -253,7 +253,7 @@ impl ChannelId { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { rest::get_message(self.0, message_id.into().0) } @@ -265,7 +265,7 @@ impl ChannelId { /// /// [`Channel::get_messages`]: enum.Channel.html#method.get_messages /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> where F: FnOnce(GetMessages) -> GetMessages { let mut map = f(GetMessages::default()).0; let mut query = format!("?limit={}", map.remove("limit").unwrap_or(50)); @@ -281,6 +281,22 @@ impl ChannelId { rest::get_messages(self.0, &query) } + /// Pins a [`Message`] to the channel. + /// + /// [`Message`]: struct.Message.html + #[inline] + pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { + rest::pin_message(self.0, message_id.into().0) + } + + /// Gets the list of [`Message`]s which are pinned to the channel. + /// + /// [`Message`]: struct.Message.html + #[inline] + pub fn pins(&self) -> Result<Vec<Message>> { + rest::get_pins(self.0) + } + /// Gets the list of [`User`]s who have reacted to a [`Message`] with a /// certain [`Emoji`]. /// @@ -293,7 +309,7 @@ impl ChannelId { /// [`Message`]: struct.Message.html /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - pub fn get_reaction_users<M, R, U>(&self, + pub fn reaction_users<M, R, U>(&self, message_id: M, reaction_type: R, limit: Option<u8>, @@ -308,32 +324,6 @@ impl ChannelId { after.map(|u| u.into().0)) } - /// Retrieves the channel'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_channel_webhooks(self.0) - } - - /// Pins a [`Message`] to the channel. - /// - /// [`Message`]: struct.Message.html - #[inline] - pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - rest::pin_message(self.0, message_id.into().0) - } - - /// Gets the list of [`Message`]s which are pinned to the channel. - /// - /// [`Message`]: struct.Message.html - #[inline] - pub fn pins(&self) -> Result<Vec<Message>> { - rest::get_pins(self.0) - } - /// Sends a message with just the given message content in the channel. /// /// # Errors @@ -449,6 +439,67 @@ impl ChannelId { pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { rest::unpin_message(self.0, message_id.into().0) } + + /// Retrieves the channel'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_channel_webhooks(self.0) + } + + /// 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 [`message`]. + /// + /// [`message`]: #method.message + #[deprecated(since="0.1.5", note="Use `message` instead.")] + #[inline] + pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.message(message_id) + } + + /// Alias of [`messages`]. + /// + /// [`messages`]: #method.messages + #[deprecated(since="0.1.5", note="Use `messages` instead.")] + #[inline] + pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + where F: FnOnce(GetMessages) -> GetMessages { + self.messages(f) + } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(message_id, reaction_type, limit, after) + } + + /// 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 From<Channel> for ChannelId { diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index 21e9606..b85bc7d 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -143,14 +143,26 @@ impl Group { self.channel_id.edit_message(message_id, f) } + /// Returns the formatted URI of the group's icon if one exists. + pub fn icon_url(&self) -> Option<String> { + self.icon.as_ref().map(|icon| + format!(cdn!("/channel-icons/{}/{}.webp"), self.channel_id, icon)) + } + + /// Leaves the group. + #[inline] + pub fn leave(&self) -> Result<Group> { + rest::leave_group(self.channel_id.0) + } + /// Gets a message from the channel. /// /// Requires the [Read Message History] permission. /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - self.channel_id.get_message(message_id) + pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.channel_id.message(message_id) } /// Gets messages from the channel. @@ -159,43 +171,9 @@ impl Group { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> where F: FnOnce(GetMessages) -> GetMessages { - self.channel_id.get_messages(f) - } - - /// Gets the list of [`User`]s who have reacted to a [`Message`] with a - /// certain [`Emoji`]. - /// - /// Refer to [`Channel::get_reaction_users`] for more information. - /// - /// **Note**: Requires the [Read Message History] permission. - /// - /// [`Channel::get_reaction_users`]: enum.Channel.html#variant.get_reaction_users - /// [`Emoji`]: struct.Emoji.html - /// [`Message`]: struct.Message.html - /// [`User`]: struct.User.html - /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - #[inline] - pub fn get_reaction_users<M, R, U>(&self, - message_id: M, - reaction_type: R, - limit: Option<u8>, - after: Option<U>) - -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.channel_id.get_reaction_users(message_id, reaction_type, limit, after) - } - - /// Returns the formatted URI of the group's icon if one exists. - pub fn icon_url(&self) -> Option<String> { - self.icon.as_ref().map(|icon| - format!(cdn!("/channel-icons/{}/{}.webp"), self.channel_id, icon)) - } - - /// Leaves the group. - #[inline] - pub fn leave(&self) -> Result<Group> { - rest::leave_group(self.channel_id.0) + self.channel_id.messages(f) } /// Generates a name for the group. @@ -227,6 +205,28 @@ impl Group { self.channel_id.pins() } + /// Gets the list of [`User`]s who have reacted to a [`Message`] with a + /// certain [`Emoji`]. + /// + /// Refer to [`Channel::get_reaction_users`] for more information. + /// + /// **Note**: Requires the [Read Message History] permission. + /// + /// [`Channel::get_reaction_users`]: enum.Channel.html#variant.get_reaction_users + /// [`Emoji`]: struct.Emoji.html + /// [`Message`]: struct.Message.html + /// [`User`]: struct.User.html + /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html + #[inline] + pub fn reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.channel_id.reaction_users(message_id, reaction_type, limit, after) + } + /// Removes a recipient from the group. If the recipient is already not in /// the group, then nothing is done. /// @@ -305,4 +305,37 @@ impl Group { pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.channel_id.unpin(message_id) } + + /// Alias of [`message`]. + /// + /// [`message`]: #method.message + #[deprecated(since="0.1.5", note="Use `message` instead.")] + #[inline] + pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.message(message_id) + } + + /// Alias of [`messages`]. + /// + /// [`messages`]: #method.messages + #[deprecated(since="0.1.5", note="Use `messages` instead.")] + #[inline] + pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + where F: FnOnce(GetMessages) -> GetMessages { + self.messages(f) + } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(message_id, reaction_type, limit, after) + } } diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index eaefb70..6cbdda0 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -301,13 +301,22 @@ impl GuildChannel { self.id.edit_message(message_id, f) } + /// Attempts to find this channel's guild in the Cache. + /// + /// **Note**: Right now this performs a clone of the guild. This will be + /// optimized in the future. + #[cfg(feature="cache")] + pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { + CACHE.read().unwrap().guild(self.guild_id) + } + /// Gets all of the channel's invites. /// /// Requires the [Manage Channels] permission. /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html #[inline] - pub fn get_invites(&self) -> Result<Vec<RichInvite>> { - self.id.get_invites() + pub fn invites(&self) -> Result<Vec<RichInvite>> { + self.id.invites() } /// Gets a message from the channel. @@ -316,8 +325,8 @@ impl GuildChannel { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - self.id.get_message(message_id) + pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.id.message(message_id) } /// Gets messages from the channel. @@ -329,9 +338,21 @@ impl GuildChannel { /// [`Channel::get_messages`]: enum.Channel.html#method.get_messages /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> where F: FnOnce(GetMessages) -> GetMessages { - self.id.get_messages(f) + self.id.messages(f) + } + + /// Pins a [`Message`] to the channel. + #[inline] + pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { + self.id.pin(message_id) + } + + /// Gets all channel's pins. + #[inline] + pub fn pins(&self) -> Result<Vec<Message>> { + self.id.pins() } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a @@ -346,44 +367,13 @@ impl GuildChannel { /// [`Message`]: struct.Message.html /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - pub fn get_reaction_users<M, R, U>(&self, - message_id: M, - reaction_type: R, - limit: Option<u8>, - after: Option<U>) + pub fn reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id.get_reaction_users(message_id, reaction_type, limit, after) - } - - /// Retrieves the channel'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() - } - - /// Attempts to find this channel's guild in the Cache. - /// - /// **Note**: Right now this performs a clone of the guild. This will be - /// optimized in the future. - #[cfg(feature="cache")] - pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { - CACHE.read().unwrap().get_guild(self.guild_id) - } - - /// Pins a [`Message`] to the channel. - #[inline] - pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - self.id.pin(message_id) - } - - /// Gets all channel's pins. - #[inline] - pub fn pins(&self) -> Result<Vec<Message>> { - self.id.pins() + self.id.reaction_users(message_id, reaction_type, limit, after) } /// Sends a message with just the given message content in the channel. @@ -467,6 +457,67 @@ impl GuildChannel { pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.id.unpin(message_id) } + + /// Retrieves the channel'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 [`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 [`message`]. + /// + /// [`message`]: #method.message + #[deprecated(since="0.1.5", note="Use `message` instead.")] + #[inline] + pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.message(message_id) + } + + /// Alias of [`messages`]. + /// + /// [`messages`]: #method.messages + #[deprecated(since="0.1.5", note="Use `messages` instead.")] + #[inline] + pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + where F: FnOnce(GetMessages) -> GetMessages { + self.messages(f) + } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(message_id, reaction_type, limit, after) + } + + /// 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 GuildChannel { diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index f572aea..6bbb1a2 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -236,9 +236,9 @@ impl Message { /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_reaction_users<R, U>(&self, reaction_type: R, limit: Option<u8>, after: Option<U>) + pub fn reaction_users<R, U>(&self, reaction_type: R, limit: Option<u8>, after: Option<U>) -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { - self.channel_id.get_reaction_users(self.id, reaction_type, limit, after) + self.channel_id.reaction_users(self.id, reaction_type, limit, after) } /// Returns the associated `Guild` for the message if one is in the cache. @@ -251,7 +251,7 @@ impl Message { /// [`guild_id`]: #method.guild_id #[cfg(feature="cache")] pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { - self.guild_id().and_then(|guild_id| CACHE.read().unwrap().get_guild(guild_id)) + self.guild_id().and_then(|guild_id| CACHE.read().unwrap().guild(guild_id)) } /// Retrieves the Id of the guild that the message was sent in, if sent in @@ -261,7 +261,7 @@ impl Message { /// cache. #[cfg(feature="cache")] pub fn guild_id(&self) -> Option<GuildId> { - match CACHE.read().unwrap().get_channel(self.channel_id) { + match CACHE.read().unwrap().channel(self.channel_id) { Some(Channel::Guild(ch)) => Some(ch.read().unwrap().guild_id), _ => None, } @@ -270,7 +270,7 @@ impl Message { /// True if message was sent using direct messages. #[cfg(feature="cache")] pub fn is_private(&self) -> bool { - match CACHE.read().unwrap().get_channel(self.channel_id) { + match CACHE.read().unwrap().channel(self.channel_id) { Some(Channel::Group(_)) | Some(Channel::Private(_)) => true, _ => false, } @@ -421,6 +421,16 @@ impl Message { rest::unpin_message(self.channel_id.0, self.id.0) } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<R, U>(&self, reaction_type: R, limit: Option<u8>, after: Option<U>) + -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(reaction_type, limit, after) + } } impl From<Message> for MessageId { diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 4877785..2ad06cf 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -170,8 +170,8 @@ impl Channel { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - self.id().get_message(message_id) + pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.id().message(message_id) } /// Gets messages from the channel. @@ -191,9 +191,9 @@ impl Channel { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> where F: FnOnce(GetMessages) -> GetMessages { - self.id().get_messages(f) + self.id().messages(f) } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a @@ -213,13 +213,13 @@ impl Channel { /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_reaction_users<M, R, U>(&self, - message_id: M, - reaction_type: R, - limit: Option<u8>, - after: Option<U>) + pub fn reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id().get_reaction_users(message_id, reaction_type, limit, after) + self.id().reaction_users(message_id, reaction_type, limit, after) } /// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or @@ -310,6 +310,39 @@ impl Channel { pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.id().unpin(message_id) } + + /// Alias of [`message`]. + /// + /// [`message`]: #method.message + #[deprecated(since="0.1.5", note="Use `message` instead.")] + #[inline] + pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.message(message_id) + } + + /// Alias of [`messages`]. + /// + /// [`messages`]: #method.messages + #[deprecated(since="0.1.5", note="Use `messages` instead.")] + #[inline] + pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + where F: FnOnce(GetMessages) -> GetMessages { + self.messages(f) + } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(message_id, reaction_type, limit, after) + } } impl Deserialize for Channel { diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 802f84a..2ede408 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -134,8 +134,8 @@ impl PrivateChannel { /// /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - self.id.get_message(message_id) + pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.id.message(message_id) } /// Gets messages from the channel. @@ -147,9 +147,9 @@ impl PrivateChannel { /// [`Channel::get_messages`]: enum.Channel.html#method.get_messages /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> where F: FnOnce(GetMessages) -> GetMessages { - self.id.get_messages(f) + self.id.messages(f) } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a @@ -165,13 +165,13 @@ impl PrivateChannel { /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] - pub fn get_reaction_users<M, R, U>(&self, - message_id: M, - reaction_type: R, - limit: Option<u8>, - after: Option<U>) + pub fn reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id.get_reaction_users(message_id, reaction_type, limit, after) + self.id.reaction_users(message_id, reaction_type, limit, after) } /// Pins a [`Message`] to the channel. @@ -257,6 +257,39 @@ impl PrivateChannel { pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { self.id.unpin(message_id) } + + /// Alias of [`message`]. + /// + /// [`message`]: #method.message + #[deprecated(since="0.1.5", note="Use `message` instead.")] + #[inline] + pub fn get_message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { + self.message(message_id) + } + + /// Alias of [`messages`]. + /// + /// [`messages`]: #method.messages + #[deprecated(since="0.1.5", note="Use `messages` instead.")] + #[inline] + pub fn get_messages<F>(&self, f: F) -> Result<Vec<Message>> + where F: FnOnce(GetMessages) -> GetMessages { + self.messages(f) + } + + /// Alias of [`reaction_users`]. + /// + /// [`reaction_users`]: #method.reaction_users + #[deprecated(since="0.1.5", note="Use `reaction_users` instead.")] + #[inline] + pub fn get_reaction_users<M, R, U>(&self, + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + self.reaction_users(message_id, reaction_type, limit, after) + } } impl Display for PrivateChannel { 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() + } } diff --git a/src/model/user.rs b/src/model/user.rs index b38756a..8f7349c 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -594,7 +594,7 @@ impl UserId { /// Search the cache for the user with the Id. #[cfg(feature="cache")] pub fn find(&self) -> Option<Arc<RwLock<User>>> { - CACHE.read().unwrap().get_user(*self) + CACHE.read().unwrap().user(*self) } /// Gets a user by its Id over the REST API. diff --git a/src/model/utils.rs b/src/model/utils.rs index ab7a8fb..3af5e80 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -128,13 +128,11 @@ pub fn deserialize_voice_states<D: Deserializer>(deserializer: D) } #[cfg(feature="cache")] -pub fn user_has_perms(channel_id: ChannelId, - mut permissions: Permissions) - -> Result<bool> { +pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Result<bool> { let cache = CACHE.read().unwrap(); let current_user = &cache.user; - let channel = match cache.get_channel(channel_id) { + let channel = match cache.channel(channel_id) { Some(channel) => channel, None => return Err(Error::Client(ClientError::ItemMissing)), }; @@ -146,7 +144,7 @@ pub fn user_has_perms(channel_id: ChannelId, Channel::Guild(channel) => channel.read().unwrap().guild_id, }; - let guild = match cache.get_guild(guild_id) { + let guild = match cache.guild(guild_id) { Some(guild) => guild, None => return Err(Error::Client(ClientError::ItemMissing)), }; diff --git a/src/utils/colour.rs b/src/utils/colour.rs index 8687db0..dea6ff9 100644 --- a/src/utils/colour.rs +++ b/src/utils/colour.rs @@ -22,7 +22,7 @@ macro_rules! colour { /// # Examples /// /// Passing in a role's colour, and then retrieving its green component -/// via [`get_g`]: +/// via [`g`]: /// /// ```rust,ignore /// use serenity::utils::Colour; @@ -30,7 +30,7 @@ macro_rules! colour { /// // assuming a `role` has already been bound /// /// let colour = Colour::new(role.colour); -/// let green = colour.get_g(); +/// let green = colour.g(); /// /// println!("The green component is: {}", green); /// ``` @@ -42,7 +42,7 @@ macro_rules! colour { /// /// let colour = Colour::dark_teal(); /// -/// assert_eq!(colour.get_tuple(), (17, 128, 106)); +/// assert_eq!(colour.tuple(), (17, 128, 106)); /// ``` /// /// Colours can also be directly compared for equivilance: @@ -60,7 +60,7 @@ macro_rules! colour { /// /// [`Role`]: ../model/struct.Role.html /// [`dark_teal`]: #method.dark_teal -/// [`get_g`]: #method.get_g +/// [`g`]: #method.g #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub struct Colour(pub u32); @@ -70,17 +70,17 @@ impl Colour { /// # Examples /// /// Create a new Colour, and then ensure that its inner value is equivalent - /// to a specific RGB value, retrieved via [`get_tuple`]: + /// to a specific RGB value, retrieved via [`tuple`]: /// /// ```rust /// use serenity::utils::Colour; /// /// let colour = Colour::new(6573123); /// - /// assert_eq!(colour.get_tuple(), (100, 76, 67)); + /// assert_eq!(colour.tuple(), (100, 76, 67)); /// ``` /// - /// [`get_tuple`]: #method.get_tuple + /// [`tuple`]: #method.tuple #[inline] pub fn new(value: u32) -> Colour { Colour(value) @@ -107,10 +107,10 @@ impl Colour { /// /// let colour = Colour::from_rgb(217, 45, 215); /// - /// assert_eq!(colour.get_r(), 217); - /// assert_eq!(colour.get_g(), 45); - /// assert_eq!(colour.get_b(), 215); - /// assert_eq!(colour.get_tuple(), (217, 45, 215)); + /// assert_eq!(colour.r(), 217); + /// assert_eq!(colour.g(), 45); + /// assert_eq!(colour.b(), 215); + /// assert_eq!(colour.tuple(), (217, 45, 215)); /// ``` pub fn from_rgb(r: u8, g: u8, b: u8) -> Colour { let mut uint = r as u32; @@ -127,9 +127,9 @@ impl Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::new(6573123).get_r(), 100); + /// assert_eq!(Colour::new(6573123).r(), 100); /// ``` - pub fn get_r(&self) -> u8 { + pub fn r(&self) -> u8 { ((self.0 >> 16) & 255) as u8 } @@ -140,9 +140,9 @@ impl Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::new(6573123).get_g(), 76); + /// assert_eq!(Colour::new(6573123).g(), 76); /// ``` - pub fn get_g(&self) -> u8 { + pub fn g(&self) -> u8 { ((self.0 >> 8) & 255) as u8 } @@ -153,29 +153,65 @@ impl Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::new(6573123).get_b(), 67); - pub fn get_b(&self) -> u8 { + /// assert_eq!(Colour::new(6573123).b(), 67); + pub fn b(&self) -> u8 { (self.0 & 255) as u8 } /// Returns a tuple of the red, green, and blue components of this Colour. /// /// This is equivalent to creating a tuple with the return values of - /// [`get_r`], [`get_g`], and [`get_b`]. + /// [`r`], [`g`], and [`b`]. /// /// # Examples /// /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::new(6573123).get_tuple(), (100, 76, 67)); + /// assert_eq!(Colour::new(6573123).tuple(), (100, 76, 67)); /// ``` /// - /// [`get_r`]: #method.get_r - /// [`get_g`]: #method.get_g - /// [`get_b`]: #method.get_b + /// [`r`]: #method.r + /// [`g`]: #method.g + /// [`b`]: #method.b + pub fn tuple(&self) -> (u8, u8, u8) { + (self.r(), self.g(), self.b()) + } + + /// Alias of [`r`]. + /// + /// [`r`]: #method.r + #[deprecated(since="0.1.5", note="Use `r` instead.")] + #[inline] + pub fn get_r(&self) -> u8 { + self.r() + } + + /// Alias of [`g`]. + /// + /// [`g`]: #method.g + #[deprecated(since="0.1.5", note="Use `g` instead.")] + #[inline] + pub fn get_g(&self) -> u8 { + self.g() + } + + /// Alias of [`b`]. + /// + /// [`b`]: #method.b + #[deprecated(since="0.1.5", note="Use `b` instead.")] + #[inline] + pub fn get_b(&self) -> u8 { + self.b() + } + + /// Alias of [`tuple`]. + /// + /// [`tuple`]: #method.tuple + #[deprecated(since="0.1.5", note="Use `tuple` instead.")] + #[inline] pub fn get_tuple(&self) -> (u8, u8, u8) { - (self.get_r(), self.get_g(), self.get_b()) + self.tuple() } } @@ -191,7 +227,7 @@ impl From<i32> for Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::from(0xDEA584).get_tuple(), (222, 165, 132)); + /// assert_eq!(Colour::from(0xDEA584).tuple(), (222, 165, 132)); /// ``` fn from(value: i32) -> Colour { Colour(value as u32) @@ -208,7 +244,7 @@ impl From<u32> for Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::from(6573123u32).get_r(), 100); + /// assert_eq!(Colour::from(6573123u32).r(), 100); /// ``` fn from(value: u32) -> Colour { Colour(value) @@ -225,7 +261,7 @@ impl From<u64> for Colour { /// ```rust /// use serenity::utils::Colour; /// - /// assert_eq!(Colour::from(6573123u64).get_r(), 100); + /// assert_eq!(Colour::from(6573123u64).r(), 100); /// ``` fn from(value: u64) -> Colour { Colour(value as u32) |