From 6b92cc2b08aff77ba6eb95fd56aab23aab9026ce Mon Sep 17 00:00:00 2001 From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> Date: Sat, 14 Sep 2024 19:48:42 +0300 Subject: [PATCH] Add missing permissions (#3006) * yes * no way tests actually save the day --- .../Entities/Permissions/ChannelPermission.cs | 5 ++++ .../Permissions/ChannelPermissions.cs | 21 ++++++++++------ .../Entities/Permissions/GuildPermission.cs | 10 ++++++++ .../Entities/Permissions/GuildPermissions.cs | 25 ++++++++++++++----- .../ChannelPermissionsTests.cs | 2 ++ .../GuildPermissionsTests.cs | 4 +++ 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs b/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs index 01602b4d..f490f8b4 100644 --- a/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs +++ b/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs @@ -178,6 +178,11 @@ namespace Discord /// CreateEvents = 1L << 44, + /// + /// Allows the usage of custom soundboard sounds from other servers. + /// + UseExternalSounds = 1L << 45, + /// /// Allows sending voice messages. /// diff --git a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs index b861b4bf..4f94b9eb 100644 --- a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs @@ -23,12 +23,12 @@ namespace Discord /// /// Gets a that grants all permissions for voice channels. /// - public static readonly ChannelPermissions Voice = new(0b111_110001_001010_001010_110011_111101_111111_111101_010001); + public static readonly ChannelPermissions Voice = new(0b111_110101_001010_001010_110011_111101_111111_111101_010001); /// /// Gets a that grants all permissions for stage channels. /// - public static readonly ChannelPermissions Stage = new(0b110_110000_000010_001110_010001_010101_111111_111001_010001); + public static readonly ChannelPermissions Stage = new(0b110_110100_000010_001110_010001_010101_111111_111001_010001); /// /// Gets a that grants all permissions for category channels. @@ -156,6 +156,8 @@ namespace Discord public bool SendPolls => Permissions.GetValue(RawValue, ChannelPermission.SendPolls); /// If , a user-installed application can send public responses. public bool UserExternalApps => Permissions.GetValue(RawValue, ChannelPermission.UseExternalApps); + /// If , a user-installed application can send public responses. + public bool UseExternalSounds => Permissions.GetValue(RawValue, ChannelPermission.UseExternalSounds); /// Creates a new with the provided packed value. public ChannelPermissions(ulong rawValue) { RawValue = rawValue; } @@ -197,7 +199,8 @@ namespace Discord bool? useClydeAI = null, bool? setVoiceChannelStatus = null, bool? sendPolls = null, - bool? useExternalApps = null) + bool? useExternalApps = null, + bool? useExternalSounds = null) { ulong value = initialValue; @@ -238,6 +241,7 @@ namespace Discord Permissions.SetValue(ref value, setVoiceChannelStatus, ChannelPermission.SetVoiceChannelStatus); Permissions.SetValue(ref value, sendPolls, ChannelPermission.SendPolls); Permissions.SetValue(ref value, useExternalApps, ChannelPermission.UseExternalApps); + Permissions.SetValue(ref value, useExternalSounds, ChannelPermission.UseExternalSounds); RawValue = value; } @@ -280,12 +284,13 @@ namespace Discord bool useClydeAI = false, bool setVoiceChannelStatus = false, bool sendPolls = false, - bool useExternalApps = false) + bool useExternalApps = false, + bool useExternalSounds = false) : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, stream, manageRoles, manageWebhooks, useApplicationCommands, requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads, - startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls, useExternalApps) + startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls, useExternalApps, useExternalSounds) { } /// Creates a new from this one, changing the provided non-null permissions. @@ -326,7 +331,8 @@ namespace Discord bool? useClydeAI = null, bool? setVoiceChannelStatus = null, bool? sendPolls = null, - bool? useExternalApps = null) + bool? useExternalApps = null, + bool? useExternalSounds = null) => new ChannelPermissions(RawValue, createInstantInvite, manageChannel, @@ -364,7 +370,8 @@ namespace Discord useClydeAI, setVoiceChannelStatus, sendPolls, - useExternalApps); + useExternalApps, + useExternalSounds); public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission); diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs b/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs index 9b5b0cda..43ea1895 100644 --- a/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs +++ b/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs @@ -268,6 +268,16 @@ namespace Discord /// CreateGuildExpressions = 1L << 43, + /// + /// Allows members to edit and cancel events in this channel. + /// + CreateEvents = 1L << 44, + + /// + /// Allows the usage of custom soundboard sounds from other servers. + /// + UseExternalSounds = 1L << 45, + /// /// Allows sending voice messages. /// diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs index 666441cb..9e5280a5 100644 --- a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs @@ -120,7 +120,10 @@ namespace Discord public bool SendPolls => Permissions.GetValue(RawValue, GuildPermission.SendPolls); /// If , a user-installed application can send public responses. public bool UserExternalApps => Permissions.GetValue(RawValue, GuildPermission.UseExternalApps); - + /// If , a user can send soundboard sounds from other servers. + public bool UserExternalSounds => Permissions.GetValue(RawValue, GuildPermission.UseExternalSounds); + /// If , a user can create events. + public bool CreateEvents => Permissions.GetValue(RawValue, GuildPermission.CreateEvents); /// Creates a new with the provided packed value. public GuildPermissions(ulong rawValue) { RawValue = rawValue; } @@ -177,7 +180,9 @@ namespace Discord bool? createGuildExpressions = null, bool? setVoiceChannelStatus = null, bool? sendPolls = null, - bool? useExternalApps = null) + bool? useExternalApps = null, + bool? useExternalSounds = null, + bool? createEvents = null) { ulong value = initialValue; @@ -230,6 +235,8 @@ namespace Discord Permissions.SetValue(ref value, setVoiceChannelStatus, GuildPermission.SetVoiceChannelStatus); Permissions.SetValue(ref value, sendPolls, GuildPermission.SendPolls); Permissions.SetValue(ref value, useExternalApps, GuildPermission.UseExternalApps); + Permissions.SetValue(ref value, useExternalSounds, GuildPermission.UseExternalSounds); + Permissions.SetValue(ref value, createEvents, GuildPermission.CreateEvents); RawValue = value; } @@ -284,7 +291,9 @@ namespace Discord bool createGuildExpressions = false, bool setVoiceChannelStatus = false, bool sendPolls = false, - bool useExternalApps = false) + bool useExternalApps = false, + bool useExternalSounds = false, + bool createEvents = false) : this(0, createInstantInvite: createInstantInvite, manageRoles: manageRoles, @@ -334,7 +343,9 @@ namespace Discord createGuildExpressions: createGuildExpressions, setVoiceChannelStatus: setVoiceChannelStatus, sendPolls: sendPolls, - useExternalApps: useExternalApps) + useExternalApps: useExternalApps, + useExternalSounds: useExternalSounds, + createEvents: createEvents) { } /// Creates a new from this one, changing the provided non-null permissions. @@ -387,14 +398,16 @@ namespace Discord bool? createGuildExpressions = null, bool? setVoiceChannelStatus = null, bool? sendPolls = null, - bool? useExternalApps = null) + bool? useExternalApps = null, + bool? useExternalSounds = null, + bool? createEvents = null) => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, viewAuditLog, viewGuildInsights, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, stream, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojisAndStickers, useApplicationCommands, requestToSpeak, manageEvents, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads, startEmbeddedActivities, moderateMembers, useSoundboard, viewMonetizationAnalytics, sendVoiceMessages, useClydeAI, createGuildExpressions, setVoiceChannelStatus, - sendPolls, useExternalApps); + sendPolls, useExternalApps, useExternalSounds, createEvents); /// /// Returns a value that indicates if a specific is enabled diff --git a/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs b/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs index e47af0d4..f7c55c6c 100644 --- a/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs +++ b/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs @@ -97,6 +97,7 @@ namespace Discord AssertFlag(() => new ChannelPermissions(setVoiceChannelStatus: true), ChannelPermission.SetVoiceChannelStatus); AssertFlag(() => new ChannelPermissions(sendPolls: true), ChannelPermission.SendPolls); AssertFlag(() => new ChannelPermissions(useExternalApps: true), ChannelPermission.UseExternalApps); + AssertFlag(() => new ChannelPermissions(useExternalSounds: true), ChannelPermission.UseExternalSounds); } /// @@ -166,6 +167,7 @@ namespace Discord AssertUtil(ChannelPermission.SetVoiceChannelStatus, x => x.SetVoiceChannelStatus, (p, enable) => p.Modify(setVoiceChannelStatus: enable)); AssertUtil(ChannelPermission.SendPolls, x => x.SendPolls, (p, enable) => p.Modify(sendPolls: enable)); AssertUtil(ChannelPermission.UseExternalApps, x => x.UserExternalApps, (p, enable) => p.Modify(useExternalApps: enable)); + AssertUtil(ChannelPermission.UseExternalSounds, x => x.UseExternalSounds, (p, enable) => p.Modify(useExternalSounds: enable)); } /// diff --git a/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs b/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs index a35950dd..438f69f5 100644 --- a/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs +++ b/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs @@ -108,6 +108,8 @@ namespace Discord AssertFlag(() => new GuildPermissions(setVoiceChannelStatus: true), GuildPermission.SetVoiceChannelStatus); AssertFlag(() => new GuildPermissions(sendPolls: true), GuildPermission.SendPolls); AssertFlag(() => new GuildPermissions(useExternalApps: true), GuildPermission.UseExternalApps); + AssertFlag(() => new GuildPermissions(useExternalSounds: true), GuildPermission.UseExternalSounds); + AssertFlag(() => new GuildPermissions(createEvents: true), GuildPermission.CreateEvents); } /// @@ -194,6 +196,8 @@ namespace Discord AssertUtil(GuildPermission.SetVoiceChannelStatus, x => x.SetVoiceChannelStatus, (p, enable) => p.Modify(setVoiceChannelStatus: enable)); AssertUtil(GuildPermission.SendPolls, x => x.SendPolls, (p, enable) => p.Modify(sendPolls: enable)); AssertUtil(GuildPermission.UseExternalApps, x => x.UserExternalApps, (p, enable) => p.Modify(useExternalApps: enable)); + AssertUtil(GuildPermission.UseExternalSounds, x => x.UserExternalSounds, (p, enable) => p.Modify(useExternalSounds: enable)); + AssertUtil(GuildPermission.CreateEvents, x => x.CreateEvents, (p, enable) => p.Modify(createEvents: enable)); } } }