Skip to content

Commit f7f29d5

Browse files
authored
[Feature] Add UseExternalApps permission (#2941)
1 parent 51f59bf commit f7f29d5

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,10 @@ public enum ChannelPermission : ulong
197197
/// Allows sending polls.
198198
/// </summary>
199199
SendPolls = 1L << 49,
200+
201+
/// <summary>
202+
/// Allows user-installed apps to send public responses.
203+
/// </summary>
204+
UseExternalApps = 1L << 50,
200205
}
201206
}

src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ public struct ChannelPermissions
1818
/// <summary>
1919
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for text channels.
2020
/// </summary>
21-
public static readonly ChannelPermissions Text = new(0b10_110001_001111_110010_110011_111101_111111_111101_010001);
21+
public static readonly ChannelPermissions Text = new(0b110_110001_001111_110010_110011_111101_111111_111101_010001);
2222

2323
/// <summary>
2424
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for voice channels.
2525
/// </summary>
26-
public static readonly ChannelPermissions Voice = new(0b11_110001_001010_001010_110011_111101_111111_111101_010001);
26+
public static readonly ChannelPermissions Voice = new(0b111_110001_001010_001010_110011_111101_111111_111101_010001);
2727

2828
/// <summary>
2929
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for stage channels.
3030
/// </summary>
31-
public static readonly ChannelPermissions Stage = new(0b10_110000_000010_001110_010001_010101_111111_111001_010001);
31+
public static readonly ChannelPermissions Stage = new(0b110_110000_000010_001110_010001_010101_111111_111001_010001);
3232

3333
/// <summary>
3434
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels.
@@ -154,6 +154,8 @@ public static ChannelPermissions All(IChannel channel)
154154
public bool SetVoiceChannelStatus => Permissions.GetValue(RawValue, ChannelPermission.SetVoiceChannelStatus);
155155
/// <summary> If <see langword="true"/>, a user can send polls.</summary>
156156
public bool SendPolls => Permissions.GetValue(RawValue, ChannelPermission.SendPolls);
157+
/// <summary> If <see langword="true"/>, a user-installed application can send public responses.</summary>
158+
public bool UserExternalApps => Permissions.GetValue(RawValue, ChannelPermission.UseExternalApps);
157159

158160
/// <summary> Creates a new <see cref="ChannelPermissions"/> with the provided packed value.</summary>
159161
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
@@ -194,7 +196,8 @@ private ChannelPermissions(ulong initialValue,
194196
bool? sendVoiceMessages = null,
195197
bool? useClydeAI = null,
196198
bool? setVoiceChannelStatus = null,
197-
bool? sendPolls = null)
199+
bool? sendPolls = null,
200+
bool? useExternalApps = null)
198201
{
199202
ulong value = initialValue;
200203

@@ -234,6 +237,7 @@ private ChannelPermissions(ulong initialValue,
234237
Permissions.SetValue(ref value, useClydeAI, ChannelPermission.UseClydeAI);
235238
Permissions.SetValue(ref value, setVoiceChannelStatus, ChannelPermission.SetVoiceChannelStatus);
236239
Permissions.SetValue(ref value, sendPolls, ChannelPermission.SendPolls);
240+
Permissions.SetValue(ref value, useExternalApps, ChannelPermission.UseExternalApps);
237241

238242
RawValue = value;
239243
}
@@ -275,12 +279,13 @@ public ChannelPermissions(
275279
bool sendVoiceMessages = false,
276280
bool useClydeAI = false,
277281
bool setVoiceChannelStatus = false,
278-
bool sendPolls = false)
282+
bool sendPolls = false,
283+
bool useExternalApps = false)
279284
: this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages,
280285
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect,
281286
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, stream, manageRoles, manageWebhooks,
282287
useApplicationCommands, requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads,
283-
startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls)
288+
startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls, useExternalApps)
284289
{ }
285290

