[Feature] Add PinMessages permission (#3178)

This commit is contained in:
Mihail Gribkov
2025-08-22 23:38:45 +03:00
committed by GitHub
parent ae6e7d50b3
commit 5273f1df98
6 changed files with 43 additions and 15 deletions

View File

@@ -207,5 +207,10 @@ namespace Discord
/// Allows user-installed apps to send public responses.
/// </summary>
UseExternalApps = 1L << 50,
/// <summary>
/// Allows pinning and unpinning messages.
/// </summary>
PinMessages = 1L << 51,
}
}

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(0b110_110001_001111_110010_110011_111101_111111_111101_010001);
public static readonly ChannelPermissions Text = new(0b1110_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(0b111_110101_001010_001010_110011_111101_111111_111101_010001);
public static readonly ChannelPermissions Voice = new(0b0111_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_110100_000010_001110_010001_010101_111111_111001_010001);
public static readonly ChannelPermissions Stage = new(0b0110_110100_000010_001110_010001_010101_111111_111001_010001);
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels.
@@ -48,7 +48,7 @@ namespace Discord
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for forum channels.
/// </summary>
public static readonly ChannelPermissions Forum = new(0b000001_001110_010010_110011_111101_111111_111101_010001);
public static readonly ChannelPermissions Forum = new(0b1000_000001_001110_010010_110011_111101_111111_111101_010001);
/// <summary>
/// Gets a <see cref="ChannelPermissions"/> that grants all permissions for media channels.
@@ -158,6 +158,8 @@ namespace Discord
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> If <see langword="true"/>, a user can ping and unpin messages.</summary>
public bool PinMessages => Permissions.GetValue(RawValue, ChannelPermission.PinMessages);
/// <summary> Creates a new <see cref="ChannelPermissions"/> with the provided packed value.</summary>
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; }
@@ -200,7 +202,8 @@ namespace Discord
bool? setVoiceChannelStatus = null,
bool? sendPolls = null,
bool? useExternalApps = null,
bool? useExternalSounds = null)
bool? useExternalSounds = null,
bool? pinMessages = null)
{
ulong value = initialValue;
@@ -242,6 +245,7 @@ namespace Discord
Permissions.SetValue(ref value, sendPolls, ChannelPermission.SendPolls);
Permissions.SetValue(ref value, useExternalApps, ChannelPermission.UseExternalApps);
Permissions.SetValue(ref value, useExternalSounds, ChannelPermission.UseExternalSounds);
Permissions.SetValue(ref value, pinMessages, ChannelPermission.PinMessages);
RawValue = value;
}
@@ -285,12 +289,14 @@ namespace Discord
bool setVoiceChannelStatus = false,
bool sendPolls = false,
bool useExternalApps = false,
bool useExternalSounds = false)
bool useExternalSounds = false,
bool pinMessages = 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, useExternalSounds)
startEmbeddedActivities, useSoundboard, createEvents, sendVoiceMessages, useClydeAI, setVoiceChannelStatus, sendPolls, useExternalApps,
useExternalSounds, pinMessages)
{ }
/// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions.</summary>
@@ -332,7 +338,8 @@ namespace Discord
bool? setVoiceChannelStatus = null,
bool? sendPolls = null,
bool? useExternalApps = null,
bool? useExternalSounds = null)
bool? useExternalSounds = null,
bool? pinMessages = null)
=> new ChannelPermissions(RawValue,
createInstantInvite,
manageChannel,
@@ -371,7 +378,8 @@ namespace Discord
setVoiceChannelStatus,
sendPolls,
useExternalApps,
useExternalSounds);
useExternalSounds,
pinMessages);
public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission);

View File

@@ -302,5 +302,10 @@ namespace Discord
/// Allows user-installed apps to send public responses.
/// </summary>
UseExternalApps = 1L << 50,
/// <summary>
/// Allows pinning and unpinning messages.
/// </summary>
PinMessages = 1L << 51,
}
}

View File

@@ -124,6 +124,8 @@ namespace Discord
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> If <see langword="true"/>, a user can ping and unpin messages.</summary>
public bool PinMessages => Permissions.GetValue(RawValue, GuildPermission.PinMessages);
/// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary>
public GuildPermissions(ulong rawValue) { RawValue = rawValue; }
@@ -182,7 +184,8 @@ namespace Discord
bool? sendPolls = null,
bool? useExternalApps = null,
bool? useExternalSounds = null,
bool? createEvents = null)
bool? createEvents = null,
bool? pinMessages = null)
{
ulong value = initialValue;
@@ -237,6 +240,7 @@ namespace Discord
Permissions.SetValue(ref value, useExternalApps, GuildPermission.UseExternalApps);
Permissions.SetValue(ref value, useExternalSounds, GuildPermission.UseExternalSounds);
Permissions.SetValue(ref value, createEvents, GuildPermission.CreateEvents);
Permissions.SetValue(ref value, pinMessages, GuildPermission.PinMessages);
RawValue = value;
}
@@ -293,7 +297,8 @@ namespace Discord
bool sendPolls = false,
bool useExternalApps = false,
bool useExternalSounds = false,
bool createEvents = false)
bool createEvents = false,
bool pinMessages = false)
: this(0,
createInstantInvite: createInstantInvite,
manageRoles: manageRoles,
@@ -345,7 +350,8 @@ namespace Discord
sendPolls: sendPolls,
useExternalApps: useExternalApps,
useExternalSounds: useExternalSounds,
createEvents: createEvents)
createEvents: createEvents,
pinMessages: pinMessages)
{ }
/// <summary> Creates a new <see cref="GuildPermissions"/> from this one, changing the provided non-null permissions. </summary>
@@ -400,14 +406,15 @@ namespace Discord
bool? sendPolls = null,
bool? useExternalApps = null,
bool? useExternalSounds = null,
bool? createEvents = null)
bool? createEvents = null,
bool? pinMessages = 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, useExternalSounds, createEvents);
sendPolls, useExternalApps, useExternalSounds, createEvents, pinMessages);
/// <summary>
/// Returns a value that indicates if a specific <see cref="GuildPermission"/> is enabled

View File

@@ -97,7 +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);
AssertFlag(() => new ChannelPermissions(pinMessages: true), ChannelPermission.PinMessages);
}
/// <summary>
@@ -168,6 +168,7 @@ namespace Discord
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));
AssertUtil(ChannelPermission.PinMessages, x => x.PinMessages, (p, enable) => p.Modify(pinMessages: enable));
}
/// <summary>

View File

@@ -109,6 +109,7 @@ namespace Discord
AssertFlag(() => new GuildPermissions(useExternalApps: true), GuildPermission.UseExternalApps);
AssertFlag(() => new GuildPermissions(useExternalSounds: true), GuildPermission.UseExternalSounds);
AssertFlag(() => new GuildPermissions(createEvents: true), GuildPermission.CreateEvents);
AssertFlag(() => new GuildPermissions(pinMessages: true), GuildPermission.PinMessages);
}
/// <summary>
@@ -197,6 +198,7 @@ namespace Discord
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));
AssertUtil(GuildPermission.PinMessages, x => x.PinMessages, (p, enable) => p.Modify(pinMessages: enable));
}
}
}