[Feature] Add UseExternalApps permission (#2941)

This commit is contained in:
Mihail Gribkov
2024-06-10 23:57:31 +03:00
committed by GitHub
parent 51f59bf185
commit f7f29d5cc8
6 changed files with 44 additions and 16 deletions

View File

@@ -197,5 +197,10 @@ namespace Discord
/// Allows sending polls.
/// </summary>
SendPolls = 1L << 49,
/// <summary>
/// Allows user-installed apps to send public responses.
/// </summary>
UseExternalApps = 1L << 50,
}
}

View File

@@ -18,17 +18,17 @@ namespace Discord
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for text channels.
/// </summary>
public static readonly ChannelPermissions Text = new(0b10_110001_001111_110010_110011_111101_111111_111101_010001);
public static readonly ChannelPermissions Text = new(0b110_110001_001111_110010_110011_111101_111111_111101_010001);
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for voice channels.
/// </summary>
public static readonly ChannelPermissions Voice = new(0b11_110001_001010_001010_110011_111101_111111_111101_010001);
public static readonly ChannelPermissions Voice = new(0b111_110001_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(0b10_110000_000010_001110_010001_010101_111111_111001_010001);
public static readonly ChannelPermissions Stage = new(0b110_110000_000010_001110_010001_010101_111111_111001_010001);
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels.
@@ -154,6 +154,8 @@ namespace Discord
public bool SetVoiceChannelStatus => Permissions.GetValue(RawValue, ChannelPermission.SetVoiceChannelStatus);
/// <summary> If <see langword="true"/>, a user can send polls.</summary>
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> Creates a new <see cref="ChannelPermissions"/> with the provided packed value.</summary>
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
@@ -194,7 +196,8 @@ namespace Discord
bool? sendVoiceMessages = null,
bool? useClydeAI = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null)
bool? sendPolls = null,
bool? useExternalApps = null)
{
ulong value = initialValue;
@@ -234,6 +237,7 @@ namespace Discord
Permissions.SetValue(ref value, useClydeAI, ChannelPermission.UseClydeAI);
Permissions.SetValue(ref value, setVoiceChannelStatus, ChannelPermission.SetVoiceChannelStatus);
Permissions.SetValue(ref value, sendPolls, ChannelPermission.SendPolls);
Permissions.SetValue(ref value, useExternalApps, ChannelPermission.UseExternalApps);
RawValue = value;
}
@@ -275,12 +279,13 @@ namespace Discord
bool sendVoiceMessages = false,
bool useClydeAI = false,
bool setVoiceChannelStatus = false,
bool sendPolls = false)
bool sendPolls = false,
bool useExternalApps = 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)
startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls, useExternalApps)
{ }
/// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions.</summary>
@@ -320,7 +325,8 @@ namespace Discord
bool? sendVoiceMessages = null,
bool? useClydeAI = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null)
bool? sendPolls = null,
bool? useExternalApps = null)
=> new ChannelPermissions(RawValue,
createInstantInvite,
manageChannel,
@@ -357,7 +363,8 @@ namespace Discord
sendVoiceMessages,
useClydeAI,
setVoiceChannelStatus,
sendPolls);
sendPolls,
useExternalApps);
public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission);

View File

@@ -287,5 +287,10 @@ namespace Discord
/// Allows sending polls.
/// </summary>
SendPolls = 1L << 49,
/// <summary>
/// Allows user-installed apps to send public responses.
/// </summary>
UseExternalApps = 1L << 50,
}
}

View File