286291
/// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions.</summary>
@@ -320,7 +325,8 @@ public ChannelPermissions Modify(
320325
bool? sendVoiceMessages = null,
321326
bool? useClydeAI = null,
322327
bool? setVoiceChannelStatus = null,
323-
bool? sendPolls = null)
328+
bool? sendPolls = null,
329+
bool? useExternalApps = null)
324330
=> new ChannelPermissions(RawValue,
325331
createInstantInvite,
326332
manageChannel,
@@ -357,7 +363,8 @@ public ChannelPermissions Modify(
357363
sendVoiceMessages,
358364
useClydeAI,
359365
setVoiceChannelStatus,
360-
sendPolls);
366+
sendPolls,
367+
useExternalApps);
361368

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

src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,10 @@ public enum GuildPermission : ulong
287287
/// Allows sending polls.
288288
/// </summary>
289289
SendPolls = 1L << 49,
290+
291+
/// <summary>
292+
/// Allows user-installed apps to send public responses.
293+
/// </summary>
294+
UseExternalApps = 1L << 50,
290295
}
291296
}

src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public struct GuildPermissions
118118
public bool SetVoiceChannelStatus => Permissions.GetValue(RawValue, GuildPermission.SetVoiceChannelStatus);
119119
/// <summary> If <see langword="true"/>, a user can send polls.</summary>
120120
public bool SendPolls => Permissions.GetValue(RawValue, GuildPermission.SendPolls);
121+
/// <summary> If <see langword="true"/>, a user-installed application can send public responses.</summary>
122+
public bool UserExternalApps => Permissions.GetValue(RawValue, GuildPermission.UseExternalApps);
121123

122124

123125
/// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary>
@@ -174,7 +176,8 @@ private GuildPermissions(ulong initialValue,
174176
bool? useClydeAI = null,
175177
bool? createGuildExpressions = null,
176178
bool? setVoiceChannelStatus = null,
177-
bool? sendPolls = null)
179+
bool? sendPolls = null,
180+
bool? useExternalApps = null)
178181
{
179182
ulong value = initialValue;
180183

@@ -226,6 +229,7 @@ private GuildPermissions(ulong initialValue,
226229
Permissions.SetValue(ref value, createGuildExpressions, GuildPermission.CreateGuildExpressions);
227230
Permissions.SetValue(ref value, setVoiceChannelStatus, GuildPermission.SetVoiceChannelStatus);
228231
Permissions.SetValue(ref value, sendPolls, GuildPermission.SendPolls);
232+
Permissions.SetValue(ref value, useExternalApps, GuildPermission.UseExternalApps);
229233

230234
RawValue = value;
231235
}
@@ -279,7 +283,8 @@ public GuildPermissions(
279283
bool useClydeAI = false,
280284
bool createGuildExpressions = false,
281285
bool setVoiceChannelStatus = false,
282-
bool sendPolls = false)
286+
bool sendPolls = false,
287+
bool useExternalApps = false)
283288
: this(0,
284289
createInstantInvite: createInstantInvite,
285290
manageRoles: manageRoles,
@@ -328,7 +333,8 @@ public GuildPermissions(
328333
useClydeAI: useClydeAI,
329334
createGuildExpressions: createGuildExpressions,
330335
setVoiceChannelStatus: setVoiceChannelStatus,
331-
sendPolls: sendPolls)
336+
sendPolls: sendPolls,
337+
useExternalApps: useExternalApps)
332338
{ }
333339

334340
/// <summary> Creates a new <see cref="GuildPermissions"/> from this one, changing the provided non-null permissions. </summary>
@@ -380,14 +386,15 @@ public GuildPermissions Modify(
380386
bool? useClydeAI = null,
381387
bool? createGuildExpressions = null,
382388
bool? setVoiceChannelStatus = null,
383-
bool? sendPolls = null)
389+
bool? sendPolls = null,
390+
bool? useExternalApps = null)
384391
=> new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions,
385392
viewAuditLog, viewGuildInsights, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles,
386393
readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers,
387394
useVoiceActivation, prioritySpeaker, stream, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojisAndStickers,
388395
useApplicationCommands, requestToSpeak, manageEvents, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads,
389396
startEmbeddedActivities, moderateMembers, useSoundboard, viewMonetizationAnalytics, sendVoiceMessages, useClydeAI, createGuildExpressions, setVoiceChannelStatus,
390-
sendPolls);
397+
sendPolls, useExternalApps);
391398

