Skip to content

Commit

Permalink
Add missing permission override parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Oct 27, 2024
1 parent b9ca2b8 commit 1d36611
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Kook.Net.Core/Entities/Permissions/GuildPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public struct GuildPermissions
public bool ShareScreen => Permissions.GetValue(RawValue, GuildPermission.ShareScreen);

/// <summary>
/// 获取此权限集是否允许相关用户发布t帖子回复
/// 获取此权限集是否允许相关用户发布帖子回复
/// </summary>
public bool ReplyToPost => Permissions.GetValue(RawValue, GuildPermission.ReplyToPost);

Expand Down
25 changes: 18 additions & 7 deletions src/Kook.Net.Core/Entities/Permissions/OverwritePermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public static OverwritePermissions DenyAll(IChannel channel) =>
/// </summary>
public PermValue ShareScreen => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ShareScreen);

/// <summary>
/// 获取此权限重写配置对频道权限位 <see cref="Kook.ChannelPermission.ReplyToPost"/> 的重写配置。
/// </summary>
public PermValue ReplyToPost => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ReplyToPost);

/// <summary>
/// 使用指定的原始值初始化一个 <see cref="OverwritePermissions"/> 结构的新实例。
/// </summary>
Expand Down Expand Up @@ -156,7 +161,8 @@ private OverwritePermissions(ulong allowValue, ulong denyValue,
PermValue? deafenMembers = null,
PermValue? muteMembers = null,
PermValue? playSoundtrack = null,
PermValue? shareScreen = null)
PermValue? shareScreen = null,
PermValue? replyToPost = null)
{
Permissions.SetValue(ref allowValue, ref denyValue, createInvites, ChannelPermission.CreateInvites);
Permissions.SetValue(ref allowValue, ref denyValue, manageChannels, ChannelPermission.ManageChannels);
Expand All @@ -176,6 +182,7 @@ private OverwritePermissions(ulong allowValue, ulong denyValue,
Permissions.SetValue(ref allowValue, ref denyValue, muteMembers, ChannelPermission.MuteMembers);
Permissions.SetValue(ref allowValue, ref denyValue, playSoundtrack, ChannelPermission.PlaySoundtrack);
Permissions.SetValue(ref allowValue, ref denyValue, shareScreen, ChannelPermission.ShareScreen);
Permissions.SetValue(ref allowValue, ref denyValue, replyToPost, ChannelPermission.ReplyToPost);

AllowValue = allowValue;
DenyValue = denyValue;
Expand All @@ -202,6 +209,7 @@ private OverwritePermissions(ulong allowValue, ulong denyValue,
/// <param name="muteMembers"> 服务器闭麦。 </param>
/// <param name="playSoundtrack"> 共享计算机音频。 </param>
/// <param name="shareScreen"> 屏幕分享。 </param>
/// <param name="replyToPost"> 发布帖子回复。 </param>
public OverwritePermissions(
PermValue createInvites = PermValue.Inherit,
PermValue manageChannels = PermValue.Inherit,
Expand All @@ -220,10 +228,11 @@ public OverwritePermissions(
PermValue deafenMembers = PermValue.Inherit,
PermValue muteMembers = PermValue.Inherit,
PermValue playSoundtrack = PermValue.Inherit,
PermValue shareScreen = PermValue.Inherit)
PermValue shareScreen = PermValue.Inherit,
PermValue replyToPost = PermValue.Inherit)
: this(0, 0, createInvites, manageChannels, manageRoles, viewChannel, sendMessages, manageMessages,
attachFiles, connect, manageVoice, mentionEveryone, addReactions, passiveConnect, useVoiceActivity, speak,
deafenMembers, muteMembers, playSoundtrack, shareScreen)
deafenMembers, muteMembers, playSoundtrack, shareScreen, replyToPost)
{
}

Expand All @@ -248,6 +257,7 @@ public OverwritePermissions(
/// <param name="muteMembers"> 服务器闭麦。 </param>
/// <param name="playSoundtrack"> 共享计算机音频。 </param>
/// <param name="shareScreen"> 屏幕分享。 </param>
/// <param name="replyToPost"> 发布帖子回复。 </param>
/// <returns> 更改了指定权限的新的权限集。 </returns>
public OverwritePermissions Modify(
PermValue? createInvites = null,
Expand All @@ -267,10 +277,11 @@ public OverwritePermissions Modify(
PermValue? deafenMembers = null,
PermValue? muteMembers = null,
PermValue? playSoundtrack = null,
PermValue? shareScreen = null) =>
new(AllowValue, DenyValue, createInvites, manageChannels, manageRoles, viewChannel,
sendMessages, manageMessages, attachFiles, connect, manageVoice, mentionEveryone, addReactions,
passiveConnect, useVoiceActivity, speak, deafenMembers, muteMembers, playSoundtrack, shareScreen);
PermValue? shareScreen = null,
PermValue? replyToPost = null) =>
new(AllowValue, DenyValue, createInvites, manageChannels, manageRoles, viewChannel, sendMessages,
manageMessages, attachFiles, connect, manageVoice, mentionEveryone, addReactions, passiveConnect,
useVoiceActivity, speak, deafenMembers, muteMembers, playSoundtrack, shareScreen, replyToPost);

/// <summary>
/// 获取一个包含当前权限重写配置所包含的所有重写允许的 <see cref="ChannelPermission"/> 独立位标志枚举值的集合。
Expand Down
7 changes: 5 additions & 2 deletions test/Kook.Net.Tests.Unit/GuildPermissionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IEnumerable<ulong> GetTestValues()

/// <summary>
/// Tests the behavior of the <see cref="Kook.GuildPermissions"/> constructor for each
/// of it's flags.
/// of its flags.
/// </summary>
[Fact]
public void FlagsConstructor()
Expand Down Expand Up @@ -89,10 +89,12 @@ void AssertFlag(Func<GuildPermissions> cstr, GuildPermission flag)
AssertFlag(() => new GuildPermissions(manageNicknames: true), GuildPermission.ManageNicknames);
AssertFlag(() => new GuildPermissions(playSoundtrack: true), GuildPermission.PlaySoundtrack);
AssertFlag(() => new GuildPermissions(shareScreen: true), GuildPermission.ShareScreen);
AssertFlag(() => new GuildPermissions(replyToPost: true), GuildPermission.ReplyToPost);
}

/// <summary>
/// Tests the behavior of <see cref="Kook.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="Kook.GuildPermissions.Modify(System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean})"/>
/// with each of the parameters.
/// </summary>
[Fact]
Expand Down Expand Up @@ -160,5 +162,6 @@ void AssertUtil(GuildPermission permission,
AssertUtil(GuildPermission.ManageNicknames, x => x.ManageNicknames, (p, enable) => p.Modify(manageNicknames: enable));
AssertUtil(GuildPermission.PlaySoundtrack, x => x.PlaySoundtrack, (p, enable) => p.Modify(playSoundtrack: enable));
AssertUtil(GuildPermission.ShareScreen, x => x.ShareScreen, (p, enable) => p.Modify(shareScreen: enable));
AssertUtil(GuildPermission.ReplyToPost, x => x.ReplyToPost, (p, enable) => p.Modify(replyToPost: enable));
}
}

0 comments on commit 1d36611

Please sign in to comment.