Browse Source

implement fix

pull/2293/head
Cenngo 3 years ago
parent
commit
109728ef93
4 changed files with 11 additions and 8 deletions
  1. +1
    -1
      src/Discord.Net.Interactions/Info/ModuleInfo.cs
  2. +6
    -3
      src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs
  3. +2
    -2
      src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs
  4. +2
    -2
      src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs

+ 1
- 1
src/Discord.Net.Interactions/Info/ModuleInfo.cs View File

@@ -248,7 +248,7 @@ namespace Discord.Interactions


while (parent != null) while (parent != null)
{ {
permissions = (permissions ?? 0) | (parent.DefaultMemberPermissions ?? 0);
permissions = (permissions ?? 0) | (parent.DefaultMemberPermissions ?? 0).SanitizeGuildPermissions();
parent = parent.Parent; parent = parent.Parent;
} }




+ 6
- 3
src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs View File

@@ -41,7 +41,7 @@ namespace Discord.Interactions
Name = commandInfo.Name, Name = commandInfo.Name,
Description = commandInfo.Description, Description = commandInfo.Description,
IsDMEnabled = commandInfo.IsEnabledInDm, IsDMEnabled = commandInfo.IsEnabledInDm,
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
}.Build(); }.Build();


if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount)
@@ -69,14 +69,14 @@ namespace Discord.Interactions
{ {
Name = commandInfo.Name, Name = commandInfo.Name,
IsDefaultPermission = commandInfo.DefaultPermission, IsDefaultPermission = commandInfo.DefaultPermission,
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0),
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
IsDMEnabled = commandInfo.IsEnabledInDm IsDMEnabled = commandInfo.IsEnabledInDm
}.Build(), }.Build(),
ApplicationCommandType.User => new UserCommandBuilder ApplicationCommandType.User => new UserCommandBuilder
{ {
Name = commandInfo.Name, Name = commandInfo.Name,
IsDefaultPermission = commandInfo.DefaultPermission, IsDefaultPermission = commandInfo.DefaultPermission,
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0),
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
IsDMEnabled = commandInfo.IsEnabledInDm IsDMEnabled = commandInfo.IsEnabledInDm
}.Build(), }.Build(),
_ => throw new InvalidOperationException($"{commandInfo.CommandType} isn't a supported command type.") _ => throw new InvalidOperationException($"{commandInfo.CommandType} isn't a supported command type.")
@@ -232,5 +232,8 @@ namespace Discord.Interactions


return builder.Build(); return builder.Build();
} }

public static GuildPermission? SanitizeGuildPermissions(this GuildPermission permissions) =>
permissions == 0 ? null : permissions;
} }
} }

+ 2
- 2
src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs View File

@@ -65,8 +65,8 @@ namespace Discord.Rest
: ImmutableArray.Create<RestApplicationCommandOption>(); : ImmutableArray.Create<RestApplicationCommandOption>();


IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
DefaultMemberPermissions = model.DefaultMemberPermission.IsSpecified
? new GuildPermissions((ulong)model.DefaultMemberPermission.Value) : GuildPermissions.None;
DefaultMemberPermissions = model.DefaultMemberPermission.GetValueOrDefault(null).HasValue
? new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(null).Value) : GuildPermissions.None;
} }


/// <inheritdoc/> /// <inheritdoc/>


+ 2
- 2
src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs View File

@@ -94,8 +94,8 @@ namespace Discord.WebSocket
: ImmutableArray.Create<SocketApplicationCommandOption>(); : ImmutableArray.Create<SocketApplicationCommandOption>();


IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
DefaultMemberPermissions = model.DefaultMemberPermission.IsSpecified
? new GuildPermissions((ulong)model.DefaultMemberPermission.Value) : GuildPermissions.None;
DefaultMemberPermissions = model.DefaultMemberPermission.GetValueOrDefault(null).HasValue
? new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(null).Value) : GuildPermissions.None;
} }


/// <inheritdoc/> /// <inheritdoc/>


Loading…
Cancel
Save