392399
/// <summary>
393400
/// Returns a value that indicates if a specific <see cref="GuildPermission"/> is enabled

test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ IEnumerable<ulong> GetTestValues()
4747
}
4848

4949
/// <summary>
50-
/// Tests the behavior of the <see cref="Discord.ChannelPermissions"/> constructor for each
50+
/// Tests the behavior of the <see cref="ChannelPermissions"/> constructor for each
5151
/// of it's flags.
5252
/// </summary>
5353
[Fact]
@@ -96,10 +96,11 @@ void AssertFlag(Func<ChannelPermissions> cstr, ChannelPermission flag)
9696
AssertFlag(() => new ChannelPermissions(useClydeAI: true), ChannelPermission.UseClydeAI);
9797
AssertFlag(() => new ChannelPermissions(setVoiceChannelStatus: true), ChannelPermission.SetVoiceChannelStatus);
9898
AssertFlag(() => new ChannelPermissions(sendPolls: true), ChannelPermission.SendPolls);
99+
AssertFlag(() => new ChannelPermissions(useExternalApps: true), ChannelPermission.UseExternalApps);
99100
}
100101

101102
/// <summary>
102-
/// Tests the behavior of <see cref="Discord.ChannelPermissions.Modify"/>
103+
/// Tests the behavior of <see cref="ChannelPermissions.Modify"/>
103104
/// with each of the parameters.
104105
/// </summary>
105106
[Fact]
@@ -164,6 +165,7 @@ void AssertUtil(ChannelPermission permission,
164165
AssertUtil(ChannelPermission.UseClydeAI, x => x.UseClydeAI, (p, enable) => p.Modify(useClydeAI: enable));
165166
AssertUtil(ChannelPermission.SetVoiceChannelStatus, x => x.SetVoiceChannelStatus, (p, enable) => p.Modify(setVoiceChannelStatus: enable));
166167
AssertUtil(ChannelPermission.SendPolls, x => x.SendPolls, (p, enable) => p.Modify(sendPolls: enable));
168+
AssertUtil(ChannelPermission.UseExternalApps, x => x.UserExternalApps, (p, enable) => p.Modify(useExternalApps: enable));
167169
}
168170

169171
/// <summary>

test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ void AssertFlag(Func<GuildPermissions> cstr, GuildPermission flag)
107107
AssertFlag(() => new GuildPermissions(createGuildExpressions: true), GuildPermission.CreateGuildExpressions);
108108
AssertFlag(() => new GuildPermissions(setVoiceChannelStatus: true), GuildPermission.SetVoiceChannelStatus);
109109
AssertFlag(() => new GuildPermissions(sendPolls: true), GuildPermission.SendPolls);
110+
AssertFlag(() => new GuildPermissions(useExternalApps: true), GuildPermission.UseExternalApps);
110111
}
111112

112113
/// <summary>
113-
/// 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?)"/>
114+
/// Tests the behavior of <see cref="GuildPermissions.Modify"/>
114115
/// with each of the parameters.
115116
/// </summary>
116117
[Fact]
@@ -192,6 +193,7 @@ void AssertUtil(GuildPermission permission,
192193
AssertUtil(GuildPermission.CreateGuildExpressions, x => x.CreateGuildExpressions, (p, enable) => p.Modify(createGuildExpressions: enable));
193194
AssertUtil(GuildPermission.SetVoiceChannelStatus, x => x.SetVoiceChannelStatus, (p, enable) => p.Modify(setVoiceChannelStatus: enable));
194195
AssertUtil(GuildPermission.SendPolls, x => x.SendPolls, (p, enable) => p.Modify(sendPolls: enable));
196+
AssertUtil(GuildPermission.UseExternalApps, x => x.UserExternalApps, (p, enable) => p.Modify(useExternalApps: enable));
195197
}
196198
}
197199
}

0 commit comments

Comments
 (0)