[Feature] Age restricted (NSFW) application commands support (#2531)

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

* add `nsfw` prop to command builders

* add `NsfwCommandAttribute` to Interaction Framework

* working state

* docs?
This commit is contained in:
Misha133
2022-12-20 01:00:56 +03:00
committed by GitHub
parent 60956c720b
commit 56b1a930e7
23 changed files with 230 additions and 15 deletions

View File

@@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders
/// </summary>
public bool IsEnabledInDm { get; set; } = true;
/// <summary>
/// Gets whether this command is age restricted.
/// </summary>
public bool IsNsfw { get; set; } = false;
/// <summary>
/// Gets the default permissions needed for executing this command.
/// </summary>
@@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders
return this;
}
/// <summary>
/// Sets <see cref="IsNsfw"/>.
/// </summary>
/// <param name="isNsfw">New value of the <see cref="IsNsfw"/>.</param>
/// <returns>
/// The builder instance.
/// </returns>
public ContextCommandBuilder SetNsfw(bool isNsfw)
{
IsNsfw = isNsfw;
return this;
}
/// <summary>
/// Sets <see cref="DefaultMemberPermissions"/>.
/// </summary>

View File

@@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders
/// </summary>
public bool IsEnabledInDm { get; set; } = true;
/// <summary>
/// Gets whether this command is age restricted.
/// </summary>
public bool IsNsfw { get; set; } = false;
/// <summary>
/// Gets the default permissions needed for executing this command.
/// </summary>
@@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders
return this;
}
/// <summary>
/// Sets <see cref="IsNsfw"/>.
/// </summary>
/// <param name="isNsfw">New value of the <see cref="IsNsfw"/>.</param>
/// <returns>
/// The builder instance.
/// </returns>
public SlashCommandBuilder SetNsfw(bool isNsfw)
{
IsNsfw = isNsfw;
return this;
}
/// <summary>
/// Sets <see cref="DefaultMemberPermissions"/>.
/// </summary>

View File

@@ -59,6 +59,11 @@ namespace Discord.Interactions.Builders
/// </summary>
public bool IsEnabledInDm { get; set; } = true;
/// <summary>
/// Gets whether this command is age restricted.
/// </summary>
public bool IsNsfw { get; set; } = false;
/// <summary>
/// Gets the default permissions needed for executing this command.
/// </summary>
@@ -190,6 +195,19 @@ namespace Discord.Interactions.Builders
return this;
}
/// <summary>
/// Sets <see cref="IsNsfw"/>.
/// </summary>
/// <param name="isNsfw">New value of the <see cref="IsNsfw"/>.</param>
/// <returns>
/// The builder instance.
/// </returns>
public ModuleBuilder SetNsfw(bool isNsfw)
{
IsNsfw = isNsfw;
return this;
}
/// <summary>
/// Sets <see cref="DefaultMemberPermissions"/>.
/// </summary>

View File

@@ -101,6 +101,9 @@ namespace Discord.Interactions.Builders
case DontAutoRegisterAttribute dontAutoRegister:
builder.DontAutoRegister = true;
break;
case NsfwCommandAttribute nsfwCommand:
builder.SetNsfw(nsfwCommand.IsNsfw);
break;
default:
builder.AddAttributes(attribute);
break;
@@ -192,6 +195,9 @@ namespace Discord.Interactions.Builders
case PreconditionAttribute precondition:
builder.WithPreconditions(precondition);
break;
case NsfwCommandAttribute nsfwCommand:
builder.SetNsfw(nsfwCommand.IsNsfw);
break;
default:
builder.WithAttributes(attribute);
break;
@@ -244,6 +250,9 @@ namespace Discord.Interactions.Builders
case PreconditionAttribute precondition:
builder.WithPreconditions(precondition);
break;
case NsfwCommandAttribute nsfwCommand:
builder.SetNsfw(nsfwCommand.IsNsfw);
break;
default:
builder.WithAttributes(attribute);
break;