Browse Source

add `nsfw` to data model & internal methods; add missing property

pull/2531/head
Misha133 2 years ago
parent
commit
7ecfdfb514
8 changed files with 47 additions and 8 deletions
  1. +5
    -0
      src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs
  2. +5
    -0
      src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs
  3. +3
    -0
      src/Discord.Net.Rest/API/Common/ApplicationCommand.cs
  4. +5
    -1
      src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs
  5. +6
    -0
      src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs
  6. +15
    -7
      src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
  7. +4
    -0
      src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs
  8. +4
    -0
      src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs

+ 5
- 0
src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs View File

@@ -83,6 +83,11 @@ namespace Discord
/// </summary>
public Optional<bool> IsDMEnabled { get; set; }

/// <summary>
/// Gets or sets whether or not this command is age restricted.
/// </summary>
public Optional<bool> IsNsfw { get; set; }

/// <summary>
/// Gets or sets the default permissions required by a user to execute this application command.
/// </summary>


+ 5
- 0
src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs View File

@@ -42,6 +42,11 @@ namespace Discord
/// </remarks>
bool IsEnabledInDm { get; }

/// <summary>
/// Indicates whether the command is age restricted.
/// </summary>
bool IsNsfw { get; }

/// <summary>
/// Set of default <see cref="GuildPermission"/> required to invoke the command.
/// </summary>


+ 3
- 0
src/Discord.Net.Rest/API/Common/ApplicationCommand.cs View File

@@ -44,5 +44,8 @@ namespace Discord.API

[JsonProperty("default_member_permissions")]
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }

[JsonProperty("nsfw")]
public Optional<bool?> Nsfw { get; set; }
}
}

+ 5
- 1
src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs View File

@@ -35,9 +35,12 @@ namespace Discord.API.Rest
[JsonProperty("default_member_permissions")]
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }

[JsonProperty("nsfw")]
public Optional<bool> Nsfw { get; set; }

public CreateApplicationCommandParams() { }
public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null,
IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null)
IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null, bool nsfw = false)
{
Name = name;
Description = description;
@@ -45,6 +48,7 @@ namespace Discord.API.Rest
Type = type;
NameLocalizations = nameLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
DescriptionLocalizations = descriptionLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
Nsfw = nsfw;
}
}
}

+ 6
- 0
src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs View File

@@ -17,6 +17,12 @@ namespace Discord.API.Rest
[JsonProperty("default_permission")]
public Optional<bool> DefaultPermission { get; set; }

[JsonProperty("nsfw")]
public Optional<bool> Nsfw { get; set; }

[JsonProperty("default_member_permissions")]
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }

[JsonProperty("name_localizations")]
public Optional<Dictionary<string, string>> NameLocalizations { get; set; }



+ 15
- 7
src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs View File

@@ -107,7 +107,8 @@ namespace Discord.Rest

// TODO: better conversion to nullable optionals
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
DmPermission = arg.IsDMEnabled.ToNullable()
DmPermission = arg.IsDMEnabled.ToNullable(),
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
};

if (arg is SlashCommandProperties slashProps)
@@ -147,8 +148,9 @@ namespace Discord.Rest

// TODO: better conversion to nullable optionals
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
DmPermission = arg.IsDMEnabled.ToNullable()
};
DmPermission = arg.IsDMEnabled.ToNullable(),
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
};

if (arg is SlashCommandProperties slashProps)
{
@@ -190,7 +192,8 @@ namespace Discord.Rest

// TODO: better conversion to nullable optionals
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
DmPermission = arg.IsDMEnabled.ToNullable()
DmPermission = arg.IsDMEnabled.ToNullable(),
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
};

if (arg is SlashCommandProperties slashProps)
@@ -252,7 +255,9 @@ namespace Discord.Rest
? args.IsDefaultPermission.Value
: Optional<bool>.Unspecified,
NameLocalizations = args.NameLocalizations?.ToDictionary(),
DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary()
DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary(),
Nsfw = args.IsNsfw.GetValueOrDefault(false),
DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable()
};

if (args is SlashCommandProperties slashProps)
@@ -312,7 +317,8 @@ namespace Discord.Rest

// TODO: better conversion to nullable optionals
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
DmPermission = arg.IsDMEnabled.ToNullable()
DmPermission = arg.IsDMEnabled.ToNullable(),
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
};

if (arg is SlashCommandProperties slashProps)
@@ -347,7 +353,9 @@ namespace Discord.Rest
? arg.IsDefaultPermission.Value
: Optional<bool>.Unspecified,
NameLocalizations = arg.NameLocalizations?.ToDictionary(),
DescriptionLocalizations = arg.DescriptionLocalizations?.ToDictionary()
DescriptionLocalizations = arg.DescriptionLocalizations?.ToDictionary(),
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable()
};

if (arg is SlashCommandProperties slashProps)


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

@@ -30,6 +30,9 @@ namespace Discord.Rest
/// <inheritdoc/>
public bool IsEnabledInDm { get; private set; }

/// <inheritdoc/>
public bool IsNsfw { get; private set; }

/// <inheritdoc/>
public GuildPermissions DefaultMemberPermissions { get; private set; }

@@ -101,6 +104,7 @@ namespace Discord.Rest
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
}

/// <inheritdoc/>


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

@@ -39,6 +39,9 @@ namespace Discord.WebSocket
/// <inheritdoc/>
public bool IsEnabledInDm { get; private set; }

/// <inheritdoc/>
public bool IsNsfw { get; private set; }

/// <inheritdoc/>
public GuildPermissions DefaultMemberPermissions { get; private set; }

@@ -130,6 +133,7 @@ namespace Discord.WebSocket

IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
}

/// <inheritdoc/>


Loading…
Cancel
Save