diff options
| author | Austin Hellyer <[email protected]> | 2016-11-25 20:06:47 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-25 20:06:47 -0800 |
| commit | adde653dc4797faf8094816da46f8e4430b33c98 (patch) | |
| tree | 229acc0e3d130bb44d53f09fef0716f2c16915af /src | |
| parent | Fix permission check on Message::delete (diff) | |
| download | serenity-adde653dc4797faf8094816da46f8e4430b33c98.tar.xz serenity-adde653dc4797faf8094816da46f8e4430b33c98.zip | |
Rename PublicChannel to GuildChannel
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/context.rs | 20 | ||||
| -rw-r--r-- | src/client/rest/mod.rs | 24 | ||||
| -rw-r--r-- | src/ext/cache/mod.rs | 34 | ||||
| -rw-r--r-- | src/model/channel.rs | 34 | ||||
| -rw-r--r-- | src/model/gateway.rs | 4 | ||||
| -rw-r--r-- | src/model/guild.rs | 8 | ||||
| -rw-r--r-- | src/model/id.rs | 6 | ||||
| -rw-r--r-- | src/model/mod.rs | 8 | ||||
| -rw-r--r-- | src/model/permissions.rs | 2 | ||||
| -rw-r--r-- | src/model/utils.rs | 4 | ||||
| -rw-r--r-- | src/utils/builder/edit_channel.rs | 8 | ||||
| -rw-r--r-- | src/utils/message_builder.rs | 4 |
12 files changed, 78 insertions, 78 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index a4d893e..943741b 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -52,7 +52,7 @@ use super::CACHE; /// one. /// /// For example, if you are needing information about a -/// [channel][`PublicChannel`] within a [guild][`Guild`], then you can +/// [channel][`GuildChannel`] within a [guild][`Guild`], then you can /// use [`get_channel`] to retrieve it. Under most circumstances, the guild and /// its channels will be cached within the cache, and `get_channel` will just /// pull from the cache. If it does not exist, it will make a request to the @@ -67,7 +67,7 @@ use super::CACHE; /// [`Client::on_message`]: struct.Client.html#method.on_message /// [`Guild`]: ../model/struct.Guild.html /// [`Message`]: ../model/struct.Message.html -/// [`PublicChannel`]: ../model/struct.PublicChannel.html +/// [`GuildChannel`]: ../model/struct.GuildChannel.html /// [`Shard`]: gateway/struct.Shard.html /// [`Cache`]: ../ext/cache/struct.Cache.html /// [`get_channel`]: #method.get_channel @@ -207,7 +207,7 @@ impl Context { rest::broadcast_typing(channel_id.into().0) } - /// Creates a [`PublicChannel`] in the given [`Guild`]. + /// Creates a [`GuildChannel`] in the given [`Guild`]. /// /// Refer to [`rest::create_channel`] for more information. /// @@ -224,7 +224,7 @@ impl Context { /// ``` /// /// [`Guild`]: ../model/struct.Guild.html - /// [`PublicChannel`]: ../model/struct.PublicChannel.html + /// [`GuildChannel`]: ../model/struct.GuildChannel.html /// [`rest::create_channel`]: rest/fn.create_channel.html /// [Manage Channels]: ../model/permissions/constant.MANAGE_CHANNELS.html pub fn create_channel<G>(&self, guild_id: G, name: &str, kind: ChannelType) @@ -475,12 +475,12 @@ impl Context { /// Deletes a [`Channel`] based on the Id given. /// - /// If the channel being deleted is a [`PublicChannel`] (a [`Guild`]'s + /// If the channel being deleted is a [`GuildChannel`] (a [`Guild`]'s /// channel), then the [Manage Channels] permission is required. /// /// [`Channel`]: ../model/enum.Channel.html /// [`Guild`]: ../model/struct.Guild.html - /// [`PublicChannel`]: ../model/struct.PublicChannel.html + /// [`GuildChannel`]: ../model/struct.GuildChannel.html /// [Manage Messages]: ../model/permissions/constant.MANAGE_CHANNELS.html pub fn delete_channel<C>(&self, channel_id: C) -> Result<Channel> where C: Into<ChannelId> { @@ -673,12 +673,12 @@ impl Context { } pub fn edit_channel<C, F>(&self, channel_id: C, f: F) - -> Result<PublicChannel> where C: Into<ChannelId>, + -> Result<GuildChannel> where C: Into<ChannelId>, F: FnOnce(EditChannel) -> EditChannel { let channel_id = channel_id.into(); let map = match try!(self.get_channel(channel_id)) { - Channel::Public(channel) => { + Channel::Guild(channel) => { let map = ObjectBuilder::new() .insert("name", channel.name) .insert("position", channel.position); @@ -841,7 +841,7 @@ impl Context { } pub fn get_channels<G>(&self, guild_id: G) - -> Result<HashMap<ChannelId, PublicChannel>> where G: Into<GuildId> { + -> Result<HashMap<ChannelId, GuildChannel>> where G: Into<GuildId> { let guild_id = guild_id.into(); feature_cache_enabled! {{ @@ -1161,7 +1161,7 @@ impl Context { /// let cache = CACHE.read().unwrap(); /// let ch = cache.get_channel(message.channel_id); /// let name = match ch { - /// Some(Channel::Public(ch)) => ch.name.clone(), + /// Some(Channel::Guild(ch)) => ch.name.clone(), /// _ => "Unknown".to_owned(), /// }; /// diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs index 0558df8..5624ab7 100644 --- a/src/client/rest/mod.rs +++ b/src/client/rest/mod.rs @@ -192,14 +192,14 @@ pub fn broadcast_typing(channel_id: u64) -> Result<()> { channel_id)) } -/// Creates a [`PublicChannel`] in the [`Guild`] given its Id. +/// Creates a [`GuildChannel`] in the [`Guild`] given its Id. /// /// Refer to the Discord's [docs] for information on what fields this requires. /// /// **Note**: Requires the [Manage Channels] permission. /// /// [`Guild`]: ../../model/struct.Guild.html -/// [`PublicChannel`]: ../../model/struct.PublicChannel.html +/// [`GuildChannel`]: ../../model/struct.GuildChannel.html /// [docs]: https://discordapp.com/developers/docs/resources/guild#create-guild-channel /// [Manage Channels]: ../../model/permissions/constant.MANAGE_CHANNELS.html pub fn create_channel(guild_id: u64, map: Value) -> Result<Channel> { @@ -295,7 +295,7 @@ pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: Value) integration_id)) } -/// Creates a [`RichInvite`] for the given [channel][`PublicChannel`]. +/// Creates a [`RichInvite`] for the given [channel][`GuildChannel`]. /// /// Refer to Discord's [docs] for field information. /// @@ -303,7 +303,7 @@ pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: Value) /// /// **Note**: Requires the [Create Invite] permission. /// -/// [`PublicChannel`]: ../../model/struct.PublicChannel.html +/// [`GuildChannel`]: ../../model/struct.GuildChannel.html /// [`RichInvite`]: ../../model/struct.RichInvite.html /// [Create Invite]: ../../model/permissions/constant.CREATE_INVITE.html /// [docs]: https://discordapp.com/developers/docs/resources/channel#create-channel-invite @@ -361,7 +361,7 @@ pub fn create_role(guild_id: u64) -> Result<Role> { Role::decode(try!(serde_json::from_reader(response))) } -/// Creates a webhook for the given [channel][`PublicChannel`]'s Id, passing in +/// Creates a webhook for the given [channel][`GuildChannel`]'s Id, passing in /// the given data. /// /// This method requires authentication. @@ -390,7 +390,7 @@ pub fn create_role(guild_id: u64) -> Result<Role> { /// let webhook = rest::create_webhook(channel_id, map).expect("err creating"); /// ``` /// -/// [`PublicChannel`]: ../../model/struct.PublicChannel.html +/// [`GuildChannel`]: ../../model/struct.GuildChannel.html pub fn create_webhook(channel_id: u64, map: Value) -> Result<Webhook> { let body = try!(serde_json::to_string(&map)); let response = request!(Route::ChannelsIdWebhooks(channel_id), @@ -572,14 +572,14 @@ pub fn delete_webhook_with_token(webhook_id: u64, token: &str) -> Result<()> { } pub fn edit_channel(channel_id: u64, map: Value) - -> Result<PublicChannel> { + -> Result<GuildChannel> { let body = try!(serde_json::to_string(&map)); let response = request!(Route::ChannelsId(channel_id), patch(body), "/channels/{}", channel_id); - PublicChannel::decode(try!(serde_json::from_reader(response))) + GuildChannel::decode(try!(serde_json::from_reader(response))) } pub fn edit_emoji(guild_id: u64, emoji_id: u64, map: Value) @@ -862,7 +862,7 @@ pub fn get_channel_invites(channel_id: u64) RichInvite::decode) } -/// Retrieves the webhooks for the given [channel][`PublicChannel`]'s Id. +/// Retrieves the webhooks for the given [channel][`GuildChannel`]'s Id. /// /// This method requires authentication. /// @@ -879,7 +879,7 @@ pub fn get_channel_invites(channel_id: u64) /// .expect("err getting channel webhooks"); /// ``` /// -/// [`PublicChannel`]: ../../model/struct.PublicChannel.html +/// [`GuildChannel`]: ../../model/struct.GuildChannel.html pub fn get_channel_webhooks(channel_id: u64) -> Result<Vec<Webhook>> { let response = request!(Route::ChannelsIdWebhooks(channel_id), get, @@ -898,14 +898,14 @@ pub fn get_channel(channel_id: u64) -> Result<Channel> { Channel::decode(try!(serde_json::from_reader(response))) } -pub fn get_channels(guild_id: u64) -> Result<Vec<PublicChannel>> { +pub fn get_channels(guild_id: u64) -> Result<Vec<GuildChannel>> { let response = request!(Route::ChannelsId(guild_id), get, "/guilds/{}/channels", guild_id); decode_array(try!(serde_json::from_reader(response)), - PublicChannel::decode) + GuildChannel::decode) } pub fn get_current_user() -> Result<CurrentUser> { diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs index e819eea..28a8a6c 100644 --- a/src/ext/cache/mod.rs +++ b/src/ext/cache/mod.rs @@ -119,7 +119,7 @@ impl Cache { for guild in self.guilds.values() { for channel in guild.channels.values() { if channel.id == id { - return Some(Channel::Public(channel.clone())); + return Some(Channel::Guild(channel.clone())); } } } @@ -326,7 +326,7 @@ impl Cache { ch.map(Channel::Private) }, - Channel::Public(ref channel) => { + Channel::Guild(ref channel) => { let ch = self.guilds .get_mut(&channel.guild_id) .map(|guild| { @@ -338,7 +338,7 @@ impl Cache { _ => None, }; - ch.map(Channel::Public) + ch.map(Channel::Guild) }, } } @@ -353,13 +353,13 @@ impl Cache { self.private_channels.remove(&channel.id) .map(Channel::Private) }, - Channel::Public(ref channel) => { + Channel::Guild(ref channel) => { let ch = self.guilds .get_mut(&channel.guild_id) .map(|guild| guild.channels.remove(&channel.id)); match ch { - Some(Some(ch)) => Some(Channel::Public(ch)), + Some(Some(ch)) => Some(Channel::Guild(ch)), _ => None, } }, @@ -430,17 +430,17 @@ impl Cache { }, } }, - Channel::Private(ref channel) => { - self.private_channels - .get_mut(&channel.id) - .map(|private| private.clone_from(channel)); - }, - Channel::Public(ref channel) => { + Channel::Guild(ref channel) => { self.guilds .get_mut(&channel.guild_id) .map(|guild| guild.channels .insert(channel.id, channel.clone())); }, + Channel::Private(ref channel) => { + self.private_channels + .get_mut(&channel.id) + .map(|private| private.clone_from(channel)); + }, } } @@ -652,7 +652,7 @@ impl Cache { Channel::Private(channel) => { self.private_channels.insert(channel_id, channel); }, - Channel::Public(_) => {}, + Channel::Guild(_) => {}, } } @@ -835,15 +835,15 @@ fn update_presence(presences: &mut HashMap<UserId, Presence>, } } -/// A reference to a private channel, public channel, or group. +/// A reference to a private channel, guild's channel, or group. #[derive(Debug, Clone, Copy)] pub enum ChannelRef<'a> { + /// A group's channel + Group(&'a Group), + /// A guild channel and its guild + Guild(&'a Guild, &'a GuildChannel), /// A private channel Private(&'a PrivateChannel), - /// A group channel - Group(&'a Group), - /// A public channel and its guild - Public(&'a Guild, &'a PublicChannel), } fn opt_modify<T: Clone>(dest: &mut T, src: &Option<T>) { diff --git a/src/model/channel.rs b/src/model/channel.rs index 8911487..64e7c71 100644 --- a/src/model/channel.rs +++ b/src/model/channel.rs @@ -195,8 +195,8 @@ impl Channel { pub fn decode(value: Value) -> Result<Channel> { let map = try!(into_map(value)); match req!(map.get("type").and_then(|x| x.as_u64())) { - 0 | 2 => PublicChannel::decode(Value::Object(map)) - .map(Channel::Public), + 0 | 2 => GuildChannel::decode(Value::Object(map)) + .map(Channel::Guild), 1 => PrivateChannel::decode(Value::Object(map)) .map(Channel::Private), 3 => Group::decode(Value::Object(map)) @@ -218,28 +218,28 @@ impl Channel { Channel::Group(ref group) => { let _ = try!(group.leave()); }, + Channel::Guild(ref public_channel) => { + let _ = try!(public_channel.delete()); + }, Channel::Private(ref private_channel) => { let _ = try!(private_channel.delete()); }, - Channel::Public(ref public_channel) => { - let _ = try!(public_channel.delete()); - }, } Ok(()) } - /// Retrieves the Id of the inner [`Group`], [`PublicChannel`], or + /// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or /// [`PrivateChannel`]. /// /// [`Group`]: struct.Group.html - /// [`PublicChannel`]: struct.PublicChannel.html + /// [`GuildChannel`]: struct.GuildChannel.html /// [`PrivateChannel`]: struct.PrivateChannel.html pub fn id(&self) -> ChannelId { match *self { Channel::Group(ref group) => group.channel_id, + Channel::Guild(ref channel) => channel.id, Channel::Private(ref channel) => channel.id, - Channel::Public(ref channel) => channel.id, } } } @@ -251,18 +251,18 @@ impl fmt::Display for Channel { /// /// - [`Group`]s: the generated name retrievable via [`Group::name`]; /// - [`PrivateChannel`]s: the recipient's name; - /// - [`PublicChannel`]s: a string mentioning the channel that users who can + /// - [`GuildChannel`]s: a string mentioning the channel that users who can /// see the channel can click on. /// /// [`Group`]: struct.Group.html /// [`Group::name`]: struct.Group.html#method.name - /// [`PublicChannel`]: struct.PublicChannel.html + /// [`GuildChannel`]: struct.GuildChannel.html /// [`PrivateChannel`]: struct.PrivateChannel.html fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let out = match *self { Channel::Group(ref group) => group.name().to_owned(), + Channel::Guild(ref channel) => Cow::Owned(format!("{}", channel)), Channel::Private(ref channel) => Cow::Owned(channel.recipient.name.clone()), - Channel::Public(ref channel) => Cow::Owned(format!("{}", channel)), }; fmt::Display::fmt(&out, f) @@ -784,7 +784,7 @@ impl fmt::Display for PrivateChannel { } } -impl PublicChannel { +impl GuildChannel { /// Broadcasts to the channel that the current user is typing. /// /// For bots, this is a good indicator for long-running commands. @@ -819,18 +819,18 @@ impl PublicChannel { } #[doc(hidden)] - pub fn decode(value: Value) -> Result<PublicChannel> { + pub fn decode(value: Value) -> Result<GuildChannel> { let mut map = try!(into_map(value)); let id = try!(remove(&mut map, "guild_id").and_then(GuildId::decode)); - PublicChannel::decode_guild(Value::Object(map), id) + GuildChannel::decode_guild(Value::Object(map), id) } #[doc(hidden)] - pub fn decode_guild(value: Value, guild_id: GuildId) -> Result<PublicChannel> { + pub fn decode_guild(value: Value, guild_id: GuildId) -> Result<GuildChannel> { let mut map = try!(into_map(value)); - missing!(map, PublicChannel { + missing!(map, GuildChannel { id: try!(remove(&mut map, "id").and_then(ChannelId::decode)), name: try!(remove(&mut map, "name").and_then(into_string)), guild_id: guild_id, @@ -954,7 +954,7 @@ impl PublicChannel { } } -impl fmt::Display for PublicChannel { +impl fmt::Display for GuildChannel { /// Formas the channel, creating a mention of it. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.mention(), f) diff --git a/src/model/gateway.rs b/src/model/gateway.rs index d12205b..c867a00 100644 --- a/src/model/gateway.rs +++ b/src/model/gateway.rs @@ -462,10 +462,10 @@ pub enum Event { VoiceStateUpdate(VoiceStateUpdateEvent), /// Voice server information is available VoiceServerUpdate(VoiceServerUpdateEvent), - /// A webhook for a [channel][`PublicChannel`] was updated in a [`Guild`]. + /// A webhook for a [channel][`GuildChannel`] was updated in a [`Guild`]. /// /// [`Guild`]: struct.Guild.html - /// [`PublicChannel`]: struct.PublicChannel.html + /// [`GuildChannel`]: struct.GuildChannel.html WebhookUpdate(WebhookUpdateEvent), /// An event type not covered by the above Unknown(UnknownEvent), diff --git a/src/model/guild.rs b/src/model/guild.rs index 33adc80..9cfbd7e 100644 --- a/src/model/guild.rs +++ b/src/model/guild.rs @@ -331,7 +331,7 @@ impl Guild { let mut public_channels = HashMap::new(); let vals = try!(decode_array(try!(remove(&mut map, "channels")), - |v| PublicChannel::decode_guild(v, id))); + |v| GuildChannel::decode_guild(v, id))); for public_channel in vals { public_channels.insert(public_channel.id, public_channel); @@ -461,11 +461,11 @@ impl Guild { rest::edit_nickname(self.id.0, new_nickname) } - /// Attempts to retrieve a [`PublicChannel`] with the given Id. + /// Attempts to retrieve a [`GuildChannel`] with the given Id. /// - /// [`PublicChannel`]: struct.PublicChannel.html + /// [`GuildChannel`]: struct.GuildChannel.html pub fn get_channel<C: Into<ChannelId>>(&self, channel_id: C) - -> Option<&PublicChannel> { + -> Option<&GuildChannel> { self.channels.get(&channel_id.into()) } diff --git a/src/model/id.rs b/src/model/id.rs index d7d131a..7cc4f31 100644 --- a/src/model/id.rs +++ b/src/model/id.rs @@ -53,8 +53,8 @@ impl From<Channel> for ChannelId { fn from(channel: Channel) -> ChannelId { match channel { Channel::Group(group) => group.channel_id, + Channel::Guild(channel) => channel.id, Channel::Private(channel) => channel.id, - Channel::Public(channel) => channel.id, } } } @@ -65,8 +65,8 @@ impl From<PrivateChannel> for ChannelId { } } -impl From<PublicChannel> for ChannelId { - fn from(public_channel: PublicChannel) -> ChannelId { +impl From<GuildChannel> for ChannelId { + fn from(public_channel: GuildChannel) -> ChannelId { public_channel.id } } diff --git a/src/model/mod.rs b/src/model/mod.rs index 880be42..5d1540b 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -124,15 +124,15 @@ id! { pub enum Channel { /// A group. A group comprises of only one channel. Group(Group), - /// A private channel to another [`User`]. No other users may access the - /// channel. For multi-user "private channels", use a group. - Private(PrivateChannel), /// A [text] or [voice] channel within a [`Guild`]. /// /// [`Guild`]: struct.Guild.html /// [text]: enum.ChannelType.html#variant.Text /// [voice]: enum.ChannelType.html#variant.Voice - Public(PublicChannel), + Guild(GuildChannel), + /// A private channel to another [`User`]. No other users may access the + /// channel. For multi-user "private channels", use a group. + Private(PrivateChannel), } /// A container for guilds. diff --git a/src/model/permissions.rs b/src/model/permissions.rs index cb9a061..3f164fe 100644 --- a/src/model/permissions.rs +++ b/src/model/permissions.rs @@ -169,7 +169,7 @@ bitflags! { const ADMINISTRATOR = 1 << 3, /// Allows management and editing of guild [channel]s. /// - /// [channel]: ../struct.PublicChannel.html + /// [channel]: ../struct.GuildChannel.html const MANAGE_CHANNELS = 1 << 4, /// Allows management and editing of the [guild]. /// diff --git a/src/model/utils.rs b/src/model/utils.rs index a995758..23fdfc5 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -143,7 +143,7 @@ pub fn decode_private_channels(value: Value) let id = match private_channel { Channel::Group(ref group) => group.channel_id, Channel::Private(ref channel) => channel.id, - Channel::Public(_) => unreachable!("Public private channel decode"), + Channel::Guild(_) => unreachable!("Guild private channel decode"), }; private_channels.insert(id, private_channel); @@ -287,7 +287,7 @@ pub fn user_has_perms(channel_id: ChannelId, Channel::Group(_) | Channel::Private(_) => { return Ok(permissions == permissions::MANAGE_MESSAGES); }, - Channel::Public(channel) => channel.guild_id, + Channel::Guild(channel) => channel.guild_id, }; let guild = match cache.get_guild(guild_id) { diff --git a/src/utils/builder/edit_channel.rs b/src/utils/builder/edit_channel.rs index 7225902..1fd1b5c 100644 --- a/src/utils/builder/edit_channel.rs +++ b/src/utils/builder/edit_channel.rs @@ -1,12 +1,12 @@ use serde_json::builder::ObjectBuilder; use std::default::Default; -/// A builder to edit a [`PublicChannel`] for use via one of a couple methods. +/// A builder to edit a [`GuildChannel`] for use via one of a couple methods. /// /// These methods are: /// /// - [`Context::edit_channel`] -/// - [`PublicChannel::edit`] +/// - [`GuildChannel::edit`] /// /// Defaults are not directly provided by the builder itself. /// @@ -22,8 +22,8 @@ use std::default::Default; /// ``` /// /// [`Context::edit_channel`]: ../client/struct.Context.html#method.edit_channel -/// [`PublicChannel`]: ../model/struct.PublicChannel.html -/// [`PublicChannel::edit`]: ../model/struct.PublicChannel.html#method.edit +/// [`GuildChannel`]: ../model/struct.GuildChannel.html +/// [`GuildChannel::edit`]: ../model/struct.GuildChannel.html#method.edit pub struct EditChannel(pub ObjectBuilder); impl EditChannel { diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs index a9a88ae..e30db05 100644 --- a/src/utils/message_builder.rs +++ b/src/utils/message_builder.rs @@ -53,7 +53,7 @@ impl MessageBuilder { self.0 } - /// Mentions the [`PublicChannel`] in the built message. + /// Mentions the [`GuildChannel`] in the built message. /// /// This accepts anything that converts _into_ a [`ChannelId`]. Refer to /// `ChannelId`'s documentation for more information. @@ -62,7 +62,7 @@ impl MessageBuilder { /// how this is formatted. /// /// [`ChannelId`]: ../model/struct.ChannelId.html - /// [`PublicChannel`]: ../model/struct.PublicChannel.html + /// [`GuildChannel`]: ../model/struct.GuildChannel.html /// [Display implementation]: ../model/struct.ChannelId.html#method.fmt-1 pub fn channel<C: Into<ChannelId>>(mut self, channel: C) -> Self { self.0.push_str(&format!("{}", channel.into())); |