@@ -118,6 +118,8 @@ namespace Discord
public bool SetVoiceChannelStatus => Permissions.GetValue(RawValue, GuildPermission.SetVoiceChannelStatus);
/// <summary> If <see langword="true"/>, a user can send polls.</summary>
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> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary>
@@ -174,7 +176,8 @@ namespace Discord
bool? useClydeAI = null,
bool? createGuildExpressions = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null)
bool? sendPolls = null,
bool? useExternalApps = null)
{
ulong value = initialValue;
@@ -226,6 +229,7 @@ namespace Discord
Permissions.SetValue(ref value, createGuildExpressions, GuildPermission.CreateGuildExpressions);
Permissions.SetValue(ref value, setVoiceChannelStatus, GuildPermission.SetVoiceChannelStatus);
Permissions.SetValue(ref value, sendPolls, GuildPermission.SendPolls);
Permissions.SetValue(ref value, useExternalApps, GuildPermission.UseExternalApps);
RawValue = value;
}
@@ -279,7 +283,8 @@ namespace Discord
bool useClydeAI = false,
bool createGuildExpressions = false,
bool setVoiceChannelStatus = false,
bool sendPolls = false)
bool sendPolls = false,
bool useExternalApps = false)
: this(0,
createInstantInvite: createInstantInvite,
manageRoles: manageRoles,
@@ -328,7 +333,8 @@ namespace Discord
useClydeAI: useClydeAI,
createGuildExpressions: createGuildExpressions,
setVoiceChannelStatus: setVoiceChannelStatus,
sendPolls: sendPolls)
sendPolls: sendPolls,
useExternalApps: useExternalApps)
{ }
/// <summary> Creates a new <see cref="GuildPermissions"/> from this one, changing the provided non-null permissions. </summary>
@@ -380,14 +386,15 @@ namespace Discord
bool? useClydeAI = null,
bool? createGuildExpressions = null,
bool? setVoiceChannelStatus = null,
bool? sendPolls = null)
bool? sendPolls = null,
bool? useExternalApps = 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);
sendPolls, useExternalApps);
/// <summary>
/// Returns a value that indicates if a specific <see cref="GuildPermission"/> is enabled

View File

@@ -47,7 +47,7 @@ namespace Discord
}
/// <summary>
/// Tests the behavior of the <see cref="Discord.ChannelPermissions"/> constructor for each
/// Tests the behavior of the <see cref="ChannelPermissions"/> constructor for each
/// of it's flags.
/// </summary>
[Fact]
@@ -96,10 +96,11 @@ namespace Discord
AssertFlag(() => new ChannelPermissions(useClydeAI: true), ChannelPermission.UseClydeAI);
AssertFlag(() => new ChannelPermissions(setVoiceChannelStatus: true), ChannelPermission.SetVoiceChannelStatus);
AssertFlag(() => new ChannelPermissions(sendPolls: true), ChannelPermission.SendPolls);
AssertFlag(() => new ChannelPermissions(useExternalApps: true), ChannelPermission.UseExternalApps);
}
/// <summary>
/// Tests the behavior of <see cref="Discord.ChannelPermissions.Modify"/>
/// Tests the behavior of <see cref="ChannelPermissions.Modify"/>
/// with each of the parameters.
/// </summary>
[Fact]
@@ -164,6 +165,7 @@ namespace Discord
AssertUtil(ChannelPermission.UseClydeAI, x => x.UseClydeAI, (p, enable) => p.Modify(useClydeAI: enable));
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));
}
/// <summary>

View File

@@ -107,10 +107,11 @@ namespace Discord
AssertFlag(() => new GuildPermissions(createGuildExpressions: true), GuildPermission.CreateGuildExpressions);
AssertFlag(() => new GuildPermissions(setVoiceChannelStatus: true), GuildPermission.SetVoiceChannelStatus);
AssertFlag(() => new GuildPermissions(sendPolls: true), GuildPermission.SendPolls);
AssertFlag(() => new GuildPermissions(useExternalApps: true), GuildPermission.UseExternalApps);
}
/// <summary>
/// Tests the behavior of <see cref="Discord.GuildPermissions.Modify(bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?, bool?)"/>
/// Tests the behavior of <see cref="GuildPermissions.Modify"/>
/// with each of the parameters.
/// </summary>
[Fact]
@@ -192,6 +193,7 @@ namespace Discord
AssertUtil(GuildPermission.CreateGuildExpressions, x => x.CreateGuildExpressions, (p, enable) => p.Modify(createGuildExpressions: enable));
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));
}
}
}