diff options
| author | Leah <[email protected]> | 2018-03-23 13:54:12 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2018-03-23 13:54:12 +0100 |
| commit | fdcf44e1463e708cd8b612c183e302db9af0febd (patch) | |
| tree | 1a311f26fb38522ba380881fa6e72c0c2e5c54bc /src | |
| parent | Fix Create(Embed/Message) to be consistent (diff) | |
| download | serenity-fdcf44e1463e708cd8b612c183e302db9af0febd.tar.xz serenity-fdcf44e1463e708cd8b612c183e302db9af0febd.zip | |
Change the way ids and some enums are made (#295)
This makes them easier to be found by tools like rls.
Also update struct inits to use the shorthand version for `x: x`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/builder/create_embed.rs | 2 | ||||
| -rw-r--r-- | src/constants.rs | 108 | ||||
| -rw-r--r-- | src/framework/standard/mod.rs | 4 | ||||
| -rw-r--r-- | src/internal/macros.rs | 13 | ||||
| -rw-r--r-- | src/internal/timer.rs | 2 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 46 | ||||
| -rw-r--r-- | src/model/channel/mod.rs | 53 | ||||
| -rw-r--r-- | src/model/event.rs | 18 | ||||
| -rw-r--r-- | src/model/gateway.rs | 41 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 134 | ||||
| -rw-r--r-- | src/model/id.rs | 67 | ||||
| -rw-r--r-- | src/model/permissions.rs | 84 | ||||
| -rw-r--r-- | src/utils/mod.rs | 2 | ||||
| -rw-r--r-- | src/utils/vec_map.rs | 4 | ||||
| -rw-r--r-- | src/voice/connection.rs | 10 | ||||
| -rw-r--r-- | src/voice/handler.rs | 16 | ||||
| -rw-r--r-- | src/voice/manager.rs | 4 | ||||
| -rw-r--r-- | src/voice/streamer.rs | 4 |
18 files changed, 365 insertions, 247 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index de2031c..e1988ac 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -451,7 +451,7 @@ pub struct Timestamp { impl From<String> for Timestamp { fn from(ts: String) -> Self { Timestamp { - ts: ts, + ts, } } } diff --git a/src/constants.rs b/src/constants.rs index c9f22ac..1eff758 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -45,33 +45,49 @@ pub static JOIN_MESSAGES: &'static [&'static str] = &[ "$user just showed up. Hold my beer.", ]; +/// Enum to map gateway opcodes. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum OpCode { + /// Dispatches an event. + Event = 0, + /// Used for ping checking. + Heartbeat = 1, + /// Used for client handshake. + Identify = 2, + /// Used to update the client status. + StatusUpdate = 3, + /// Used to join/move/leave voice channels. + VoiceStateUpdate = 4, + /// Used for voice ping checking. + VoiceServerPing = 5, + /// Used to resume a closed connection. + Resume = 6, + /// Used to tell clients to reconnect to the gateway. + Reconnect = 7, + /// Used to request guild members. + GetGuildMembers = 8, + /// Used to notify clients that they have an invalid session Id. + InvalidSession = 9, + /// Sent immediately after connection, contains heartbeat + server info. + Hello = 10, + /// Sent immediately following a client heartbeat that was received. + HeartbeatAck = 11, +} + enum_number!( - /// Enum to map gateway opcodes. OpCode { - /// Dispatches an event. - Event = 0, - /// Used for ping checking. - Heartbeat = 1, - /// Used for client handshake. - Identify = 2, - /// Used to update the client status. - StatusUpdate = 3, - /// Used to join/move/leave voice channels. - VoiceStateUpdate = 4, - /// Used for voice ping checking. - VoiceServerPing = 5, - /// Used to resume a closed connection. - Resume = 6, - /// Used to tell clients to reconnect to the gateway. - Reconnect = 7, - /// Used to request guild members. - GetGuildMembers = 8, - /// Used to notify clients that they have an invalid session Id. - InvalidSession = 9, - /// Sent immediately after connection, contains heartbeat + server info. - Hello = 10, - /// Sent immediately following a client heartbeat that was received. - HeartbeatAck = 11, + Event, + Heartbeat, + Identify, + StatusUpdate, + VoiceStateUpdate, + VoiceServerPing, + Resume, + Reconnect, + GetGuildMembers, + InvalidSession, + Hello, + HeartbeatAck, } ); @@ -94,23 +110,35 @@ impl OpCode { } } + +/// Enum to map voice opcodes. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum VoiceOpCode { + /// Used to begin a voice websocket connection. + Identify = 0, + /// Used to select the voice protocol. + SelectProtocol = 1, + /// Used to complete the websocket handshake. + Hello = 2, + /// Used to keep the websocket connection alive. + KeepAlive = 3, + /// Used to describe the session. + SessionDescription = 4, + /// Used to indicate which users are speaking. + Speaking = 5, + /// Used to heartbeat. + Heartbeat = 8, +} + enum_number!( - /// Enum to map voice opcodes. VoiceOpCode { - /// Used to begin a voice websocket connection. - Identify = 0, - /// Used to select the voice protocol. - SelectProtocol = 1, - /// Used to complete the websocket handshake. - Hello = 2, - /// Used to keep the websocket connection alive. - KeepAlive = 3, - /// Used to describe the session. - SessionDescription = 4, - /// Used to indicate which users are speaking. - Speaking = 5, - /// Used to heartbeat. - Heartbeat = 8, + Identify, + SelectProtocol, + Hello, + KeepAlive, + SessionDescription, + Speaking, + Heartbeat, } ); diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index 03abce8..1eb1ad2 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -299,7 +299,7 @@ impl StandardFramework { s.to_string(), Bucket { ratelimit: Ratelimit { - delay: delay, + delay, limit: Some((time_span, limit)), }, users: HashMap::new(), @@ -445,7 +445,7 @@ impl StandardFramework { s.to_string(), Bucket { ratelimit: Ratelimit { - delay: delay, + delay, limit: None, }, users: HashMap::new(), diff --git a/src/internal/macros.rs b/src/internal/macros.rs index 875326a..c4d2b6f 100644 --- a/src/internal/macros.rs +++ b/src/internal/macros.rs @@ -99,16 +99,7 @@ macro_rules! feature_framework { } macro_rules! enum_number { - (#[$attr_:meta] $name:ident { $(#[$attr:meta] $variant:ident = $value:expr, )* }) => { - #[$attr_] - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] - pub enum $name { - $( - #[$attr] - $variant = $value, - )* - } - + ($name:ident { $($variant:ident, )* }) => { impl ::serde::Serialize for $name { fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error> where S: ::serde::Serializer @@ -138,7 +129,7 @@ macro_rules! enum_number { // Rust does not come with a simple way of converting a // number to an enum, so use a big `match`. match value { - $( $value => Ok($name::$variant), )* + $( v if v == $name::$variant as u64 => Ok($name::$variant), )* _ => Err(E::custom( format!("unknown {} value: {}", stringify!($name), value))), diff --git a/src/internal/timer.rs b/src/internal/timer.rs index fa2fcc2..18ca672 100644 --- a/src/internal/timer.rs +++ b/src/internal/timer.rs @@ -14,7 +14,7 @@ impl Timer { Timer { due: Utc::now() + duration, - duration: duration, + duration, } } diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index eefb633..566107b 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -605,25 +605,37 @@ pub struct MessageReaction { pub reaction_type: ReactionType, } +/// Differentiates between regular and different types of system messages. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum MessageType { + /// A regular message. + Regular = 0, + /// An indicator that a recipient was added by the author. + GroupRecipientAddition = 1, + /// An indicator that a recipient was removed by the author. + GroupRecipientRemoval = 2, + /// An indicator that a call was started by the author. + GroupCallCreation = 3, + /// An indicator that the group name was modified by the author. + GroupNameUpdate = 4, + /// An indicator that the group icon was modified by the author. + GroupIconUpdate = 5, + /// An indicator that a message was pinned by the author. + PinsAdd = 6, + /// An indicator that a member joined the guild. + MemberJoin = 7, +} + enum_number!( - /// Differentiates between regular and different types of system messages. MessageType { - /// A regular message. - Regular = 0, - /// An indicator that a recipient was added by the author. - GroupRecipientAddition = 1, - /// An indicator that a recipient was removed by the author. - GroupRecipientRemoval = 2, - /// An indicator that a call was started by the author. - GroupCallCreation = 3, - /// An indicator that the group name was modified by the author. - GroupNameUpdate = 4, - /// An indicator that the group icon was modified by the author. - GroupIconUpdate = 5, - /// An indicator that a message was pinned by the author. - PinsAdd = 6, - /// An indicator that a member joined the guild. - MemberJoin = 7, + Regular, + GroupRecipientAddition, + GroupRecipientRemoval, + GroupCallCreation, + GroupNameUpdate, + GroupIconUpdate, + PinsAdd, + MemberJoin, } ); diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index eadc7bb..5487a0b 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -555,29 +555,38 @@ impl Display for Channel { } } +/// A representation of a type of channel. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum ChannelType { + /// An indicator that the channel is a text [`GuildChannel`]. + /// + /// [`GuildChannel`]: struct.GuildChannel.html + Text = 0, + /// An indicator that the channel is a [`PrivateChannel`]. + /// + /// [`PrivateChannel`]: struct.PrivateChannel.html + Private = 1, + /// An indicator that the channel is a voice [`GuildChannel`]. + /// + /// [`GuildChannel`]: struct.GuildChannel.html + Voice = 2, + /// An indicator that the channel is the channel of a [`Group`]. + /// + /// [`Group`]: struct.Group.html + Group = 3, + /// An indicator that the channel is the channel of a [`ChannelCategory`]. + /// + /// [`ChannelCategory`]: struct.ChannelCategory.html + Category = 4, +} + enum_number!( - /// A representation of a type of channel. ChannelType { - #[doc="An indicator that the channel is a text [`GuildChannel`]. - -[`GuildChannel`]: struct.GuildChannel.html"] - Text = 0, - #[doc="An indicator that the channel is a [`PrivateChannel`]. - -[`PrivateChannel`]: struct.PrivateChannel.html"] - Private = 1, - #[doc="An indicator that the channel is a voice [`GuildChannel`]. - -[`GuildChannel`]: struct.GuildChannel.html"] - Voice = 2, - #[doc="An indicator that the channel is the channel of a [`Group`]. - -[`Group`]: struct.Group.html"] - Group = 3, - #[doc="An indicator that the channel is the channel of a [`ChannelCategory`]. - -[`ChannelCategory`]: struct.ChannelCategory.html"] - Category = 4, + Text, + Private, + Voice, + Group, + Category, } ); @@ -633,7 +642,7 @@ impl<'de> Deserialize<'de> for PermissionOverwrite { Ok(PermissionOverwrite { allow: data.allow, deny: data.deny, - kind: kind, + kind, }) } } diff --git a/src/model/event.rs b/src/model/event.rs index cf18995..5f66dac 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -483,7 +483,7 @@ impl<'de> Deserialize<'de> for GuildMemberAddEvent { .map_err(DeError::custom)?; Ok(GuildMemberAddEvent { - guild_id: guild_id, + guild_id, member: Member::deserialize(Value::Object(map)) .map_err(DeError::custom)?, }) @@ -615,8 +615,8 @@ impl<'de> Deserialize<'de> for GuildMembersChunkEvent { Deserialize::deserialize(members).map_err(DeError::custom)?; Ok(GuildMembersChunkEvent { - guild_id: guild_id, - members: members, + guild_id, + members, }) } } @@ -833,7 +833,7 @@ impl CacheUpdate for PresenceUpdateEvent { guild.members.insert(self.presence.user_id, Member { deaf: false, - guild_id: guild_id, + guild_id, joined_at: None, mute: false, nick: self.presence.nick.clone(), @@ -873,9 +873,9 @@ impl<'de> Deserialize<'de> for PresenceUpdateEvent { .map_err(DeError::custom)?; Ok(Self { - guild_id: guild_id, - presence: presence, - roles: roles, + guild_id, + presence, + roles, }) } } @@ -909,7 +909,7 @@ impl<'de> Deserialize<'de> for PresencesReplaceEvent { let presences: Vec<Presence> = Deserialize::deserialize(deserializer)?; Ok(Self { - presences: presences, + presences, }) } } @@ -1141,7 +1141,7 @@ impl<'de> Deserialize<'de> for VoiceStateUpdateEvent { }; Ok(VoiceStateUpdateEvent { - guild_id: guild_id, + guild_id, voice_state: VoiceState::deserialize(Value::Object(map)) .map_err(DeError::custom)?, }) diff --git a/src/model/gateway.rs b/src/model/gateway.rs index 924f27f..e795077 100644 --- a/src/model/gateway.rs +++ b/src/model/gateway.rs @@ -144,22 +144,31 @@ impl<'de> Deserialize<'de> for Game { .and_then(|v| serde_json::from_value::<String>(v).ok()); Ok(Game { - kind: kind, - name: name, - url: url, + kind, + name, + url, }) } } + + +/// The type of activity that is being performed when playing a game. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum GameType { + /// An indicator that the user is playing a game. + Playing = 0, + /// An indicator that the user is streaming to a service. + Streaming = 1, + /// An indicator that the user is listening to something. + Listening = 2, +} + enum_number!( - /// The type of activity that is being performed when playing a game. GameType { - /// An indicator that the user is playing a game. - Playing = 0, - /// An indicator that the user is streaming to a service. - Streaming = 1, - /// An indicator that the user is listening to something. - Listening = 2, + Playing, + Streaming, + Listening, } ); @@ -255,12 +264,12 @@ impl<'de> Deserialize<'de> for Presence { .map_err(DeError::custom)?; Ok(Presence { - game: game, - last_modified: last_modified, - nick: nick, - status: status, - user: user, - user_id: user_id, + game, + last_modified, + nick, + status, + user, + user_id, }) } } diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 629c496..9e4d8ef 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -1649,30 +1649,30 @@ impl<'de> Deserialize<'de> for Guild { .map_err(DeError::custom)?; Ok(Self { - afk_channel_id: afk_channel_id, - application_id: application_id, - afk_timeout: afk_timeout, - channels: channels, - default_message_notifications: default_message_notifications, - emojis: emojis, - explicit_content_filter: explicit_content_filter, - features: features, - icon: icon, - id: id, - joined_at: joined_at, - large: large, - member_count: member_count, - members: members, - mfa_level: mfa_level, - name: name, - owner_id: owner_id, - presences: presences, - region: region, - roles: roles, - splash: splash, - system_channel_id: system_channel_id, - verification_level: verification_level, - voice_states: voice_states, + afk_channel_id, + application_id, + afk_timeout, + channels, + default_message_notifications, + emojis, + explicit_content_filter, + features, + icon, + id, + joined_at, + large, + member_count, + members, + mfa_level, + name, + owner_id, + presences, + region, + roles, + splash, + system_channel_id, + verification_level, + voice_states, }) } } @@ -1828,13 +1828,19 @@ impl GuildStatus { } } +/// Default message notification level for a guild. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum DefaultMessageNotificationLevel { + /// Receive notifications for everything. + All = 0, + /// Receive only mentions. + Mentions = 1, +} + enum_number!( - /// Default message notification level for a guild. DefaultMessageNotificationLevel { - /// Receive notifications for everything. - All = 0, - /// Receive only mentions. - Mentions = 1, + All, + Mentions, } ); @@ -1847,15 +1853,22 @@ impl DefaultMessageNotificationLevel { } } +/// Setting used to filter explicit messages from members. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum ExplicitContentFilter { + /// Don't scan any messages. + None = 0, + /// Scan messages from members without a role. + WithoutRole = 1, + /// Scan messages sent by all members. + All = 2, +} + enum_number!( - /// Setting used to filter explicit messages from members. ExplicitContentFilter { - /// Don't scan any messages. - None = 0, - /// Scan messages from members without a role. - WithoutRole = 1, - /// Scan messages sent by all members. - All = 2, + None, + WithoutRole, + All, } ); @@ -1869,13 +1882,19 @@ impl ExplicitContentFilter { } } +/// Multi-Factor Authentication level for guild moderators. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum MfaLevel { + /// MFA is disabled. + None = 0, + /// MFA is enabled. + Elevated = 1, +} + enum_number!( - /// Multi-Factor Authentication level for guild moderators. MfaLevel { - /// MFA is disabled. - None = 0, - /// MFA is enabled. - Elevated = 1, + None, + Elevated, } ); @@ -1936,22 +1955,31 @@ impl Region { } } -enum_number!( - #[doc="The level to set as criteria prior to a user being able to send +#[doc="The level to set as criteria prior to a user being able to send messages in a [`Guild`]. [`Guild`]: struct.Guild.html"] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +pub enum VerificationLevel { + /// Does not require any verification. + None = 0, + /// Must have a verified email on the user's Discord account. + Low = 1, + /// Must also be a registered user on Discord for longer than 5 minutes. + Medium = 2, + /// Must also be a member of the guild for longer than 10 minutes. + High = 3, + /// Must have a verified phone on the user's Discord account. + Higher = 4, +} + +enum_number!( VerificationLevel { - /// Does not require any verification. - None = 0, - /// Must have a verified email on the user's Discord account. - Low = 1, - /// Must also be a registered user on Discord for longer than 5 minutes. - Medium = 2, - /// Must also be a member of the guild for longer than 10 minutes. - High = 3, - /// Must have a verified phone on the user's Discord account. - Higher = 4, + None, + Low, + Medium, + High, + Higher, } ); diff --git a/src/model/id.rs b/src/model/id.rs index 3d8c20c..4e2fbc3 100644 --- a/src/model/id.rs +++ b/src/model/id.rs @@ -7,13 +7,8 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use super::utils::U64Visitor; macro_rules! id_u64 { - ($(#[$attr:meta] $name:ident;)*) => { + ($($name:ident;)*) => { $( - #[$attr] - #[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] - #[allow(derive_hash_xor_eq)] - pub struct $name(pub u64); - impl $name { /// Retrieves the time that the Id was created at. pub fn created_at(&self) -> NaiveDateTime { @@ -65,25 +60,65 @@ macro_rules! id_u64 { } } +/// An identifier for an Application. +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct ApplicationId(pub u64); + +/// An identifier for a Channel +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct ChannelId(pub u64); + +/// An identifier for an Emoji +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct EmojiId(pub u64); + +/// An identifier for a Guild +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct GuildId(pub u64); + +/// An identifier for an Integration +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct IntegrationId(pub u64); + +/// An identifier for a Message +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct MessageId(pub u64); + +/// An identifier for a Role +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct RoleId(pub u64); + +/// An identifier for a User +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct UserId(pub u64); + +/// An identifier for a [`Webhook`](struct.Webhook.html). +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct WebhookId(pub u64); + +/// An identifier for an audit log entry. +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct AuditLogEntryId(pub u64); + id_u64! { - /// An identifier for an Application. ApplicationId; - /// An identifier for a Channel ChannelId; - /// An identifier for an Emoji EmojiId; - /// An identifier for a Guild GuildId; - /// An identifier for an Integration IntegrationId; - /// An identifier for a Message MessageId; - /// An identifier for a Role RoleId; - /// An identifier for a User UserId; - /// An identifier for a [`Webhook`](struct.Webhook.html). WebhookId; - /// An identifier for an audit log entry. AuditLogEntryId; } diff --git a/src/model/permissions.rs b/src/model/permissions.rs index dbf0b69..0076b05 100644 --- a/src/model/permissions.rs +++ b/src/model/permissions.rs @@ -145,41 +145,47 @@ pub const PRESET_VOICE: Permissions = Permissions { bits: 0b0000_0011_1111_0000_0000_0000_0000_0000, }; -bitflags! { - /// A set of permissions that can be assigned to [`User`]s and [`Role`]s via - /// [`PermissionOverwrite`]s, roles globally in a [`Guild`], and to - /// [`GuildChannel`]s. - /// - /// [`Guild`]: ../struct.Guild.html - /// [`GuildChannel`]: ../struct.GuildChannel.html - /// [`PermissionOverwrite`]: ../struct.PermissionOverwrite.html - /// [`Role`]: ../struct.Role.html - /// [`User`]: ../struct.User.html - pub struct Permissions: u64 { +/// A set of permissions that can be assigned to [`User`]s and [`Role`]s via +/// [`PermissionOverwrite`]s, roles globally in a [`Guild`], and to +/// [`GuildChannel`]s. +/// +/// [`Guild`]: ../struct.Guild.html +/// [`GuildChannel`]: ../struct.GuildChannel.html +/// [`PermissionOverwrite`]: ../struct.PermissionOverwrite.html +/// [`Role`]: ../struct.Role.html +/// [`User`]: ../struct.User.html +/// +#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)] +pub struct Permissions { + bits: u64 +} + +__impl_bitflags! { + Permissions: u64 { /// Allows for the creation of [`RichInvite`]s. /// /// [`RichInvite`]: ../struct.RichInvite.html - const CREATE_INVITE = 0b0000_0000_0000_0000_0000_0000_0000_0001; + CREATE_INVITE = 0b0000_0000_0000_0000_0000_0000_0000_0001; /// Allows for the kicking of guild [member]s. /// /// [member]: ../struct.Member.html - const KICK_MEMBERS = 0b0000_0000_0000_0000_0000_0000_0000_0010; + KICK_MEMBERS = 0b0000_0000_0000_0000_0000_0000_0000_0010; /// Allows the banning of guild [member]s. /// /// [member]: ../struct.Member.html - const BAN_MEMBERS = 0b0000_0000_0000_0000_0000_0000_0000_0100; + BAN_MEMBERS = 0b0000_0000_0000_0000_0000_0000_0000_0100; /// Allows all permissions, bypassing channel [permission overwrite]s. /// /// [permission overwrite]: ../struct.PermissionOverwrite.html - const ADMINISTRATOR = 0b0000_0000_0000_0000_0000_0000_0000_1000; + ADMINISTRATOR = 0b0000_0000_0000_0000_0000_0000_0000_1000; /// Allows management and editing of guild [channel]s. /// /// [channel]: ../struct.GuildChannel.html - const MANAGE_CHANNELS = 0b0000_0000_0000_0000_0000_0000_0001_0000; + MANAGE_CHANNELS = 0b0000_0000_0000_0000_0000_0000_0001_0000; /// Allows management and editing of the [guild]. /// /// [guild]: ../struct.Guild.html - const MANAGE_GUILD = 0b0000_0000_0000_0000_0000_0000_0010_0000; + MANAGE_GUILD = 0b0000_0000_0000_0000_0000_0000_0010_0000; /// [`Member`]s with this permission can add new [`Reaction`]s to a /// [`Message`]. Members can still react using reactions already added /// to messages without this permission. @@ -187,70 +193,70 @@ bitflags! { /// [`Member`]: ../struct.Member.html /// [`Message`]: ../struct.Message.html /// [`Reaction`]: ../struct.Reaction.html - const ADD_REACTIONS = 0b0000_0000_0000_0000_0000_0000_0100_0000; + ADD_REACTIONS = 0b0000_0000_0000_0000_0000_0000_0100_0000; // Allows viewing a guild's audit logs. - const VIEW_AUDIT_LOG = 0b0000_0000_0000_0000_0000_0000_1000_0000; + VIEW_AUDIT_LOG = 0b0000_0000_0000_0000_0000_0000_1000_0000; /// Allows reading messages in a guild channel. If a user does not have /// this permission, then they will not be able to see the channel. - const READ_MESSAGES = 0b0000_0000_0000_0000_0000_0100_0000_0000; + READ_MESSAGES = 0b0000_0000_0000_0000_0000_0100_0000_0000; /// Allows sending messages in a guild channel. - const SEND_MESSAGES = 0b0000_0000_0000_0000_0000_1000_0000_0000; + SEND_MESSAGES = 0b0000_0000_0000_0000_0000_1000_0000_0000; /// Allows the sending of text-to-speech messages in a channel. - const SEND_TTS_MESSAGES = 0b0000_0000_0000_0000_0001_0000_0000_0000; + SEND_TTS_MESSAGES = 0b0000_0000_0000_0000_0001_0000_0000_0000; /// Allows the deleting of other messages in a guild channel. /// /// **Note**: This does not allow the editing of other messages. - const MANAGE_MESSAGES = 0b0000_0000_0000_0000_0010_0000_0000_0000; + MANAGE_MESSAGES = 0b0000_0000_0000_0000_0010_0000_0000_0000; /// Allows links from this user - or users of this role - to be /// embedded, with potential data such as a thumbnail, description, and /// page name. - const EMBED_LINKS = 0b0000_0000_0000_0000_0100_0000_0000_0000; + EMBED_LINKS = 0b0000_0000_0000_0000_0100_0000_0000_0000; /// Allows uploading of files. - const ATTACH_FILES = 0b0000_0000_0000_0000_1000_0000_0000_0000; + ATTACH_FILES = 0b0000_0000_0000_0000_1000_0000_0000_0000; /// Allows the reading of a channel's message history. - const READ_MESSAGE_HISTORY = 0b0000_0000_0000_0001_0000_0000_0000_0000; + READ_MESSAGE_HISTORY = 0b0000_0000_0000_0001_0000_0000_0000_0000; /// Allows the usage of the `@everyone` mention, which will notify all /// users in a channel. The `@here` mention will also be available, and /// can be used to mention all non-offline users. /// /// **Note**: You probably want this to be disabled for most roles and /// users. - const MENTION_EVERYONE = 0b0000_0000_0000_0010_0000_0000_0000_0000; + MENTION_EVERYONE = 0b0000_0000_0000_0010_0000_0000_0000_0000; /// Allows the usage of custom emojis from other guilds. /// /// This does not dictate whether custom emojis in this guild can be /// used in other guilds. - const USE_EXTERNAL_EMOJIS = 0b0000_0000_0000_0100_0000_0000_0000_0000; + USE_EXTERNAL_EMOJIS = 0b0000_0000_0000_0100_0000_0000_0000_0000; /// Allows the joining of a voice channel. - const CONNECT = 0b0000_0000_0001_0000_0000_0000_0000_0000; + CONNECT = 0b0000_0000_0001_0000_0000_0000_0000_0000; /// Allows the user to speak in a voice channel. - const SPEAK = 0b0000_0000_0010_0000_0000_0000_0000_0000; + SPEAK = 0b0000_0000_0010_0000_0000_0000_0000_0000; /// Allows the muting of members in a voice channel. - const MUTE_MEMBERS = 0b0000_0000_0100_0000_0000_0000_0000_0000; + MUTE_MEMBERS = 0b0000_0000_0100_0000_0000_0000_0000_0000; /// Allows the deafening of members in a voice channel. - const DEAFEN_MEMBERS = 0b0000_0000_1000_0000_0000_0000_0000_0000; + DEAFEN_MEMBERS = 0b0000_0000_1000_0000_0000_0000_0000_0000; /// Allows the moving of members from one voice channel to another. - const MOVE_MEMBERS = 0b0000_0001_0000_0000_0000_0000_0000_0000; + MOVE_MEMBERS = 0b0000_0001_0000_0000_0000_0000_0000_0000; /// Allows the usage of voice-activity-detection in a [voice] channel. /// /// If this is disabled, then [`Member`]s must use push-to-talk. /// /// [`Member`]: ../struct.Member.html /// [voice]: ../enum.ChannelType.html#variant.Voice - const USE_VAD = 0b0000_0010_0000_0000_0000_0000_0000_0000; + USE_VAD = 0b0000_0010_0000_0000_0000_0000_0000_0000; /// Allows members to change their own nickname in the guild. - const CHANGE_NICKNAME = 0b0000_0100_0000_0000_0000_0000_0000_0000; + CHANGE_NICKNAME = 0b0000_0100_0000_0000_0000_0000_0000_0000; /// Allows members to change other members' nicknames. - const MANAGE_NICKNAMES = 0b0000_1000_0000_0000_0000_0000_0000_0000; + MANAGE_NICKNAMES = 0b0000_1000_0000_0000_0000_0000_0000_0000; /// Allows management and editing of roles below their own. - const MANAGE_ROLES = 0b0001_0000_0000_0000_0000_0000_0000_0000; + MANAGE_ROLES = 0b0001_0000_0000_0000_0000_0000_0000_0000; /// Allows management of webhooks. - const MANAGE_WEBHOOKS = 0b0010_0000_0000_0000_0000_0000_0000_0000; + MANAGE_WEBHOOKS = 0b0010_0000_0000_0000_0000_0000_0000_0000; /// Allows management of emojis created without the use of an /// [`Integration`]. /// /// [`Integration`]: ../struct.Integration.html - const MANAGE_EMOJIS = 0b0100_0000_0000_0000_0000_0000_0000_0000; + MANAGE_EMOJIS = 0b0100_0000_0000_0000_0000_0000_0000_0000; } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index de75632..5b98b7b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -329,7 +329,7 @@ pub fn parse_emoji(mention: &str) -> Option<EmojiIdentifier> { match id.parse::<u64>() { Ok(x) => Some(EmojiIdentifier { - name: name, + name, id: EmojiId(x), }), _ => None, diff --git a/src/utils/vec_map.rs b/src/utils/vec_map.rs index 786bf14..70e65f5 100644 --- a/src/utils/vec_map.rs +++ b/src/utils/vec_map.rs @@ -29,11 +29,11 @@ impl<K: PartialEq, V> VecMap<K, V> { match self.pos(&key) { Some(pos) => Entry::Occupied(OccupiedEntry { vec: &mut self.0, - pos: pos, + pos, }), None => Entry::Vacant(VacantEntry { vec: &mut self.0, - key: key, + key, }) } } diff --git a/src/voice/connection.rs b/src/voice/connection.rs index a98dbc7..d447d5c 100644 --- a/src/voice/connection.rs +++ b/src/voice/connection.rs @@ -575,10 +575,10 @@ fn start_threads(client: Arc<Mutex<Client>>, udp: &UdpSocket) -> Result<ThreadIt })?; Ok(ThreadItems { - rx: rx, - udp_close_sender: udp_close_sender, - udp_thread: udp_thread, - ws_close_sender: ws_close_sender, - ws_thread: ws_thread, + rx, + udp_close_sender, + udp_thread, + ws_close_sender, + ws_thread, }) } diff --git a/src/voice/handler.rs b/src/voice/handler.rs index 4124d66..2c9cf48 100644 --- a/src/voice/handler.rs +++ b/src/voice/handler.rs @@ -149,11 +149,11 @@ impl Handler { // Safe as all of these being present was already checked. self.send(VoiceStatus::Connect(ConnectionInfo { - endpoint: endpoint, - guild_id: guild_id, - session_id: session_id, - token: token, - user_id: user_id, + endpoint, + guild_id, + session_id, + token, + user_id, })); true @@ -373,14 +373,14 @@ impl Handler { Handler { channel_id: None, endpoint: None, - guild_id: guild_id, + guild_id, self_deaf: false, self_mute: false, sender: tx, session_id: None, token: None, - user_id: user_id, - ws: ws, + user_id, + ws, } } diff --git a/src/voice/manager.rs b/src/voice/manager.rs index b4b36b0..213a563 100644 --- a/src/voice/manager.rs +++ b/src/voice/manager.rs @@ -31,8 +31,8 @@ impl Manager { pub(crate) fn new(ws: MpscSender<InterMessage>, user_id: UserId) -> Manager { Manager { handlers: HashMap::new(), - user_id: user_id, - ws: ws, + user_id, + ws, } } diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs index c5954c8..3265fb6 100644 --- a/src/voice/streamer.rs +++ b/src/voice/streamer.rs @@ -163,7 +163,7 @@ pub fn dca<P: AsRef<OsStr>>(path: P) -> StdResult<Box<AudioSource>, DcaError> { pub fn opus<R: Read + Send + 'static>(is_stereo: bool, reader: R) -> Box<AudioSource> { Box::new(InputSource { stereo: is_stereo, - reader: reader, + reader, kind: AudioType::Opus, }) } @@ -172,7 +172,7 @@ pub fn opus<R: Read + Send + 'static>(is_stereo: bool, reader: R) -> Box<AudioSo pub fn pcm<R: Read + Send + 'static>(is_stereo: bool, reader: R) -> Box<AudioSource> { Box::new(InputSource { stereo: is_stereo, - reader: reader, + reader, kind: AudioType::Pcm, }) } |