Skip to content

Commit

Permalink
Add CREATE_EVENTS and CREATE_GUILD_EXPRESSIONS permissions
Browse files Browse the repository at this point in the history
Additionally:
 - Rename `MANAGE_EMOJIS_AND_STICKERS` to `MANAGE_GUILD_EXPRESSIONS` and
   deprecate the old name.
 - Adjust documentation to reflect permissions split between creation
   and modification/deletion of events (`{CREATE,MANAGE}_EVENTS`), but
   also emojis and stickers (`{CREATE,MANAGE}_GUILD_EXPRESSIONS`).
 - Deprecate `StickerId::{delete,edit}` in favor of
   `GuildId::{delete,edit}_sticker`, to better reflect object heirarchy.
  • Loading branch information
mkrasnitski committed Nov 17, 2023
1 parent b32bfcf commit cc6378b
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 140 deletions.
10 changes: 8 additions & 2 deletions command_attr/src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ impl Permissions {
"MANAGE_NICKNAMES" => 1 << 27,
"MANAGE_ROLES" => 1 << 28,
"MANAGE_WEBHOOKS" => 1 << 29,
"MANAGE_EMOJIS_AND_STICKERS" => 1 << 30,
"USE_SLASH_COMMANDS" => 1 << 31,
"MANAGE_EMOJIS_AND_STICKERS" | "MANAGE_GUILD_EXPRESSIONS" => 1 << 30,
"USE_SLASH_COMMANDS" | "USE_APPLICATION_COMMANDS" => 1 << 31,
"REQUEST_TO_SPEAK" => 1 << 32,
"MANAGE_EVENTS" => 1 << 33,
"MANAGE_THREADS" => 1 << 34,
Expand All @@ -345,6 +345,12 @@ impl Permissions {
"SEND_MESSAGES_IN_THREADS" => 1 << 38,
"USE_EMBEDDED_ACTIVITIES" => 1 << 39,
"MODERATE_MEMBERS" => 1 << 40,
"VIEW_CREATOR_MONETIZATION_ANALYTICS" => 1 << 41,
"USE_SOUNDBOARD" => 1 << 42,
"CREATE_GUILD_EXPRESSIONS" => 1 << 43,
"CREATE_EVENTS" => 1 << 44,
"USE_EXTERNAL_SOUNDS" => 1 << 45,
"SEND_VOICE_MESSAGES" => 1 << 46,
"SET_VOICE_CHANNEL_STATUS" => 1 << 48,
_ => return None,
}))
Expand Down
6 changes: 3 additions & 3 deletions src/builder/create_scheduled_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ impl<'a> Builder for CreateScheduledEvent<'a> {

/// Creates a new scheduled event in the guild with the data set, if any.
///
/// **Note**: Requires the [Manage Events] permission.
/// **Note**: Requires the [Create Events] permission.
///
/// # Errors
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
///
/// [Manage Events]: Permissions::MANAGE_EVENTS
/// [Create Events]: Permissions::CREATE_EVENTS
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
#[cfg(feature = "cache")]
crate::utils::user_has_guild_perms(&cache_http, ctx, Permissions::MANAGE_EVENTS).await?;
crate::utils::user_has_guild_perms(&cache_http, ctx, Permissions::CREATE_EVENTS).await?;

cache_http.http().create_scheduled_event(ctx, &self, self.audit_log_reason).await
}
Expand Down
12 changes: 4 additions & 8 deletions src/builder/create_sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,22 @@ impl<'a> Builder for CreateSticker<'a> {

/// Creates a new sticker in the guild with the data set, if any.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
/// **Note**: Requires the [Create Guild Expressions] permission.
///
/// # Errors
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
#[cfg(feature = "cache")]
crate::utils::user_has_guild_perms(
&cache_http,
ctx,
Permissions::MANAGE_EMOJIS_AND_STICKERS,
)
.await?;
crate::utils::user_has_guild_perms(&cache_http, ctx, Permissions::CREATE_GUILD_EXPRESSIONS)
.await?;

let map = vec![("name", self.name), ("tags", self.tags), ("description", self.description)];

Expand Down
7 changes: 3 additions & 4 deletions src/builder/edit_scheduled_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,21 @@ impl<'a> Builder for EditScheduledEvent<'a> {

/// Modifies a scheduled event in the guild with the data set, if any.
///
/// **Note**: Requires the [Manage Events] permission.
/// **Note**: If the event was created by the current user, requires either [Create Events] or
/// the [Manage Events] permission. Otherwise, the [Manage Events] permission is required.
///
/// # Errors
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
///
/// [Create Events]: Permissions::CREATE_EVENTS
/// [Manage Events]: Permissions::MANAGE_EVENTS
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
#[cfg(feature = "cache")]
crate::utils::user_has_guild_perms(&cache_http, ctx.0, Permissions::MANAGE_EVENTS).await?;

cache_http.http().edit_scheduled_event(ctx.0, ctx.1, &self, self.audit_log_reason).await
}
}
7 changes: 5 additions & 2 deletions src/builder/edit_sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ impl<'a> Builder for EditSticker<'a> {

/// Edits the sticker.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
/// **Note**: If the sticker was created by the current user, requires either the [Create Guild
/// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
/// Expressions] permission is required.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
/// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
async fn execute(
self,
cache_http: impl CacheHttp,
Expand Down
33 changes: 16 additions & 17 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ impl Http {
///
/// View the source code for [`Guild::create_emoji`] method to see what fields this requires.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
/// **Note**: Requires the [Create Guild Expressions] permission.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
pub async fn create_emoji(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -821,9 +821,9 @@ impl Http {
///
/// Refer to Discord's docs for field information.
///
/// **Note**: Requires the [Manage Events] permission.
/// **Note**: Requires the [Create Events] permission.
///
/// [Manage Events]: Permissions::MANAGE_EVENTS
/// [Create Events]: Permissions::CREATE_EVENTS
pub async fn create_scheduled_event(
&self,
guild_id: GuildId,
Expand All @@ -846,9 +846,9 @@ impl Http {

/// Creates a sticker.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
/// **Note**: Requires the [Create Guild Expressions] permission.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
pub async fn create_sticker<'a>(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -959,6 +959,8 @@ impl Http {
}

/// Deletes an emoji from a server.
///
/// See [`GuildId::edit_emoji`] for permissions requirements.
pub async fn delete_emoji(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -1326,9 +1328,7 @@ impl Http {

/// Deletes a sticker from a server.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// See [`GuildId::delete_sticker`] for permissions requirements.
pub async fn delete_sticker(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -1470,6 +1470,8 @@ impl Http {
}

/// Changes emoji information.
///
/// See [`GuildId::edit_emoji`] for permissions requirements.
pub async fn edit_emoji(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -2076,9 +2078,7 @@ impl Http {

/// Changes a sticker in a guild.
///
/// **Note**: Requires the [Manage Emojis and Stickers] permission.
///
/// [Manage Emojis and Stickers]: Permissions::MANAGE_EMOJIS_AND_STICKERS
/// See [`GuildId::edit_sticker`] for permissions requirements.
pub async fn edit_sticker(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -3456,9 +3456,9 @@ impl Http {

/// Gets a scheduled event by Id.
///
/// **Note**: Requires the [Manage Events] permission.
/// **Note**: Requires the [View Channel] permission for the channel associated with the event.
///
/// [Manage Events]: Permissions::MANAGE_EVENTS
/// [View Channel]: Permissions::VIEW_CHANNEL
pub async fn get_scheduled_event(
&self,
guild_id: GuildId,
Expand All @@ -3481,9 +3481,9 @@ impl Http {

/// Gets a list of all scheduled events for the corresponding guild.
///
/// **Note**: Requires the [Manage Events] permission.
/// **Note**: Requires the [View Channel] permission at the guild level.
///
/// [Manage Events]: Permissions::MANAGE_EVENTS
/// [View Channel]: Permissions::VIEW_CHANNEL
pub async fn get_scheduled_events(
&self,
guild_id: GuildId,
Expand Down Expand Up @@ -3514,7 +3514,6 @@ impl Http {
/// be populated with [`Guild Member`] information, if the interested user is a member of the
/// guild the event takes place in.
///
/// [`UserId`]: crate::model::id::UserId
/// [`member`]: ScheduledEventUser::member
/// [`Guild Member`]: crate::model::guild::Member
pub async fn get_scheduled_event_users(
Expand Down
15 changes: 10 additions & 5 deletions src/model/guild/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ pub struct Emoji {
impl Emoji {
/// Deletes the emoji. This method requires the cache to fetch the guild ID.
///
/// **Note**: The [Manage Emojis and Stickers] permission is required.
///
/// **Note**: If the emoji was created by the current user, requires either the [Create Guild
/// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
/// Expressions] permission is required.
///
/// # Examples
///
Expand Down Expand Up @@ -87,7 +88,8 @@ impl Emoji {
/// Returns [`Error::Http`] if the current user lacks permission, or may return
/// [`ModelError::ItemMissing`] if the emoji is not in the cache.
///
/// [Manage Emojis and Stickers]: crate::model::permissions::Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: crate::model::Permissions::CREATE_GUILD_EXPRESSIONS
/// [Manage Guild Expressions]: crate::model::Permissions::MANAGE_GUILD_EXPRESSIONS
#[cfg(feature = "cache")]
#[inline]
pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()> {
Expand All @@ -98,14 +100,17 @@ impl Emoji {
/// Edits the emoji by updating it with a new name. This method requires the cache to fetch the
/// guild ID.
///
/// **Note**: The [Manage Emojis and Stickers] permission is required.
/// **Note**: If the emoji was created by the current user, requires either the [Create Guild
/// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
/// Expressions] permission is required.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if an invalid name is
/// given.
///
/// [Manage Emojis and Stickers]: crate::model::permissions::Permissions::MANAGE_EMOJIS_AND_STICKERS
/// [Create Guild Expressions]: crate::model::Permissions::CREATE_GUILD_EXPRESSIONS
/// [Manage Guild Expressions]: crate::model::Permissions::MANAGE_GUILD_EXPRESSIONS
#[cfg(feature = "cache")]
pub async fn edit(&mut self, cache_http: impl CacheHttp, name: &str) -> Result<()> {
let guild_id = self.try_find_guild_id(&cache_http)?;
Expand Down
Loading

0 comments on commit cc6378b

Please sign in to comment.