Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing permissions #3006

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public enum ChannelPermission : ulong
/// </summary>
CreateEvents = 1L << 44,

/// <summary>
/// Allows the usage of custom soundboard sounds from other servers.
/// </summary>
UseExternalSounds = 1L << 45,

/// <summary>
/// Allows sending voice messages.
/// </summary>
Expand Down
21 changes: 14 additions & 7 deletions src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public struct ChannelPermissions
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for voice channels.
/// </summary>
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);

/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for stage channels.
/// </summary>
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);

/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels.
Expand Down Expand Up @@ -156,6 +156,8 @@ public static ChannelPermissions All(IChannel channel)
public bool SendPolls => Permissions.GetValue(RawValue, ChannelPermission.SendPolls);
/// <summary> If <see langword="true"/>, a user-installed application can send public responses.</summary>
public bool UserExternalApps => Permissions.GetValue(RawValue, ChannelPermission.UseExternalApps);
/// <summary> If <see langword="true"/>, a user-installed application can send public responses.</summary>
public bool UseExternalSounds => Permissions.GetValue(RawValue, ChannelPermission.UseExternalSounds);

/// <summary> Creates a new <see cref="ChannelPermissions"/> with the provided packed value.</summary>
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
Expand Down Expand Up @@ -197,7 +199,8 @@ private ChannelPermissions(ulong initialValue,
bool? useClydeAI = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null,
bool? useExternalApps = null)
bool? useExternalApps = null,
bool? useExternalSounds = null)
{
ulong value = initialValue;

Expand Down Expand Up @@ -238,6 +241,7 @@ private ChannelPermissions(ulong initialValue,
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;
}
Expand Down Expand Up @@ -280,12 +284,13 @@ public ChannelPermissions(
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)
{ }

/// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions.</summary>
Expand Down Expand Up @@ -326,7 +331,8 @@ public ChannelPermissions Modify(
bool? useClydeAI = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null,
bool? useExternalApps = null)
bool? useExternalApps = null,
bool? useExternalSounds = null)
=> new ChannelPermissions(RawValue,
createInstantInvite,
manageChannel,
Expand Down Expand Up @@ -364,7 +370,8 @@ public ChannelPermissions Modify(
useClydeAI,
setVoiceChannelStatus,
sendPolls,
useExternalApps);
useExternalApps,
useExternalSounds);

public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission);

Expand Down
10 changes: 10 additions & 0 deletions src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ public enum GuildPermission : ulong
/// </summary>
CreateGuildExpressions = 1L << 43,

/// <summary>
/// Allows members to edit and cancel events in this channel.
/// </summary>
CreateEvents = 1L << 44,

/// <summary>
/// Allows the usage of custom soundboard sounds from other servers.
/// </summary>
UseExternalSounds = 1L << 45,

/// <summary>
/// Allows sending voice messages.
/// </summary>
Expand Down
25 changes: 19 additions & 6 deletions src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public struct GuildPermissions
public bool SendPolls => Permissions.GetValue(RawValue, GuildPermission.SendPolls);
/// <summary> If <see langword="true"/>, a user-installed application can send public responses.</summary>
public bool UserExternalApps => Permissions.GetValue(RawValue, GuildPermission.UseExternalApps);

/// <summary> If <see langword="true"/>, a user can send soundboard sounds from other servers.</summary>
public bool UserExternalSounds => Permissions.GetValue(RawValue, GuildPermission.UseExternalSounds);
/// <summary> If <see langword="true"/>, a user can create events.</summary>
public bool CreateEvents => Permissions.GetValue(RawValue, GuildPermission.CreateEvents);

/// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary>
public GuildPermissions(ulong rawValue) { RawValue = rawValue; }
Expand Down Expand Up @@ -177,7 +180,9 @@ private GuildPermissions(ulong initialValue,
bool? createGuildExpressions = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null,
bool? useExternalApps = null)
bool? useExternalApps = null,
bool? useExternalSounds = null,
bool? createEvents = null)
{
ulong value = initialValue;

Expand Down Expand Up @@ -230,6 +235,8 @@ private GuildPermissions(ulong initialValue,
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;
}
Expand Down Expand Up @@ -284,7 +291,9 @@ public GuildPermissions(
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,
Expand Down Expand Up @@ -334,7 +343,9 @@ public GuildPermissions(
createGuildExpressions: createGuildExpressions,
setVoiceChannelStatus: setVoiceChannelStatus,
sendPolls: sendPolls,
useExternalApps: useExternalApps)
useExternalApps: useExternalApps,
useExternalSounds: useExternalSounds,
createEvents: createEvents)
{ }

/// <summary> Creates a new <see cref="GuildPermissions"/> from this one, changing the provided non-null permissions. </summary>
Expand Down Expand Up @@ -387,14 +398,16 @@ public GuildPermissions Modify(
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);

/// <summary>
/// Returns a value that indicates if a specific <see cref="GuildPermission"/> is enabled
Expand Down
2 changes: 2 additions & 0 deletions test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void AssertFlag(Func<ChannelPermissions> cstr, ChannelPermission flag)
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);
}

/// <summary>
Expand Down Expand Up @@ -166,6 +167,7 @@ void AssertUtil(ChannelPermission permission,
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));
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void AssertFlag(Func<GuildPermissions> cstr, GuildPermission flag)
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);
}

/// <summary>
Expand Down Expand Up @@ -194,6 +196,8 @@ void AssertUtil(GuildPermission permission,
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));
}
}
}