[Feature] Initial user apps support (#2883)
* omg it kinda works somehow * more things added * a bit of xmldocs * added interaction framework support * working? IF * more builder stuff * space * rename attribute to prevent conflict with `ContextType` enum * context type * moar features * remove integration types * trigger workflow * modelzzzz * `InteractionContextType` * allow setting custom status with `SetGameAsync` * bugzzz * app permissions * message interaction context * hm * push for cd * structs lets goooo * whoops forgot to change types * whoops x2 * tweak some things * xmldocs + missing prop + fix enabled in dm * moar validations * deprecate a bunch of stuffz * disable moar obsolete warnings * add IF sample * Apply suggestions from code review Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> * Update src/Discord.Net.Rest/Entities/RestApplication.cs Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> --------- Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
This commit is contained in:
@@ -164,6 +164,8 @@ Interaction service complex parameter constructors are prioritized in the follow
|
||||
3. Type's only public constuctor.
|
||||
|
||||
#### DM Permissions
|
||||
> [!WARNING]
|
||||
> [EnabledInDmAttribute] is being deprecated in favor of [CommandContextTypes] attribute.
|
||||
|
||||
You can use the [EnabledInDmAttribute] to configure whether a globally-scoped top level command should be enabled in Dms or not. Only works on top level commands.
|
||||
|
||||
@@ -419,6 +421,12 @@ Discord Slash Commands support name/description localization. Localization is av
|
||||
}
|
||||
```
|
||||
|
||||
## User Apps
|
||||
|
||||
User apps are the kind of Discord applications that are installed onto a user instead of a guild, thus making commands usable anywhere on Discord. Note that only users who have installed the application will see the commands. This sample shows you how to create a simple user install command.
|
||||
|
||||
[!code-csharp[Registering Commands Example](samples/intro/userapps.cs)]
|
||||
|
||||
[AutocompleteHandlers]: xref:Guides.IntFw.AutoCompletion
|
||||
[DependencyInjection]: xref:Guides.DI.Intro
|
||||
|
||||
@@ -447,6 +455,8 @@ Discord Slash Commands support name/description localization. Localization is av
|
||||
[ChannelTypesAttribute]: xref:Discord.Interactions.ChannelTypesAttribute
|
||||
[MaxValueAttribute]: xref:Discord.Interactions.MaxValueAttribute
|
||||
[MinValueAttribute]: xref:Discord.Interactions.MinValueAttribute
|
||||
[EnabledInDmAttribute]: xref:Discord.Interactions.EnabledInDmAttribute
|
||||
[CommandContextTypes]: xref:Discord.Interactions.CommandContextTypesAttribute
|
||||
|
||||
[IChannel]: xref:Discord.IChannel
|
||||
[IRole]: xref:Discord.IRole
|
||||
|
||||
19
docs/guides/int_framework/samples/intro/userapps.cs
Normal file
19
docs/guides/int_framework/samples/intro/userapps.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
// This parameteres can be configured on the module level
|
||||
// Set supported command context types to Bot DMs and Private Channels (regular DM & GDM)
|
||||
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
|
||||
// Set supported integration installation type to User Install
|
||||
[IntegrationType(ApplicationIntegrationType.UserInstall)]
|
||||
public class CommandModule() : InteractionModuleBase<SocketInteractionContext>
|
||||
{
|
||||
[SlashCommand("test", "Just a test command")]
|
||||
public async Task TestCommand()
|
||||
=> await RespondAsync("Hello There");
|
||||
|
||||
// But can also be overridden on the command level
|
||||
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel, InteractionContextType.Guild)]
|
||||
[IntegrationType(ApplicationIntegrationType.GuildInstall)]
|
||||
[SlashCommand("echo", "Echo the input")]
|
||||
public async Task EchoCommand(string input)
|
||||
=> await RespondAsync($"You said: {input}");
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
- name: Home
|
||||
href: index.md
|
||||
- name: Documentation
|
||||
href: api/
|
||||
topicUid: API.Docs
|
||||
- name: Guides
|
||||
href: guides/
|
||||
topicUid: Guides.Introduction
|
||||
- name: API Reference
|
||||
href: api/
|
||||
topicUid: API.Docs
|
||||
- name: FAQ
|
||||
href: faq/
|
||||
topicUid: FAQ.Basics.GetStarted
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Defines where an application can be installed.
|
||||
/// </summary>
|
||||
public enum ApplicationIntegrationType
|
||||
{
|
||||
/// <summary>
|
||||
/// The application can be installed to a guild.
|
||||
/// </summary>
|
||||
GuildInstall = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The application can be installed to a user.
|
||||
/// </summary>
|
||||
UserInstall = 1,
|
||||
}
|
||||
@@ -154,5 +154,10 @@ namespace Discord
|
||||
/// Gets the application's verification state.
|
||||
/// </summary>
|
||||
ApplicationVerificationState VerificationState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets application install params configured for integration install types.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<ApplicationIntegrationType, ApplicationInstallParams> IntegrationTypesConfig { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
@@ -54,4 +56,9 @@ public class ModifyApplicationProperties
|
||||
/// </remarks>
|
||||
public Optional<ApplicationFlags> Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets application install params configured for integration install types.
|
||||
/// </summary>
|
||||
public Optional<Dictionary<ApplicationIntegrationType, ApplicationInstallParams>> IntegrationTypesConfig { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +93,16 @@ namespace Discord
|
||||
/// </summary>
|
||||
public Optional<GuildPermission> DefaultMemberPermissions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the install method for this command.
|
||||
/// </summary>
|
||||
public Optional<HashSet<ApplicationIntegrationType>> IntegrationTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets context types this command can be executed in.
|
||||
/// </summary>
|
||||
public Optional<HashSet<InteractionContextType>> ContextTypes { get; set; }
|
||||
|
||||
internal ApplicationCommandProperties() { }
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ namespace Discord
|
||||
/// <remarks>
|
||||
/// Only for globally-scoped commands.
|
||||
/// </remarks>
|
||||
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||
bool IsEnabledInDm { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -83,6 +84,16 @@ namespace Discord
|
||||
/// </remarks>
|
||||
string DescriptionLocalized { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets context types the command can be used in; <see langword="null" /> if not specified.
|
||||
/// </summary>
|
||||
IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the install method for the command; <see langword="null" /> if not specified.
|
||||
/// </summary>
|
||||
IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the current application command.
|
||||
/// </summary>
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a context in Discord where an interaction can be used.
|
||||
/// </summary>
|
||||
public enum InteractionContextType
|
||||
{
|
||||
/// <summary>
|
||||
/// The command can be used in guilds.
|
||||
/// </summary>
|
||||
Guild = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The command can be used in DM channel with the bot.
|
||||
/// </summary>
|
||||
BotDm = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The command can be used in private channels.
|
||||
/// </summary>
|
||||
PrivateChannel = 2
|
||||
}
|
||||
@@ -44,6 +44,7 @@ namespace Discord
|
||||
/// <summary>
|
||||
/// Gets or sets whether or not this command can be used in DMs.
|
||||
/// </summary>
|
||||
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||
public bool IsDMEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
@@ -56,6 +57,16 @@ namespace Discord
|
||||
/// </summary>
|
||||
public GuildPermission? DefaultMemberPermissions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the install method for this command; <see langword="null" /> if not specified.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types this command can be executed in; <see langword="null" /> if not specified.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; } = null;
|
||||
|
||||
private string _name;
|
||||
private Dictionary<string, string> _nameLocalizations;
|
||||
|
||||
@@ -71,10 +82,14 @@ namespace Discord
|
||||
{
|
||||
Name = Name,
|
||||
IsDefaultPermission = IsDefaultPermission,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = IsDMEnabled,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||
NameLocalizations = NameLocalizations,
|
||||
IsNsfw = IsNsfw,
|
||||
IntegrationTypes = IntegrationTypes,
|
||||
ContextTypes = ContextTypes
|
||||
};
|
||||
|
||||
return props;
|
||||
@@ -133,6 +148,7 @@ namespace Discord
|
||||
/// </summary>
|
||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||
/// <returns>The current builder.</returns>
|
||||
[Obsolete("This method will be deprecated soon. Configure with WithContextTypes instead.")]
|
||||
public MessageCommandBuilder WithDMPermission(bool permission)
|
||||
{
|
||||
IsDMEnabled = permission;
|
||||
@@ -187,5 +203,31 @@ namespace Discord
|
||||
DefaultMemberPermissions = permissions;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the install method for this command.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Install types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public MessageCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = integrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(integrationTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets context types this command can be executed in.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public MessageCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = contextTypes is not null
|
||||
? new HashSet<InteractionContextType>(contextTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Discord
|
||||
/// <summary>
|
||||
/// Gets or sets whether or not this command can be used in DMs.
|
||||
/// </summary>
|
||||
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||
public bool IsDMEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
@@ -56,6 +57,16 @@ namespace Discord
|
||||
/// </summary>
|
||||
public GuildPermission? DefaultMemberPermissions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the installation method for this command. <see langword="null"/> if not set.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types this command can be executed in. <see langword="null"/> if not set.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; }
|
||||
|
||||
private string _name;
|
||||
private Dictionary<string, string> _nameLocalizations;
|
||||
|
||||
@@ -69,10 +80,14 @@ namespace Discord
|
||||
{
|
||||
Name = Name,
|
||||
IsDefaultPermission = IsDefaultPermission,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = IsDMEnabled,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||
NameLocalizations = NameLocalizations,
|
||||
IsNsfw = IsNsfw,
|
||||
ContextTypes = ContextTypes,
|
||||
IntegrationTypes = IntegrationTypes
|
||||
};
|
||||
|
||||
return props;
|
||||
@@ -131,6 +146,7 @@ namespace Discord
|
||||
/// </summary>
|
||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||
/// <returns>The current builder.</returns>
|
||||
[Obsolete("This method will be deprecated soon. Configure with WithContextTypes instead.")]
|
||||
public UserCommandBuilder WithDMPermission(bool permission)
|
||||
{
|
||||
IsDMEnabled = permission;
|
||||
@@ -185,5 +201,31 @@ namespace Discord
|
||||
DefaultMemberPermissions = permissions;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the installation method for this command.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Installation types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public UserCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = integrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(integrationTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets context types this command can be executed in.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public UserCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = contextTypes is not null
|
||||
? new HashSet<InteractionContextType>(contextTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,21 @@ namespace Discord
|
||||
/// </summary>
|
||||
IReadOnlyCollection<IEntitlement> Entitlements { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets which integrations authorized the interaction.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context this interaction was created in. <see langword="null"/> if context type is unknown.
|
||||
/// </summary>
|
||||
InteractionContextType? ContextType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions the app or bot has within the channel the interaction was sent from.
|
||||
/// </summary>
|
||||
GuildPermissions Permissions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the metadata of an application command interaction.
|
||||
/// </summary>
|
||||
public readonly struct ApplicationCommandInteractionMetadata : IMessageInteractionMetadata
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong Id { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public InteractionType Type { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong UserId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong? OriginalResponseMessageId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the command.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
internal ApplicationCommandInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
|
||||
ulong? originalResponseMessageId, string name)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
UserId = userId;
|
||||
IntegrationOwners = integrationOwners;
|
||||
OriginalResponseMessageId = originalResponseMessageId;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the metadata of an interaction.
|
||||
/// </summary>
|
||||
public interface IMessageInteractionMetadata : ISnowflakeEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of the interaction.
|
||||
/// </summary>
|
||||
InteractionType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the user who triggered the interaction.
|
||||
/// </summary>
|
||||
ulong UserId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Ids for installation contexts related to the interaction.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the original response message if the message is a followup.
|
||||
/// <see langword="null"/> on original response messages.
|
||||
/// </summary>
|
||||
ulong? OriginalResponseMessageId { get; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the metadata of a component interaction.
|
||||
/// </summary>
|
||||
public readonly struct MessageComponentInteractionMetadata : IMessageInteractionMetadata
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong Id { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public InteractionType Type { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong UserId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong? OriginalResponseMessageId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the message that was interacted with to trigger the interaction.
|
||||
/// </summary>
|
||||
public ulong InteractedMessageId { get; }
|
||||
|
||||
internal MessageComponentInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
|
||||
ulong? originalResponseMessageId, ulong interactedMessageId)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
UserId = userId;
|
||||
IntegrationOwners = integrationOwners;
|
||||
OriginalResponseMessageId = originalResponseMessageId;
|
||||
InteractedMessageId = interactedMessageId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the metadata of a modal interaction.
|
||||
/// </summary>
|
||||
public readonly struct ModalSubmitInteractionMetadata :IMessageInteractionMetadata
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong Id { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public InteractionType Type { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong UserId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong? OriginalResponseMessageId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interaction metadata of the interaction that responded with the modal.
|
||||
/// </summary>
|
||||
public IMessageInteractionMetadata TriggeringInteractionMetadata { get; }
|
||||
|
||||
internal ModalSubmitInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
|
||||
ulong? originalResponseMessageId, IMessageInteractionMetadata triggeringInteractionMetadata)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
UserId = userId;
|
||||
IntegrationOwners = integrationOwners;
|
||||
OriginalResponseMessageId = originalResponseMessageId;
|
||||
TriggeringInteractionMetadata = triggeringInteractionMetadata;
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,16 @@ namespace Discord
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> DescriptionLocalizations => _descriptionLocalizations;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types this command can be executed in. <see langword="null"/> if not set.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the installation method for this command. <see langword="null"/> if not set.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the command is enabled by default when the app is added to a guild
|
||||
/// </summary>
|
||||
@@ -83,6 +93,7 @@ namespace Discord
|
||||
/// <summary>
|
||||
/// Gets or sets whether or not this command can be used in DMs.
|
||||
/// </summary>
|
||||
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||
public bool IsDMEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
@@ -107,6 +118,10 @@ namespace Discord
|
||||
/// <returns>A <see cref="SlashCommandProperties"/> that can be used to create slash commands.</returns>
|
||||
public SlashCommandProperties Build()
|
||||
{
|
||||
// doing ?? 1 for now until we know default values (if these become non-optional)
|
||||
Preconditions.AtLeast(ContextTypes?.Count ?? 1, 1, nameof(ContextTypes), "At least 1 context type must be specified");
|
||||
Preconditions.AtLeast(IntegrationTypes?.Count ?? 1, 1, nameof(IntegrationTypes), "At least 1 integration type must be specified");
|
||||
|
||||
var props = new SlashCommandProperties
|
||||
{
|
||||
Name = Name,
|
||||
@@ -114,9 +129,13 @@ namespace Discord
|
||||
IsDefaultPermission = IsDefaultPermission,
|
||||
NameLocalizations = _nameLocalizations,
|
||||
DescriptionLocalizations = _descriptionLocalizations,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = IsDMEnabled,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||
IsNsfw = IsNsfw,
|
||||
ContextTypes = ContextTypes ?? Optional<HashSet<InteractionContextType>>.Unspecified,
|
||||
IntegrationTypes = IntegrationTypes ?? Optional<HashSet<ApplicationIntegrationType>>.Unspecified
|
||||
};
|
||||
|
||||
if (Options != null && Options.Any())
|
||||
@@ -171,6 +190,7 @@ namespace Discord
|
||||
/// </summary>
|
||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||
/// <returns>The current builder.</returns>
|
||||
[Obsolete("This method will be deprecated soon. Configure using WithContextTypes instead.")]
|
||||
public SlashCommandBuilder WithDMPermission(bool permission)
|
||||
{
|
||||
IsDMEnabled = permission;
|
||||
@@ -199,6 +219,32 @@ namespace Discord
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the installation method for this command.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Installation types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public SlashCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = integrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(integrationTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets context types this command can be executed in.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public SlashCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = contextTypes is not null
|
||||
? new HashSet<InteractionContextType>(contextTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an option to the current slash command.
|
||||
/// </summary>
|
||||
|
||||
@@ -215,6 +215,7 @@ namespace Discord
|
||||
/// <returns>
|
||||
/// A <see cref="IMessageInteraction"/> if the message is a response to an interaction; otherwise <see langword="null"/>.
|
||||
/// </returns>
|
||||
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||
IMessageInteraction Interaction { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,14 @@ namespace Discord
|
||||
/// </returns>
|
||||
IUserMessage ReferencedMessage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interaction metadata for the interaction this message is a response to.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Will be <see langword="null"/> if the message is not a response to an interaction.
|
||||
/// </remarks>
|
||||
IMessageInteractionMetadata InteractionMetadata { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Modifies this message.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Interactions;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies context types this command can be executed in.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class CommandContextTypeAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets context types this command can be executed in.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IApplicationCommandInfo.ContextTypes"/> property of an application command or module.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types set for the command.</param>
|
||||
public CommandContextTypeAttribute(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = contextTypes?.Distinct().ToImmutableArray()
|
||||
?? throw new ArgumentNullException(nameof(contextTypes));
|
||||
|
||||
if (ContextTypes.Count == 0)
|
||||
throw new ArgumentException("A command must have at least one supported context type.", nameof(contextTypes));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace Discord.Interactions
|
||||
/// Sets the <see cref="IApplicationCommandInfo.IsEnabledInDm"/> property of an application command or module.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
[Obsolete("This attribute will be deprecated soon. Configure with CommandContextTypes attribute instead.")]
|
||||
public class EnabledInDmAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Interactions;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies install method for the command.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class IntegrationTypeAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets integration install types for this command.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IApplicationCommandInfo.IntegrationTypes"/> property of an application command or module.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Integration install types set for the command.</param>
|
||||
public IntegrationTypeAttribute(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = integrationTypes?.Distinct().ToImmutableArray()
|
||||
?? throw new ArgumentNullException(nameof(integrationTypes));
|
||||
|
||||
if (integrationTypes.Length == 0)
|
||||
throw new ArgumentException("A command must have at least one integration type.", nameof(integrationTypes));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Interactions.Builders
|
||||
{
|
||||
@@ -35,7 +36,24 @@ namespace Discord.Interactions.Builders
|
||||
/// </summary>
|
||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
||||
|
||||
internal ContextCommandBuilder(ModuleBuilder module) : base(module) { }
|
||||
/// <summary>
|
||||
/// Gets the install method for this command.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types this command can be executed in.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; } = null;
|
||||
|
||||
internal ContextCommandBuilder(ModuleBuilder module) : base(module)
|
||||
{
|
||||
IntegrationTypes = module.IntegrationTypes;
|
||||
ContextTypes = module.ContextTypes;
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsEnabledInDm = module.IsEnabledInDm;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="ContextCommandBuilder"/>.
|
||||
@@ -126,6 +144,28 @@ namespace Discord.Interactions.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IntegrationTypes"/> of this <see cref="ContextCommandBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Install types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ContextCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = new HashSet<ApplicationIntegrationType>(integrationTypes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ContextTypes"/> of this <see cref="ContextCommandBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ContextCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = new HashSet<InteractionContextType>(contextTypes);
|
||||
return this;
|
||||
}
|
||||
|
||||
internal override ContextCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||
ContextCommandInfo.Create(this, module, commandService);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Interactions.Builders
|
||||
{
|
||||
@@ -35,7 +36,24 @@ namespace Discord.Interactions.Builders
|
||||
/// </summary>
|
||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
||||
|
||||
internal SlashCommandBuilder(ModuleBuilder module) : base(module) { }
|
||||
/// <summary>
|
||||
/// Gets or sets the install method for this command.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the context types this command can be executed in.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; } = null;
|
||||
|
||||
internal SlashCommandBuilder(ModuleBuilder module) : base(module)
|
||||
{
|
||||
IntegrationTypes = module.IntegrationTypes;
|
||||
ContextTypes = module.ContextTypes;
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsEnabledInDm = module.IsEnabledInDm;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="SlashCommandBuilder"/>.
|
||||
@@ -126,6 +144,32 @@ namespace Discord.Interactions.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IntegrationTypes"/> on this <see cref="SlashCommandBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Install types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public SlashCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = integrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(integrationTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ContextTypes"/> on this <see cref="SlashCommandBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public SlashCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = contextTypes is not null
|
||||
? new HashSet<InteractionContextType>(contextTypes)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal override SlashCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||
new SlashCommandInfo(this, module, commandService);
|
||||
}
|
||||
|
||||
@@ -51,12 +51,13 @@ namespace Discord.Interactions.Builders
|
||||
/// <summary>
|
||||
/// Gets and sets the default permission of this module.
|
||||
/// </summary>
|
||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")]
|
||||
[Obsolete($"To be deprecated soon, use {nameof(ContextTypes)} and {nameof(DefaultMemberPermissions)} instead.")]
|
||||
public bool DefaultPermission { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this command can be used in DMs.
|
||||
/// </summary>
|
||||
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||
public bool IsEnabledInDm { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
@@ -114,6 +115,16 @@ namespace Discord.Interactions.Builders
|
||||
/// </summary>
|
||||
public IReadOnlyList<ModalCommandBuilder> ModalCommands => _modalCommands;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the install method for this command.
|
||||
/// </summary>
|
||||
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the context types this command can be executed in.
|
||||
/// </summary>
|
||||
public HashSet<InteractionContextType> ContextTypes { get; set; } = null;
|
||||
|
||||
internal TypeInfo TypeInfo { get; set; }
|
||||
|
||||
internal ModuleBuilder(InteractionService interactionService, ModuleBuilder parent = null)
|
||||
@@ -189,6 +200,7 @@ namespace Discord.Interactions.Builders
|
||||
/// <returns>
|
||||
/// The builder instance.
|
||||
/// </returns>
|
||||
[Obsolete("This method will be deprecated soon. Use WithContextTypes instead.")]
|
||||
public ModuleBuilder SetEnabledInDm(bool isEnabled)
|
||||
{
|
||||
IsEnabledInDm = isEnabled;
|
||||
@@ -423,6 +435,28 @@ namespace Discord.Interactions.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IntegrationTypes"/> on this <see cref="ModuleBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="integrationTypes">Install types for this command.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ModuleBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)
|
||||
{
|
||||
IntegrationTypes = new HashSet<ApplicationIntegrationType>(integrationTypes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ContextTypes"/> on this <see cref="ModuleBuilder"/>.
|
||||
/// </summary>
|
||||
/// <param name="contextTypes">Context types the command can be executed in.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ModuleBuilder WithContextTypes(params InteractionContextType[] contextTypes)
|
||||
{
|
||||
ContextTypes = new HashSet<InteractionContextType>(contextTypes);
|
||||
return this;
|
||||
}
|
||||
|
||||
internal ModuleInfo Build(InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
|
||||
{
|
||||
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -87,11 +88,13 @@ namespace Discord.Interactions.Builders
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
case EnabledInDmAttribute enabledInDm:
|
||||
{
|
||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
case DefaultMemberPermissionsAttribute memberPermission:
|
||||
{
|
||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||
@@ -106,6 +109,12 @@ namespace Discord.Interactions.Builders
|
||||
case NsfwCommandAttribute nsfwCommand:
|
||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||
break;
|
||||
case CommandContextTypeAttribute contextType:
|
||||
builder.WithContextTypes(contextType.ContextTypes?.ToArray());
|
||||
break;
|
||||
case IntegrationTypeAttribute integrationType:
|
||||
builder.WithIntegrationTypes(integrationType.IntegrationTypes?.ToArray());
|
||||
break;
|
||||
default:
|
||||
builder.AddAttributes(attribute);
|
||||
break;
|
||||
@@ -185,12 +194,12 @@ namespace Discord.Interactions.Builders
|
||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
case EnabledInDmAttribute enabledInDm:
|
||||
{
|
||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
case DefaultMemberPermissionsAttribute memberPermission:
|
||||
{
|
||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||
@@ -202,6 +211,12 @@ namespace Discord.Interactions.Builders
|
||||
case NsfwCommandAttribute nsfwCommand:
|
||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||
break;
|
||||
case CommandContextTypeAttribute contextType:
|
||||
builder.WithContextTypes(contextType.ContextTypes.ToArray());
|
||||
break;
|
||||
case IntegrationTypeAttribute integrationType:
|
||||
builder.WithIntegrationTypes(integrationType.IntegrationTypes.ToArray());
|
||||
break;
|
||||
default:
|
||||
builder.WithAttributes(attribute);
|
||||
break;
|
||||
@@ -242,12 +257,12 @@ namespace Discord.Interactions.Builders
|
||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
case EnabledInDmAttribute enabledInDm:
|
||||
{
|
||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||
}
|
||||
break;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
case DefaultMemberPermissionsAttribute memberPermission:
|
||||
{
|
||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||
@@ -259,6 +274,12 @@ namespace Discord.Interactions.Builders
|
||||
case NsfwCommandAttribute nsfwCommand:
|
||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||
break;
|
||||
case CommandContextTypeAttribute contextType:
|
||||
builder.WithContextTypes(contextType.ContextTypes.ToArray());
|
||||
break;
|
||||
case IntegrationTypeAttribute integrationType:
|
||||
builder.WithIntegrationTypes(integrationType.IntegrationTypes.ToArray());
|
||||
break;
|
||||
default:
|
||||
builder.WithAttributes(attribute);
|
||||
break;
|
||||
|
||||
@@ -26,6 +26,12 @@ namespace Discord.Interactions
|
||||
/// <inheritdoc/>
|
||||
public GuildPermission? DefaultMemberPermissions { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IReadOnlyList<CommandParameterInfo> Parameters { get; }
|
||||
|
||||
@@ -46,6 +52,8 @@ namespace Discord.Interactions
|
||||
IsEnabledInDm = builder.IsEnabledInDm;
|
||||
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
||||
ContextTypes = builder.ContextTypes?.ToImmutableArray();
|
||||
IntegrationTypes = builder.IntegrationTypes?.ToImmutableArray();
|
||||
}
|
||||
|
||||
internal static ContextCommandInfo Create(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
||||
|
||||
@@ -46,6 +46,12 @@ namespace Discord.Interactions
|
||||
/// </summary>
|
||||
public IReadOnlyList<SlashCommandParameterInfo> FlattenedParameters { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
|
||||
internal SlashCommandInfo(Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
|
||||
{
|
||||
Description = builder.Description;
|
||||
@@ -57,6 +63,8 @@ namespace Discord.Interactions
|
||||
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
||||
FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray();
|
||||
ContextTypes = builder.ContextTypes?.ToImmutableArray();
|
||||
IntegrationTypes = builder.IntegrationTypes?.ToImmutableArray();
|
||||
|
||||
for (var i = 0; i < FlattenedParameters.Count - 1; i++)
|
||||
if (!FlattenedParameters.ElementAt(i).IsRequired && FlattenedParameters.ElementAt(i + 1).IsRequired)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Interactions
|
||||
{
|
||||
@@ -37,5 +38,15 @@ namespace Discord.Interactions
|
||||
/// Gets the default permissions needed for executing this command.
|
||||
/// </summary>
|
||||
public GuildPermission? DefaultMemberPermissions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types this command can be executed in.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the install methods for this command.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,16 @@ namespace Discord.Interactions
|
||||
/// </summary>
|
||||
public bool DontAutoRegister { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context types commands in this module can be executed in.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the install method for commands in this module.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||
|
||||
internal ModuleInfo(ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null)
|
||||
{
|
||||
CommandService = commandService;
|
||||
@@ -129,7 +139,9 @@ namespace Discord.Interactions
|
||||
DefaultPermission = builder.DefaultPermission;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsNsfw = builder.IsNsfw;
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsEnabledInDm = builder.IsEnabledInDm;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = BuildDefaultMemberPermissions(builder);
|
||||
SlashCommands = BuildSlashCommands(builder).ToImmutableArray();
|
||||
ContextCommands = BuildContextCommands(builder).ToImmutableArray();
|
||||
@@ -141,6 +153,8 @@ namespace Discord.Interactions
|
||||
Preconditions = BuildPreconditions(builder).ToImmutableArray();
|
||||
IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent);
|
||||
DontAutoRegister = builder.DontAutoRegister;
|
||||
ContextTypes = builder.ContextTypes?.ToImmutableArray();
|
||||
IntegrationTypes = builder.IntegrationTypes?.ToImmutableArray();
|
||||
|
||||
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
@@ -53,9 +53,17 @@ namespace Discord.Interactions
|
||||
Name = commandInfo.Name,
|
||||
Description = commandInfo.Description,
|
||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = commandInfo.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsNsfw = commandInfo.IsNsfw,
|
||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
||||
IntegrationTypes = commandInfo.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(commandInfo.IntegrationTypes)
|
||||
: null,
|
||||
ContextTypes = commandInfo.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(commandInfo.ContextTypes)
|
||||
: null,
|
||||
}.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||
.WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||
.Build();
|
||||
@@ -82,7 +90,7 @@ namespace Discord.Interactions
|
||||
Options = commandInfo.FlattenedParameters?.Select(x => x.ToApplicationCommandOptionProps())
|
||||
?.ToList(),
|
||||
NameLocalizations = localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty,
|
||||
DescriptionLocalizations = localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty
|
||||
DescriptionLocalizations = localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,8 +106,16 @@ namespace Discord.Interactions
|
||||
Name = commandInfo.Name,
|
||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = commandInfo.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsNsfw = commandInfo.IsNsfw,
|
||||
IntegrationTypes = commandInfo.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(commandInfo.IntegrationTypes)
|
||||
: null,
|
||||
ContextTypes = commandInfo.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(commandInfo.ContextTypes)
|
||||
: null,
|
||||
}
|
||||
.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||
.Build(),
|
||||
@@ -109,7 +125,15 @@ namespace Discord.Interactions
|
||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
||||
IsNsfw = commandInfo.IsNsfw,
|
||||
IsDMEnabled = commandInfo.IsEnabledInDm
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = commandInfo.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IntegrationTypes = commandInfo.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(commandInfo.IntegrationTypes)
|
||||
: null,
|
||||
ContextTypes = commandInfo.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(commandInfo.ContextTypes)
|
||||
: null,
|
||||
}
|
||||
.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||
.Build(),
|
||||
@@ -165,10 +189,16 @@ namespace Discord.Interactions
|
||||
Description = moduleInfo.Description,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDefaultPermission = moduleInfo.DefaultPermission,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = moduleInfo.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsNsfw = moduleInfo.IsNsfw,
|
||||
DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions
|
||||
DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions,
|
||||
IntegrationTypes = moduleInfo.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(moduleInfo.IntegrationTypes)
|
||||
: null,
|
||||
ContextTypes = moduleInfo.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(moduleInfo.ContextTypes)
|
||||
: null,
|
||||
}
|
||||
.WithNameLocalizations(localizationManager?.GetAllNames(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary<string, string>.Empty)
|
||||
.WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary<string, string>.Empty)
|
||||
@@ -230,11 +260,19 @@ namespace Discord.Interactions
|
||||
Description = command.Description,
|
||||
IsDefaultPermission = command.IsDefaultPermission,
|
||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = command.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
IsNsfw = command.IsNsfw,
|
||||
Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional<List<ApplicationCommandOptionProperties>>.Unspecified,
|
||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
ContextTypes = command.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(command.ContextTypes)
|
||||
: Optional<HashSet<InteractionContextType>>.Unspecified,
|
||||
IntegrationTypes = command.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(command.IntegrationTypes)
|
||||
: Optional<HashSet<ApplicationIntegrationType>>.Unspecified,
|
||||
},
|
||||
ApplicationCommandType.User => new UserCommandProperties
|
||||
{
|
||||
@@ -242,9 +280,17 @@ namespace Discord.Interactions
|
||||
IsDefaultPermission = command.IsDefaultPermission,
|
||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||
IsNsfw = command.IsNsfw,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = command.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty
|
||||
DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
ContextTypes = command.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(command.ContextTypes)
|
||||
: Optional<HashSet<InteractionContextType>>.Unspecified,
|
||||
IntegrationTypes = command.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(command.IntegrationTypes)
|
||||
: Optional<HashSet<ApplicationIntegrationType>>.Unspecified,
|
||||
},
|
||||
ApplicationCommandType.Message => new MessageCommandProperties
|
||||
{
|
||||
@@ -252,9 +298,17 @@ namespace Discord.Interactions
|
||||
IsDefaultPermission = command.IsDefaultPermission,
|
||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||
IsNsfw = command.IsNsfw,
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsDMEnabled = command.IsEnabledInDm,
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty
|
||||
DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
||||
ContextTypes = command.ContextTypes is not null
|
||||
? new HashSet<InteractionContextType>(command.ContextTypes)
|
||||
: Optional<HashSet<InteractionContextType>>.Unspecified,
|
||||
IntegrationTypes = command.IntegrationTypes is not null
|
||||
? new HashSet<ApplicationIntegrationType>(command.IntegrationTypes)
|
||||
: Optional<HashSet<ApplicationIntegrationType>>.Unspecified,
|
||||
},
|
||||
_ => throw new InvalidOperationException($"Cannot create command properties for command type {command.Type}"),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
@@ -94,4 +95,10 @@ internal class Application
|
||||
|
||||
[JsonProperty("verification_state")]
|
||||
public Optional<ApplicationVerificationState> VerificationState { get; set; }
|
||||
|
||||
[JsonProperty("integration_types")]
|
||||
public Optional<ApplicationIntegrationType[]> IntegrationTypes { get; set; }
|
||||
|
||||
[JsonProperty("integration_types_config")]
|
||||
public Optional<Dictionary<ApplicationIntegrationType, InstallParams>> IntegrationTypesConfig { get; set; }
|
||||
}
|
||||
|
||||
@@ -50,5 +50,11 @@ namespace Discord.API
|
||||
|
||||
[JsonProperty("nsfw")]
|
||||
public Optional<bool?> Nsfw { get; set; }
|
||||
|
||||
[JsonProperty("contexts")]
|
||||
public Optional<InteractionContextType[]> ContextTypes { get; set; }
|
||||
|
||||
[JsonProperty("integration_types")]
|
||||
public Optional<ApplicationIntegrationType[]> IntegrationTypes { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@ internal class InstallParams
|
||||
public string[] Scopes { get; set; }
|
||||
|
||||
[JsonProperty("permissions")]
|
||||
public ulong Permission { get; set; }
|
||||
public GuildPermission Permission { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
[JsonConverter(typeof(Net.Converters.InteractionConverter))]
|
||||
internal class Interaction
|
||||
{
|
||||
[JsonConverter(typeof(Net.Converters.InteractionConverter))]
|
||||
internal class Interaction
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
|
||||
@@ -20,12 +22,12 @@ namespace Discord.API
|
||||
[JsonProperty("guild_id")]
|
||||
public Optional<ulong> GuildId { get; set; }
|
||||
|
||||
[JsonProperty("channel_id")]
|
||||
public Optional<ulong> ChannelId { get; set; }
|
||||
|
||||
[JsonProperty("channel")]
|
||||
public Optional<Channel> Channel { get; set; }
|
||||
|
||||
[JsonProperty("channel_id")]
|
||||
public Optional<ulong> ChannelId { get; set; }
|
||||
|
||||
[JsonProperty("member")]
|
||||
public Optional<GuildMember> Member { get; set; }
|
||||
|
||||
@@ -49,5 +51,13 @@ namespace Discord.API
|
||||
|
||||
[JsonProperty("entitlements")]
|
||||
public Entitlement[] Entitlements { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("authorizing_integration_owners")]
|
||||
public Dictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; set; }
|
||||
|
||||
[JsonProperty("context")]
|
||||
public Optional<InteractionContextType> ContextType { get; set; }
|
||||
|
||||
[JsonProperty("app_permissions")]
|
||||
public GuildPermission ApplicationPermissions { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,67 +1,95 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
namespace Discord.API;
|
||||
|
||||
internal class Message
|
||||
{
|
||||
internal class Message
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
|
||||
// ALWAYS sent on WebSocket messages
|
||||
[JsonProperty("guild_id")]
|
||||
public Optional<ulong> GuildId { get; set; }
|
||||
|
||||
[JsonProperty("webhook_id")]
|
||||
public Optional<ulong> WebhookId { get; set; }
|
||||
|
||||
[JsonProperty("author")]
|
||||
public Optional<User> Author { get; set; }
|
||||
|
||||
// ALWAYS sent on WebSocket messages
|
||||
[JsonProperty("member")]
|
||||
public Optional<GuildMember> Member { get; set; }
|
||||
|
||||
[JsonProperty("content")]
|
||||
public Optional<string> Content { get; set; }
|
||||
|
||||
[JsonProperty("timestamp")]
|
||||
public Optional<DateTimeOffset> Timestamp { get; set; }
|
||||
|
||||
[JsonProperty("edited_timestamp")]
|
||||
public Optional<DateTimeOffset?> EditedTimestamp { get; set; }
|
||||
|
||||
[JsonProperty("tts")]
|
||||
public Optional<bool> IsTextToSpeech { get; set; }
|
||||
|
||||
[JsonProperty("mention_everyone")]
|
||||
public Optional<bool> MentionEveryone { get; set; }
|
||||
|
||||
[JsonProperty("mentions")]
|
||||
public Optional<User[]> UserMentions { get; set; }
|
||||
|
||||
[JsonProperty("mention_roles")]
|
||||
public Optional<ulong[]> RoleMentions { get; set; }
|
||||
|
||||
[JsonProperty("attachments")]
|
||||
public Optional<Attachment[]> Attachments { get; set; }
|
||||
|
||||
[JsonProperty("embeds")]
|
||||
public Optional<Embed[]> Embeds { get; set; }
|
||||
|
||||
[JsonProperty("pinned")]
|
||||
public Optional<bool> Pinned { get; set; }
|
||||
|
||||
[JsonProperty("reactions")]
|
||||
public Optional<Reaction[]> Reactions { get; set; }
|
||||
|
||||
// sent with Rich Presence-related chat embeds
|
||||
[JsonProperty("activity")]
|
||||
public Optional<MessageActivity> Activity { get; set; }
|
||||
|
||||
// sent with Rich Presence-related chat embeds
|
||||
[JsonProperty("application")]
|
||||
public Optional<MessageApplication> Application { get; set; }
|
||||
|
||||
[JsonProperty("message_reference")]
|
||||
public Optional<MessageReference> Reference { get; set; }
|
||||
|
||||
[JsonProperty("flags")]
|
||||
public Optional<MessageFlags> Flags { get; set; }
|
||||
|
||||
[JsonProperty("allowed_mentions")]
|
||||
public Optional<AllowedMentions> AllowedMentions { get; set; }
|
||||
|
||||
[JsonProperty("referenced_message")]
|
||||
public Optional<Message> ReferencedMessage { get; set; }
|
||||
|
||||
[JsonProperty("components")]
|
||||
public Optional<API.ActionRowComponent[]> Components { get; set; }
|
||||
public Optional<ActionRowComponent[]> Components { get; set; }
|
||||
|
||||
[JsonProperty("interaction")]
|
||||
public Optional<MessageInteraction> Interaction { get; set; }
|
||||
|
||||
[JsonProperty("sticker_items")]
|
||||
public Optional<StickerItem[]> StickerItems { get; set; }
|
||||
|
||||
[JsonProperty("role_subscription_data")]
|
||||
public Optional<MessageRoleSubscriptionData> RoleSubscriptionData { get; set; }
|
||||
|
||||
@@ -70,5 +98,7 @@ namespace Discord.API
|
||||
|
||||
[JsonProperty("resolved")]
|
||||
public Optional<MessageComponentInteractionDataResolved> Resolved { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("interaction_metadata")]
|
||||
public Optional<MessageInteractionMetadata> InteractionMetadata { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class MessageInteractionMetadata
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public InteractionType Type { get; set; }
|
||||
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
|
||||
[JsonProperty("authorizing_integration_owners")]
|
||||
public Dictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; set; }
|
||||
|
||||
[JsonProperty("original_response_message_id")]
|
||||
public Optional<ulong> OriginalResponseMessageId { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public Optional<string> Name { get; set; }
|
||||
|
||||
[JsonProperty("interacted_message_id")]
|
||||
public Optional<ulong> InteractedMessageId { get; set; }
|
||||
|
||||
[JsonProperty("triggering_interaction_metadata")]
|
||||
public Optional<MessageInteractionMetadata> TriggeringInteractionMetadata { get; set; }
|
||||
}
|
||||
@@ -38,9 +38,17 @@ namespace Discord.API.Rest
|
||||
[JsonProperty("nsfw")]
|
||||
public Optional<bool> Nsfw { get; set; }
|
||||
|
||||
[JsonProperty("contexts")]
|
||||
public Optional<HashSet<InteractionContextType>> ContextTypes { get; set; }
|
||||
|
||||
[JsonProperty("integration_types")]
|
||||
public Optional<HashSet<ApplicationIntegrationType>> IntegrationTypes { 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, bool nsfw = false)
|
||||
IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null, bool nsfw = false,
|
||||
HashSet<InteractionContextType> contextTypes = null, HashSet<ApplicationIntegrationType> integrationTypes = null)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
@@ -49,6 +57,8 @@ namespace Discord.API.Rest
|
||||
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;
|
||||
ContextTypes = contextTypes ?? Optional.Create<HashSet<InteractionContextType>>();
|
||||
IntegrationTypes = integrationTypes ?? Optional.Create<HashSet<ApplicationIntegrationType>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,5 +28,11 @@ namespace Discord.API.Rest
|
||||
|
||||
[JsonProperty("description_localizations")]
|
||||
public Optional<Dictionary<string, string>> DescriptionLocalizations { get; set; }
|
||||
|
||||
[JsonProperty("contexts")]
|
||||
public Optional<HashSet<InteractionContextType>> ContextTypes { get; set; }
|
||||
|
||||
[JsonProperty("integration_types")]
|
||||
public Optional<HashSet<ApplicationIntegrationType>> IntegrationTypes { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.API.Rest;
|
||||
|
||||
@@ -30,4 +31,7 @@ internal class ModifyCurrentApplicationBotParams
|
||||
|
||||
[JsonProperty("tags")]
|
||||
public Optional<string[]> Tags { get; set; }
|
||||
|
||||
[JsonProperty("integration_types_config")]
|
||||
public Optional<Dictionary<ApplicationIntegrationType, InstallParams>> IntegrationTypesConfig { get; set; }
|
||||
}
|
||||
|
||||
@@ -55,10 +55,17 @@ namespace Discord.Rest
|
||||
? null
|
||||
: new InstallParams
|
||||
{
|
||||
Permission = (ulong)args.InstallParams.Value.Permission,
|
||||
Permission = args.InstallParams.Value.Permission,
|
||||
Scopes = args.InstallParams.Value.Scopes.ToArray()
|
||||
}
|
||||
: Optional<InstallParams>.Unspecified,
|
||||
IntegrationTypesConfig = args.IntegrationTypesConfig.IsSpecified
|
||||
? args.IntegrationTypesConfig.Value?.ToDictionary(x => x.Key, x => new InstallParams
|
||||
{
|
||||
Permission = x.Value.Permission,
|
||||
Scopes = x.Value.Scopes.ToArray()
|
||||
})
|
||||
: Optional<Dictionary<ApplicationIntegrationType, InstallParams>>.Unspecified
|
||||
}, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ namespace Discord.Rest
|
||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
|
||||
IntegrationTypes = arg.IntegrationTypes,
|
||||
ContextTypes = arg.ContextTypes
|
||||
};
|
||||
|
||||
if (arg is SlashCommandProperties slashProps)
|
||||
@@ -146,7 +148,9 @@ namespace Discord.Rest
|
||||
// TODO: better conversion to nullable optionals
|
||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
|
||||
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
|
||||
IntegrationTypes = arg.IntegrationTypes,
|
||||
ContextTypes = arg.ContextTypes
|
||||
};
|
||||
|
||||
if (arg is SlashCommandProperties slashProps)
|
||||
@@ -190,7 +194,9 @@ namespace Discord.Rest
|
||||
// TODO: better conversion to nullable optionals
|
||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
|
||||
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
|
||||
IntegrationTypes = arg.IntegrationTypes,
|
||||
ContextTypes = arg.ContextTypes
|
||||
};
|
||||
|
||||
if (arg is SlashCommandProperties slashProps)
|
||||
@@ -254,7 +260,9 @@ namespace Discord.Rest
|
||||
NameLocalizations = args.NameLocalizations?.ToDictionary(),
|
||||
DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary(),
|
||||
Nsfw = args.IsNsfw.GetValueOrDefault(false),
|
||||
DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable()
|
||||
DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable(),
|
||||
IntegrationTypes = args.IntegrationTypes,
|
||||
ContextTypes = args.ContextTypes
|
||||
};
|
||||
|
||||
if (args is SlashCommandProperties slashProps)
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Discord.Rest
|
||||
public bool IsDefaultPermission { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||
public bool IsEnabledInDm { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -67,6 +68,12 @@ namespace Discord.Rest
|
||||
/// </remarks>
|
||||
public string DescriptionLocalized { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt
|
||||
=> SnowflakeUtils.FromSnowflake(Id);
|
||||
@@ -102,9 +109,14 @@ namespace Discord.Rest
|
||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||
|
||||
IntegrationTypes = model.IntegrationTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||
ContextTypes = model.ContextTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -90,9 +90,18 @@ namespace Discord.Rest
|
||||
/// <inheritdoc/>
|
||||
public ulong ApplicationId { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public InteractionContextType? ContextType { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GuildPermissions Permissions { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
||||
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; private set; }
|
||||
|
||||
internal RestInteraction(BaseDiscordClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
@@ -232,6 +241,13 @@ namespace Discord.Rest
|
||||
: null;
|
||||
|
||||
Entitlements = model.Entitlements.Select(x => RestEntitlement.Create(discord, x)).ToImmutableArray();
|
||||
|
||||
IntegrationOwners = model.IntegrationOwners;
|
||||
ContextType = model.ContextType.IsSpecified
|
||||
? model.ContextType.Value
|
||||
: null;
|
||||
|
||||
Permissions = new GuildPermissions((ulong)model.ApplicationPermissions);
|
||||
}
|
||||
|
||||
internal string SerializePayload(object payload)
|
||||
|
||||
@@ -308,6 +308,7 @@ namespace Discord.Rest
|
||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||
IMessageInteraction IMessage.Interaction => Interaction;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public IUserMessage ReferencedMessage => _referencedMessage;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMessageInteractionMetadata InteractionMetadata { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public MessageResolvedData ResolvedData { get; internal set; }
|
||||
|
||||
@@ -162,6 +165,8 @@ namespace Discord.Rest
|
||||
|
||||
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
||||
}
|
||||
if (model.InteractionMetadata.IsSpecified)
|
||||
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -6,14 +6,14 @@ using System.Threading.Tasks;
|
||||
|
||||
using Model = Discord.API.Application;
|
||||
|
||||
namespace Discord.Rest
|
||||
namespace Discord.Rest;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a REST-based entity that contains information about a Discord application created via the developer portal.
|
||||
/// </summary>
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RestApplication : RestEntity<ulong>, IApplication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a REST-based entity that contains information about a Discord application created via the developer portal.
|
||||
/// </summary>
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RestApplication : RestEntity<ulong>, IApplication
|
||||
{
|
||||
protected string _iconId;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -103,6 +103,9 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<string> Tags { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ApplicationInstallParams> IntegrationTypesConfig { get; private set; }
|
||||
|
||||
internal RestApplication(BaseDiscordClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
@@ -165,6 +168,16 @@ namespace Discord.Rest
|
||||
RpcState = model.RpcState.GetValueOrDefault(ApplicationRpcState.Disabled);
|
||||
StoreState = model.StoreState.GetValueOrDefault(ApplicationStoreState.None);
|
||||
VerificationState = model.VerificationState.GetValueOrDefault(ApplicationVerificationState.Ineligible);
|
||||
|
||||
var dict = new Dictionary<ApplicationIntegrationType, ApplicationInstallParams>();
|
||||
if (model.IntegrationTypesConfig.IsSpecified)
|
||||
{
|
||||
foreach (var p in model.IntegrationTypesConfig.Value)
|
||||
{
|
||||
dict.Add(p.Key, new ApplicationInstallParams(p.Value.Scopes ?? Array.Empty<string>(), p.Value.Permission));
|
||||
}
|
||||
}
|
||||
IntegrationTypesConfig = dict.ToImmutableDictionary();
|
||||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException">Unable to update this object from a different application token.</exception>
|
||||
@@ -180,9 +193,8 @@ namespace Discord.Rest
|
||||
/// Gets the name of the application.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Name of the application.
|
||||
/// The name of the application.
|
||||
/// </returns>
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Discord.Rest;
|
||||
|
||||
internal static class InteractionMetadataExtensions
|
||||
{
|
||||
public static IMessageInteractionMetadata ToInteractionMetadata(this API.MessageInteractionMetadata metadata)
|
||||
{
|
||||
switch (metadata.Type)
|
||||
{
|
||||
case InteractionType.ApplicationCommand:
|
||||
return new ApplicationCommandInteractionMetadata(
|
||||
metadata.Id,
|
||||
metadata.Type,
|
||||
metadata.UserId,
|
||||
metadata.IntegrationOwners.ToImmutableDictionary(),
|
||||
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
|
||||
metadata.Name.GetValueOrDefault(null));
|
||||
|
||||
case InteractionType.MessageComponent:
|
||||
return new MessageComponentInteractionMetadata(
|
||||
metadata.Id,
|
||||
metadata.Type,
|
||||
metadata.UserId,
|
||||
metadata.IntegrationOwners.ToImmutableDictionary(),
|
||||
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
|
||||
metadata.InteractedMessageId.GetValueOrDefault(0));
|
||||
|
||||
case InteractionType.ModalSubmit:
|
||||
return new ModalSubmitInteractionMetadata(
|
||||
metadata.Id,
|
||||
metadata.Type,
|
||||
metadata.UserId,
|
||||
metadata.IntegrationOwners.ToImmutableDictionary(),
|
||||
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
|
||||
metadata.TriggeringInteractionMetadata.GetValueOrDefault(null)?.ToInteractionMetadata());
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ namespace Discord.WebSocket
|
||||
public bool IsDefaultPermission { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||
public bool IsEnabledInDm { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -79,6 +80,12 @@ namespace Discord.WebSocket
|
||||
/// </remarks>
|
||||
public string DescriptionLocalized { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt
|
||||
=> SnowflakeUtils.FromSnowflake(Id);
|
||||
@@ -131,9 +138,14 @@ namespace Discord.WebSocket
|
||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||
|
||||
IntegrationTypes = model.IntegrationTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||
ContextTypes = model.ContextTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -73,9 +73,18 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc/>
|
||||
public ulong ApplicationId { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public InteractionContextType? ContextType { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GuildPermissions Permissions { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
||||
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; private set; }
|
||||
|
||||
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
|
||||
: base(client, id)
|
||||
{
|
||||
@@ -149,6 +158,13 @@ namespace Discord.WebSocket
|
||||
: null;
|
||||
|
||||
Entitlements = model.Entitlements.Select(x => RestEntitlement.Create(Discord, x)).ToImmutableArray();
|
||||
|
||||
IntegrationOwners = model.IntegrationOwners;
|
||||
ContextType = model.ContextType.IsSpecified
|
||||
? model.ContextType.Value
|
||||
: null;
|
||||
|
||||
Permissions = new GuildPermissions((ulong)model.ApplicationPermissions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -334,6 +334,7 @@ namespace Discord.WebSocket
|
||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||
IMessageInteraction IMessage.Interaction => Interaction;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public IUserMessage ReferencedMessage => _referencedMessage;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMessageInteractionMetadata InteractionMetadata { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public MessageResolvedData ResolvedData { get; internal set; }
|
||||
|
||||
@@ -203,6 +206,9 @@ namespace Discord.WebSocket
|
||||
|
||||
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
||||
}
|
||||
|
||||
if (model.InteractionMetadata.IsSpecified)
|
||||
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user