[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.
|
3. Type's only public constuctor.
|
||||||
|
|
||||||
#### DM Permissions
|
#### 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.
|
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
|
[AutocompleteHandlers]: xref:Guides.IntFw.AutoCompletion
|
||||||
[DependencyInjection]: xref:Guides.DI.Intro
|
[DependencyInjection]: xref:Guides.DI.Intro
|
||||||
|
|
||||||
@@ -447,6 +455,8 @@ Discord Slash Commands support name/description localization. Localization is av
|
|||||||
[ChannelTypesAttribute]: xref:Discord.Interactions.ChannelTypesAttribute
|
[ChannelTypesAttribute]: xref:Discord.Interactions.ChannelTypesAttribute
|
||||||
[MaxValueAttribute]: xref:Discord.Interactions.MaxValueAttribute
|
[MaxValueAttribute]: xref:Discord.Interactions.MaxValueAttribute
|
||||||
[MinValueAttribute]: xref:Discord.Interactions.MinValueAttribute
|
[MinValueAttribute]: xref:Discord.Interactions.MinValueAttribute
|
||||||
|
[EnabledInDmAttribute]: xref:Discord.Interactions.EnabledInDmAttribute
|
||||||
|
[CommandContextTypes]: xref:Discord.Interactions.CommandContextTypesAttribute
|
||||||
|
|
||||||
[IChannel]: xref:Discord.IChannel
|
[IChannel]: xref:Discord.IChannel
|
||||||
[IRole]: xref:Discord.IRole
|
[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
|
- name: Home
|
||||||
href: index.md
|
href: index.md
|
||||||
- name: Documentation
|
|
||||||
href: api/
|
|
||||||
topicUid: API.Docs
|
|
||||||
- name: Guides
|
- name: Guides
|
||||||
href: guides/
|
href: guides/
|
||||||
topicUid: Guides.Introduction
|
topicUid: Guides.Introduction
|
||||||
|
- name: API Reference
|
||||||
|
href: api/
|
||||||
|
topicUid: API.Docs
|
||||||
- name: FAQ
|
- name: FAQ
|
||||||
href: faq/
|
href: faq/
|
||||||
topicUid: FAQ.Basics.GetStarted
|
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.
|
/// Gets the application's verification state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ApplicationVerificationState VerificationState { get; }
|
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;
|
namespace Discord;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,4 +56,9 @@ public class ModifyApplicationProperties
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public Optional<ApplicationFlags> Flags { get; set; }
|
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>
|
/// </summary>
|
||||||
public Optional<GuildPermission> DefaultMemberPermissions { get; set; }
|
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() { }
|
internal ApplicationCommandProperties() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,7 @@ namespace Discord
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Only for globally-scoped commands.
|
/// Only for globally-scoped commands.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||||
bool IsEnabledInDm { get; }
|
bool IsEnabledInDm { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -83,6 +84,16 @@ namespace Discord
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
string DescriptionLocalized { get; }
|
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>
|
/// <summary>
|
||||||
/// Modifies the current application command.
|
/// Modifies the current application command.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets or sets whether or not this command can be used in DMs.
|
/// Gets or sets whether or not this command can be used in DMs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -56,6 +57,16 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; }
|
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 string _name;
|
||||||
private Dictionary<string, string> _nameLocalizations;
|
private Dictionary<string, string> _nameLocalizations;
|
||||||
|
|
||||||
@@ -71,10 +82,14 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
IsDefaultPermission = IsDefaultPermission,
|
IsDefaultPermission = IsDefaultPermission,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
NameLocalizations = NameLocalizations,
|
NameLocalizations = NameLocalizations,
|
||||||
IsNsfw = IsNsfw,
|
IsNsfw = IsNsfw,
|
||||||
|
IntegrationTypes = IntegrationTypes,
|
||||||
|
ContextTypes = ContextTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
@@ -133,6 +148,7 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
|
[Obsolete("This method will be deprecated soon. Configure with WithContextTypes instead.")]
|
||||||
public MessageCommandBuilder WithDMPermission(bool permission)
|
public MessageCommandBuilder WithDMPermission(bool permission)
|
||||||
{
|
{
|
||||||
IsDMEnabled = permission;
|
IsDMEnabled = permission;
|
||||||
@@ -187,5 +203,31 @@ namespace Discord
|
|||||||
DefaultMemberPermissions = permissions;
|
DefaultMemberPermissions = permissions;
|
||||||
return this;
|
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>
|
/// <summary>
|
||||||
/// Gets or sets whether or not this command can be used in DMs.
|
/// Gets or sets whether or not this command can be used in DMs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -56,6 +57,16 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; }
|
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 string _name;
|
||||||
private Dictionary<string, string> _nameLocalizations;
|
private Dictionary<string, string> _nameLocalizations;
|
||||||
|
|
||||||
@@ -69,10 +80,14 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
IsDefaultPermission = IsDefaultPermission,
|
IsDefaultPermission = IsDefaultPermission,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
NameLocalizations = NameLocalizations,
|
NameLocalizations = NameLocalizations,
|
||||||
IsNsfw = IsNsfw,
|
IsNsfw = IsNsfw,
|
||||||
|
ContextTypes = ContextTypes,
|
||||||
|
IntegrationTypes = IntegrationTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
@@ -131,6 +146,7 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
|
[Obsolete("This method will be deprecated soon. Configure with WithContextTypes instead.")]
|
||||||
public UserCommandBuilder WithDMPermission(bool permission)
|
public UserCommandBuilder WithDMPermission(bool permission)
|
||||||
{
|
{
|
||||||
IsDMEnabled = permission;
|
IsDMEnabled = permission;
|
||||||
@@ -185,5 +201,31 @@ namespace Discord
|
|||||||
DefaultMemberPermissions = permissions;
|
DefaultMemberPermissions = permissions;
|
||||||
return this;
|
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>
|
/// </summary>
|
||||||
IReadOnlyCollection<IEntitlement> Entitlements { get; }
|
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>
|
/// <summary>
|
||||||
/// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>.
|
/// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>.
|
||||||
/// </summary>
|
/// </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>
|
/// </summary>
|
||||||
public IReadOnlyDictionary<string, string> DescriptionLocalizations => _descriptionLocalizations;
|
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>
|
/// <summary>
|
||||||
/// Gets or sets whether the command is enabled by default when the app is added to a guild
|
/// Gets or sets whether the command is enabled by default when the app is added to a guild
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -83,6 +93,7 @@ namespace Discord
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether or not this command can be used in DMs.
|
/// Gets or sets whether or not this command can be used in DMs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -107,6 +118,10 @@ namespace Discord
|
|||||||
/// <returns>A <see cref="SlashCommandProperties"/> that can be used to create slash commands.</returns>
|
/// <returns>A <see cref="SlashCommandProperties"/> that can be used to create slash commands.</returns>
|
||||||
public SlashCommandProperties Build()
|
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
|
var props = new SlashCommandProperties
|
||||||
{
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
@@ -114,9 +129,13 @@ namespace Discord
|
|||||||
IsDefaultPermission = IsDefaultPermission,
|
IsDefaultPermission = IsDefaultPermission,
|
||||||
NameLocalizations = _nameLocalizations,
|
NameLocalizations = _nameLocalizations,
|
||||||
DescriptionLocalizations = _descriptionLocalizations,
|
DescriptionLocalizations = _descriptionLocalizations,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
IsNsfw = IsNsfw,
|
IsNsfw = IsNsfw,
|
||||||
|
ContextTypes = ContextTypes ?? Optional<HashSet<InteractionContextType>>.Unspecified,
|
||||||
|
IntegrationTypes = IntegrationTypes ?? Optional<HashSet<ApplicationIntegrationType>>.Unspecified
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Options != null && Options.Any())
|
if (Options != null && Options.Any())
|
||||||
@@ -171,6 +190,7 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
|
[Obsolete("This method will be deprecated soon. Configure using WithContextTypes instead.")]
|
||||||
public SlashCommandBuilder WithDMPermission(bool permission)
|
public SlashCommandBuilder WithDMPermission(bool permission)
|
||||||
{
|
{
|
||||||
IsDMEnabled = permission;
|
IsDMEnabled = permission;
|
||||||
@@ -199,6 +219,32 @@ namespace Discord
|
|||||||
return this;
|
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>
|
/// <summary>
|
||||||
/// Adds an option to the current slash command.
|
/// Adds an option to the current slash command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="IMessageInteraction"/> if the message is a response to an interaction; otherwise <see langword="null"/>.
|
/// A <see cref="IMessageInteraction"/> if the message is a response to an interaction; otherwise <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||||
IMessageInteraction Interaction { get; }
|
IMessageInteraction Interaction { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ namespace Discord
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
IUserMessage ReferencedMessage { get; }
|
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>
|
/// <summary>
|
||||||
/// Modifies this message.
|
/// Modifies this message.
|
||||||
/// </summary>
|
/// </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.
|
/// Sets the <see cref="IApplicationCommandInfo.IsEnabledInDm"/> property of an application command or module.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
[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
|
public class EnabledInDmAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.Interactions.Builders
|
namespace Discord.Interactions.Builders
|
||||||
{
|
{
|
||||||
@@ -35,7 +36,24 @@ namespace Discord.Interactions.Builders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
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>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="ContextCommandBuilder"/>.
|
/// Initializes a new <see cref="ContextCommandBuilder"/>.
|
||||||
@@ -126,6 +144,28 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
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) =>
|
internal override ContextCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||||
ContextCommandInfo.Create(this, module, commandService);
|
ContextCommandInfo.Create(this, module, commandService);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.Interactions.Builders
|
namespace Discord.Interactions.Builders
|
||||||
{
|
{
|
||||||
@@ -35,7 +36,24 @@ namespace Discord.Interactions.Builders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
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>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="SlashCommandBuilder"/>.
|
/// Initializes a new <see cref="SlashCommandBuilder"/>.
|
||||||
@@ -126,6 +144,32 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
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) =>
|
internal override SlashCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||||
new SlashCommandInfo(this, module, commandService);
|
new SlashCommandInfo(this, module, commandService);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,13 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets and sets the default permission of this module.
|
/// Gets and sets the default permission of this module.
|
||||||
/// </summary>
|
/// </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;
|
public bool DefaultPermission { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether this command can be used in DMs.
|
/// Gets whether this command can be used in DMs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||||
public bool IsEnabledInDm { get; set; } = true;
|
public bool IsEnabledInDm { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -114,6 +115,16 @@ namespace Discord.Interactions.Builders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<ModalCommandBuilder> ModalCommands => _modalCommands;
|
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 TypeInfo TypeInfo { get; set; }
|
||||||
|
|
||||||
internal ModuleBuilder(InteractionService interactionService, ModuleBuilder parent = null)
|
internal ModuleBuilder(InteractionService interactionService, ModuleBuilder parent = null)
|
||||||
@@ -189,6 +200,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
[Obsolete("This method will be deprecated soon. Use WithContextTypes instead.")]
|
||||||
public ModuleBuilder SetEnabledInDm(bool isEnabled)
|
public ModuleBuilder SetEnabledInDm(bool isEnabled)
|
||||||
{
|
{
|
||||||
IsEnabledInDm = isEnabled;
|
IsEnabledInDm = isEnabled;
|
||||||
@@ -423,6 +435,28 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
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)
|
internal ModuleInfo Build(InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
|
||||||
{
|
{
|
||||||
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -87,11 +88,13 @@ namespace Discord.Interactions.Builders
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
case EnabledInDmAttribute enabledInDm:
|
case EnabledInDmAttribute enabledInDm:
|
||||||
{
|
{
|
||||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
case DefaultMemberPermissionsAttribute memberPermission:
|
case DefaultMemberPermissionsAttribute memberPermission:
|
||||||
{
|
{
|
||||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||||
@@ -106,6 +109,12 @@ namespace Discord.Interactions.Builders
|
|||||||
case NsfwCommandAttribute nsfwCommand:
|
case NsfwCommandAttribute nsfwCommand:
|
||||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||||
break;
|
break;
|
||||||
|
case CommandContextTypeAttribute contextType:
|
||||||
|
builder.WithContextTypes(contextType.ContextTypes?.ToArray());
|
||||||
|
break;
|
||||||
|
case IntegrationTypeAttribute integrationType:
|
||||||
|
builder.WithIntegrationTypes(integrationType.IntegrationTypes?.ToArray());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
builder.AddAttributes(attribute);
|
builder.AddAttributes(attribute);
|
||||||
break;
|
break;
|
||||||
@@ -185,12 +194,12 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
case EnabledInDmAttribute enabledInDm:
|
case EnabledInDmAttribute enabledInDm:
|
||||||
{
|
{
|
||||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
case DefaultMemberPermissionsAttribute memberPermission:
|
case DefaultMemberPermissionsAttribute memberPermission:
|
||||||
{
|
{
|
||||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||||
@@ -202,6 +211,12 @@ namespace Discord.Interactions.Builders
|
|||||||
case NsfwCommandAttribute nsfwCommand:
|
case NsfwCommandAttribute nsfwCommand:
|
||||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||||
break;
|
break;
|
||||||
|
case CommandContextTypeAttribute contextType:
|
||||||
|
builder.WithContextTypes(contextType.ContextTypes.ToArray());
|
||||||
|
break;
|
||||||
|
case IntegrationTypeAttribute integrationType:
|
||||||
|
builder.WithIntegrationTypes(integrationType.IntegrationTypes.ToArray());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
builder.WithAttributes(attribute);
|
builder.WithAttributes(attribute);
|
||||||
break;
|
break;
|
||||||
@@ -242,12 +257,12 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
builder.DefaultPermission = defaultPermission.IsDefaultPermission;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
case EnabledInDmAttribute enabledInDm:
|
case EnabledInDmAttribute enabledInDm:
|
||||||
{
|
{
|
||||||
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
builder.IsEnabledInDm = enabledInDm.IsEnabled;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
case DefaultMemberPermissionsAttribute memberPermission:
|
case DefaultMemberPermissionsAttribute memberPermission:
|
||||||
{
|
{
|
||||||
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
builder.DefaultMemberPermissions = memberPermission.Permissions;
|
||||||
@@ -259,6 +274,12 @@ namespace Discord.Interactions.Builders
|
|||||||
case NsfwCommandAttribute nsfwCommand:
|
case NsfwCommandAttribute nsfwCommand:
|
||||||
builder.SetNsfw(nsfwCommand.IsNsfw);
|
builder.SetNsfw(nsfwCommand.IsNsfw);
|
||||||
break;
|
break;
|
||||||
|
case CommandContextTypeAttribute contextType:
|
||||||
|
builder.WithContextTypes(contextType.ContextTypes.ToArray());
|
||||||
|
break;
|
||||||
|
case IntegrationTypeAttribute integrationType:
|
||||||
|
builder.WithIntegrationTypes(integrationType.IntegrationTypes.ToArray());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
builder.WithAttributes(attribute);
|
builder.WithAttributes(attribute);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; }
|
public GuildPermission? DefaultMemberPermissions { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override IReadOnlyList<CommandParameterInfo> Parameters { get; }
|
public override IReadOnlyList<CommandParameterInfo> Parameters { get; }
|
||||||
|
|
||||||
@@ -46,6 +52,8 @@ namespace Discord.Interactions
|
|||||||
IsEnabledInDm = builder.IsEnabledInDm;
|
IsEnabledInDm = builder.IsEnabledInDm;
|
||||||
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
||||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
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)
|
internal static ContextCommandInfo Create(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<SlashCommandParameterInfo> FlattenedParameters { get; }
|
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)
|
internal SlashCommandInfo(Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
|
||||||
{
|
{
|
||||||
Description = builder.Description;
|
Description = builder.Description;
|
||||||
@@ -57,6 +63,8 @@ namespace Discord.Interactions
|
|||||||
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
DefaultMemberPermissions = builder.DefaultMemberPermissions;
|
||||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
||||||
FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray();
|
FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray();
|
||||||
|
ContextTypes = builder.ContextTypes?.ToImmutableArray();
|
||||||
|
IntegrationTypes = builder.IntegrationTypes?.ToImmutableArray();
|
||||||
|
|
||||||
for (var i = 0; i < FlattenedParameters.Count - 1; i++)
|
for (var i = 0; i < FlattenedParameters.Count - 1; i++)
|
||||||
if (!FlattenedParameters.ElementAt(i).IsRequired && FlattenedParameters.ElementAt(i + 1).IsRequired)
|
if (!FlattenedParameters.ElementAt(i).IsRequired && FlattenedParameters.ElementAt(i + 1).IsRequired)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.Interactions
|
namespace Discord.Interactions
|
||||||
{
|
{
|
||||||
@@ -37,5 +38,15 @@ namespace Discord.Interactions
|
|||||||
/// Gets the default permissions needed for executing this command.
|
/// Gets the default permissions needed for executing this command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; }
|
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>
|
/// </summary>
|
||||||
public bool DontAutoRegister { get; }
|
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)
|
internal ModuleInfo(ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null)
|
||||||
{
|
{
|
||||||
CommandService = commandService;
|
CommandService = commandService;
|
||||||
@@ -129,7 +139,9 @@ namespace Discord.Interactions
|
|||||||
DefaultPermission = builder.DefaultPermission;
|
DefaultPermission = builder.DefaultPermission;
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
IsNsfw = builder.IsNsfw;
|
IsNsfw = builder.IsNsfw;
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsEnabledInDm = builder.IsEnabledInDm;
|
IsEnabledInDm = builder.IsEnabledInDm;
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
DefaultMemberPermissions = BuildDefaultMemberPermissions(builder);
|
DefaultMemberPermissions = BuildDefaultMemberPermissions(builder);
|
||||||
SlashCommands = BuildSlashCommands(builder).ToImmutableArray();
|
SlashCommands = BuildSlashCommands(builder).ToImmutableArray();
|
||||||
ContextCommands = BuildContextCommands(builder).ToImmutableArray();
|
ContextCommands = BuildContextCommands(builder).ToImmutableArray();
|
||||||
@@ -141,6 +153,8 @@ namespace Discord.Interactions
|
|||||||
Preconditions = BuildPreconditions(builder).ToImmutableArray();
|
Preconditions = BuildPreconditions(builder).ToImmutableArray();
|
||||||
IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent);
|
IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent);
|
||||||
DontAutoRegister = builder.DontAutoRegister;
|
DontAutoRegister = builder.DontAutoRegister;
|
||||||
|
ContextTypes = builder.ContextTypes?.ToImmutableArray();
|
||||||
|
IntegrationTypes = builder.IntegrationTypes?.ToImmutableArray();
|
||||||
|
|
||||||
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
|
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,17 @@ namespace Discord.Interactions
|
|||||||
Name = commandInfo.Name,
|
Name = commandInfo.Name,
|
||||||
Description = commandInfo.Description,
|
Description = commandInfo.Description,
|
||||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = commandInfo.IsEnabledInDm,
|
IsDMEnabled = commandInfo.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
IsNsfw = commandInfo.IsNsfw,
|
IsNsfw = commandInfo.IsNsfw,
|
||||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
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)
|
}.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
.WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
.WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
.Build();
|
.Build();
|
||||||
@@ -82,7 +90,7 @@ namespace Discord.Interactions
|
|||||||
Options = commandInfo.FlattenedParameters?.Select(x => x.ToApplicationCommandOptionProps())
|
Options = commandInfo.FlattenedParameters?.Select(x => x.ToApplicationCommandOptionProps())
|
||||||
?.ToList(),
|
?.ToList(),
|
||||||
NameLocalizations = localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty,
|
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,
|
Name = commandInfo.Name,
|
||||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = commandInfo.IsEnabledInDm,
|
IsDMEnabled = commandInfo.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
IsNsfw = commandInfo.IsNsfw,
|
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)
|
.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
.Build(),
|
.Build(),
|
||||||
@@ -109,7 +125,15 @@ namespace Discord.Interactions
|
|||||||
IsDefaultPermission = commandInfo.DefaultPermission,
|
IsDefaultPermission = commandInfo.DefaultPermission,
|
||||||
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
|
||||||
IsNsfw = commandInfo.IsNsfw,
|
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)
|
.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
.Build(),
|
.Build(),
|
||||||
@@ -165,10 +189,16 @@ namespace Discord.Interactions
|
|||||||
Description = moduleInfo.Description,
|
Description = moduleInfo.Description,
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDefaultPermission = moduleInfo.DefaultPermission,
|
IsDefaultPermission = moduleInfo.DefaultPermission,
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
IsDMEnabled = moduleInfo.IsEnabledInDm,
|
IsDMEnabled = moduleInfo.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
IsNsfw = moduleInfo.IsNsfw,
|
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)
|
.WithNameLocalizations(localizationManager?.GetAllNames(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
.WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(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,
|
Description = command.Description,
|
||||||
IsDefaultPermission = command.IsDefaultPermission,
|
IsDefaultPermission = command.IsDefaultPermission,
|
||||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = command.IsEnabledInDm,
|
IsDMEnabled = command.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
IsNsfw = command.IsNsfw,
|
IsNsfw = command.IsNsfw,
|
||||||
Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional<List<ApplicationCommandOptionProperties>>.Unspecified,
|
Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional<List<ApplicationCommandOptionProperties>>.Unspecified,
|
||||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
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.User => new UserCommandProperties
|
ApplicationCommandType.User => new UserCommandProperties
|
||||||
{
|
{
|
||||||
@@ -242,9 +280,17 @@ namespace Discord.Interactions
|
|||||||
IsDefaultPermission = command.IsDefaultPermission,
|
IsDefaultPermission = command.IsDefaultPermission,
|
||||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||||
IsNsfw = command.IsNsfw,
|
IsNsfw = command.IsNsfw,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = command.IsEnabledInDm,
|
IsDMEnabled = command.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
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
|
ApplicationCommandType.Message => new MessageCommandProperties
|
||||||
{
|
{
|
||||||
@@ -252,9 +298,17 @@ namespace Discord.Interactions
|
|||||||
IsDefaultPermission = command.IsDefaultPermission,
|
IsDefaultPermission = command.IsDefaultPermission,
|
||||||
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
DefaultMemberPermissions = command.DefaultMemberPermissions.RawValue == 0 ? new Optional<GuildPermission>() : (GuildPermission)command.DefaultMemberPermissions.RawValue,
|
||||||
IsNsfw = command.IsNsfw,
|
IsNsfw = command.IsNsfw,
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsDMEnabled = command.IsEnabledInDm,
|
IsDMEnabled = command.IsEnabledInDm,
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty,
|
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}"),
|
_ => throw new InvalidOperationException($"Cannot create command properties for command type {command.Type}"),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.API;
|
namespace Discord.API;
|
||||||
|
|
||||||
@@ -94,4 +95,10 @@ internal class Application
|
|||||||
|
|
||||||
[JsonProperty("verification_state")]
|
[JsonProperty("verification_state")]
|
||||||
public Optional<ApplicationVerificationState> VerificationState { get; set; }
|
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")]
|
[JsonProperty("nsfw")]
|
||||||
public Optional<bool?> Nsfw { get; set; }
|
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; }
|
public string[] Scopes { get; set; }
|
||||||
|
|
||||||
[JsonProperty("permissions")]
|
[JsonProperty("permissions")]
|
||||||
public ulong Permission { get; set; }
|
public GuildPermission Permission { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,63 @@
|
|||||||
using Newtonsoft.Json;
|
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))]
|
[JsonProperty("id")]
|
||||||
internal class Interaction
|
public ulong Id { get; set; }
|
||||||
{
|
|
||||||
[JsonProperty("id")]
|
|
||||||
public ulong Id { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("application_id")]
|
[JsonProperty("application_id")]
|
||||||
public ulong ApplicationId { get; set; }
|
public ulong ApplicationId { get; set; }
|
||||||
|
|
||||||
[JsonProperty("type")]
|
[JsonProperty("type")]
|
||||||
public InteractionType Type { get; set; }
|
public InteractionType Type { get; set; }
|
||||||
|
|
||||||
[JsonProperty("data")]
|
[JsonProperty("data")]
|
||||||
public Optional<IDiscordInteractionData> Data { get; set; }
|
public Optional<IDiscordInteractionData> Data { get; set; }
|
||||||
|
|
||||||
[JsonProperty("guild_id")]
|
[JsonProperty("guild_id")]
|
||||||
public Optional<ulong> GuildId { get; set; }
|
public Optional<ulong> GuildId { get; set; }
|
||||||
|
|
||||||
[JsonProperty("channel_id")]
|
[JsonProperty("channel")]
|
||||||
public Optional<ulong> ChannelId { get; set; }
|
public Optional<Channel> Channel { get; set; }
|
||||||
|
|
||||||
[JsonProperty("channel")]
|
[JsonProperty("channel_id")]
|
||||||
public Optional<Channel> Channel { get; set; }
|
public Optional<ulong> ChannelId { get; set; }
|
||||||
|
|
||||||
[JsonProperty("member")]
|
[JsonProperty("member")]
|
||||||
public Optional<GuildMember> Member { get; set; }
|
public Optional<GuildMember> Member { get; set; }
|
||||||
|
|
||||||
[JsonProperty("user")]
|
[JsonProperty("user")]
|
||||||
public Optional<User> User { get; set; }
|
public Optional<User> User { get; set; }
|
||||||
|
|
||||||
[JsonProperty("token")]
|
[JsonProperty("token")]
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
|
|
||||||
[JsonProperty("version")]
|
[JsonProperty("version")]
|
||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
|
|
||||||
[JsonProperty("message")]
|
[JsonProperty("message")]
|
||||||
public Optional<Message> Message { get; set; }
|
public Optional<Message> Message { get; set; }
|
||||||
|
|
||||||
[JsonProperty("locale")]
|
[JsonProperty("locale")]
|
||||||
public Optional<string> UserLocale { get; set; }
|
public Optional<string> UserLocale { get; set; }
|
||||||
|
|
||||||
[JsonProperty("guild_locale")]
|
[JsonProperty("guild_locale")]
|
||||||
public Optional<string> GuildLocale { get; set; }
|
public Optional<string> GuildLocale { get; set; }
|
||||||
|
|
||||||
[JsonProperty("entitlements")]
|
[JsonProperty("entitlements")]
|
||||||
public Entitlement[] Entitlements { get; set; }
|
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,74 +1,104 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Discord.API
|
namespace Discord.API;
|
||||||
|
|
||||||
|
internal class Message
|
||||||
{
|
{
|
||||||
internal class Message
|
[JsonProperty("id")]
|
||||||
{
|
public ulong Id { get; set; }
|
||||||
[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<MessageInteraction> Interaction { get; set; }
|
|
||||||
[JsonProperty("sticker_items")]
|
|
||||||
public Optional<StickerItem[]> StickerItems { get; set; }
|
|
||||||
[JsonProperty("role_subscription_data")]
|
|
||||||
public Optional<MessageRoleSubscriptionData> RoleSubscriptionData { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("thread")]
|
[JsonProperty("type")]
|
||||||
public Optional<Channel> Thread { get; set; }
|
public MessageType Type { get; set; }
|
||||||
|
|
||||||
[JsonProperty("resolved")]
|
[JsonProperty("channel_id")]
|
||||||
public Optional<MessageComponentInteractionDataResolved> Resolved { get; set; }
|
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<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; }
|
||||||
|
|
||||||
|
[JsonProperty("thread")]
|
||||||
|
public Optional<Channel> Thread { get; set; }
|
||||||
|
|
||||||
|
[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")]
|
[JsonProperty("nsfw")]
|
||||||
public Optional<bool> Nsfw { get; set; }
|
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() { }
|
||||||
|
|
||||||
public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null,
|
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;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
@@ -49,6 +57,8 @@ namespace Discord.API.Rest
|
|||||||
NameLocalizations = nameLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
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;
|
DescriptionLocalizations = descriptionLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
||||||
Nsfw = nsfw;
|
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")]
|
[JsonProperty("description_localizations")]
|
||||||
public Optional<Dictionary<string, string>> DescriptionLocalizations { get; set; }
|
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 Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.API.Rest;
|
namespace Discord.API.Rest;
|
||||||
|
|
||||||
@@ -30,4 +31,7 @@ internal class ModifyCurrentApplicationBotParams
|
|||||||
|
|
||||||
[JsonProperty("tags")]
|
[JsonProperty("tags")]
|
||||||
public Optional<string[]> Tags { get; set; }
|
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
|
? null
|
||||||
: new InstallParams
|
: new InstallParams
|
||||||
{
|
{
|
||||||
Permission = (ulong)args.InstallParams.Value.Permission,
|
Permission = args.InstallParams.Value.Permission,
|
||||||
Scopes = args.InstallParams.Value.Scopes.ToArray()
|
Scopes = args.InstallParams.Value.Scopes.ToArray()
|
||||||
}
|
}
|
||||||
: Optional<InstallParams>.Unspecified,
|
: 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);
|
}, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ namespace Discord.Rest
|
|||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.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)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -146,7 +148,9 @@ namespace Discord.Rest
|
|||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.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)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -190,7 +194,9 @@ namespace Discord.Rest
|
|||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.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)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -254,7 +260,9 @@ namespace Discord.Rest
|
|||||||
NameLocalizations = args.NameLocalizations?.ToDictionary(),
|
NameLocalizations = args.NameLocalizations?.ToDictionary(),
|
||||||
DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary(),
|
DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary(),
|
||||||
Nsfw = args.IsNsfw.GetValueOrDefault(false),
|
Nsfw = args.IsNsfw.GetValueOrDefault(false),
|
||||||
DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable()
|
DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable(),
|
||||||
|
IntegrationTypes = args.IntegrationTypes,
|
||||||
|
ContextTypes = args.ContextTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
if (args is SlashCommandProperties slashProps)
|
if (args is SlashCommandProperties slashProps)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace Discord.Rest
|
|||||||
public bool IsDefaultPermission { get; private set; }
|
public bool IsDefaultPermission { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||||
public bool IsEnabledInDm { get; private set; }
|
public bool IsEnabledInDm { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -67,6 +68,12 @@ namespace Discord.Rest
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public string DescriptionLocalized { get; private set; }
|
public string DescriptionLocalized { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DateTimeOffset CreatedAt
|
public DateTimeOffset CreatedAt
|
||||||
=> SnowflakeUtils.FromSnowflake(Id);
|
=> SnowflakeUtils.FromSnowflake(Id);
|
||||||
@@ -102,9 +109,14 @@ namespace Discord.Rest
|
|||||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||||
|
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
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));
|
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||||
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||||
|
|
||||||
|
IntegrationTypes = model.IntegrationTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||||
|
ContextTypes = model.ContextTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -90,9 +90,18 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ulong ApplicationId { get; private set; }
|
public ulong ApplicationId { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public InteractionContextType? ContextType { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public GuildPermissions Permissions { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
||||||
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; private set; }
|
||||||
|
|
||||||
internal RestInteraction(BaseDiscordClient discord, ulong id)
|
internal RestInteraction(BaseDiscordClient discord, ulong id)
|
||||||
: base(discord, id)
|
: base(discord, id)
|
||||||
{
|
{
|
||||||
@@ -232,6 +241,13 @@ namespace Discord.Rest
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
Entitlements = model.Entitlements.Select(x => RestEntitlement.Create(discord, x)).ToImmutableArray();
|
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)
|
internal string SerializePayload(object payload)
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ namespace Discord.Rest
|
|||||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||||
IMessageInteraction IMessage.Interaction => Interaction;
|
IMessageInteraction IMessage.Interaction => Interaction;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IUserMessage ReferencedMessage => _referencedMessage;
|
public IUserMessage ReferencedMessage => _referencedMessage;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IMessageInteractionMetadata InteractionMetadata { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MessageResolvedData ResolvedData { get; internal set; }
|
public MessageResolvedData ResolvedData { get; internal set; }
|
||||||
|
|
||||||
@@ -162,6 +165,8 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
||||||
}
|
}
|
||||||
|
if (model.InteractionMetadata.IsSpecified)
|
||||||
|
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -6,183 +6,195 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
using Model = Discord.API.Application;
|
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>
|
protected string _iconId;
|
||||||
/// Represents a REST-based entity that contains information about a Discord application created via the developer portal.
|
|
||||||
/// </summary>
|
/// <inheritdoc />
|
||||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
public string Name { get; private set; }
|
||||||
public class RestApplication : RestEntity<ulong>, IApplication
|
/// <inheritdoc />
|
||||||
|
public string Description { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<string> RPCOrigins { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationFlags Flags { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool? IsBotPublic { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool? BotRequiresCodeGrant { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ITeam Team { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IUser Owner { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string TermsOfService { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string PrivacyPolicy { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string VerifyKey { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string CustomInstallUrl { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string RoleConnectionsVerificationUrl { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string IconUrl => CDN.GetApplicationIconUrl(Id, _iconId);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public PartialGuild Guild { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int? ApproximateGuildCount { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<string> RedirectUris { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string InteractionsEndpointUrl { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationInstallParams InstallParams { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationDiscoverabilityState DiscoverabilityState { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public DiscoveryEligibilityFlags DiscoveryEligibilityFlags { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationExplicitContentFilterLevel ExplicitContentFilterLevel { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsHook { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<string> InteractionEventTypes { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationInteractionsVersion InteractionsVersion { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsMonetized { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationMonetizationEligibilityFlags MonetizationEligibilityFlags { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationMonetizationState MonetizationState { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationRpcState RpcState { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationStoreState StoreState { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ApplicationVerificationState VerificationState { get; private set; }
|
||||||
|
|
||||||
|
/// <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)
|
||||||
{
|
{
|
||||||
protected string _iconId;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string Name { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string Description { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IReadOnlyCollection<string> RPCOrigins { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationFlags Flags { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool? IsBotPublic { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool? BotRequiresCodeGrant { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ITeam Team { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IUser Owner { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string TermsOfService { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string PrivacyPolicy { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string VerifyKey { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string CustomInstallUrl { get; private set; }
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string RoleConnectionsVerificationUrl { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string IconUrl => CDN.GetApplicationIconUrl(Id, _iconId);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public PartialGuild Guild { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public int? ApproximateGuildCount { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IReadOnlyCollection<string> RedirectUris { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string InteractionsEndpointUrl { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationInstallParams InstallParams { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationDiscoverabilityState DiscoverabilityState { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public DiscoveryEligibilityFlags DiscoveryEligibilityFlags { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationExplicitContentFilterLevel ExplicitContentFilterLevel { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool IsHook { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IReadOnlyCollection<string> InteractionEventTypes { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationInteractionsVersion InteractionsVersion { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool IsMonetized { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationMonetizationEligibilityFlags MonetizationEligibilityFlags { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationMonetizationState MonetizationState { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationRpcState RpcState { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationStoreState StoreState { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ApplicationVerificationState VerificationState { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IReadOnlyCollection<string> Tags { get; private set; }
|
|
||||||
|
|
||||||
internal RestApplication(BaseDiscordClient discord, ulong id)
|
|
||||||
: base(discord, id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal static RestApplication Create(BaseDiscordClient discord, Model model)
|
|
||||||
{
|
|
||||||
var entity = new RestApplication(discord, model.Id);
|
|
||||||
entity.Update(model);
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
internal void Update(Model model)
|
|
||||||
{
|
|
||||||
Description = model.Description;
|
|
||||||
RPCOrigins = model.RPCOrigins.IsSpecified ? model.RPCOrigins.Value.ToImmutableArray() : ImmutableArray<string>.Empty;
|
|
||||||
Name = model.Name;
|
|
||||||
_iconId = model.Icon;
|
|
||||||
IsBotPublic = model.IsBotPublic.IsSpecified ? model.IsBotPublic.Value : null;
|
|
||||||
BotRequiresCodeGrant = model.BotRequiresCodeGrant.IsSpecified ? model.BotRequiresCodeGrant.Value : null;
|
|
||||||
Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray<string>.Empty;
|
|
||||||
PrivacyPolicy = model.PrivacyPolicy;
|
|
||||||
TermsOfService = model.TermsOfService;
|
|
||||||
|
|
||||||
InstallParams = model.InstallParams.IsSpecified
|
|
||||||
? new ApplicationInstallParams(model.InstallParams.Value.Scopes, (GuildPermission)model.InstallParams.Value.Permission)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (model.Flags.IsSpecified)
|
|
||||||
Flags = model.Flags.Value;
|
|
||||||
if (model.Owner.IsSpecified)
|
|
||||||
Owner = RestUser.Create(Discord, model.Owner.Value);
|
|
||||||
if (model.Team != null)
|
|
||||||
Team = RestTeam.Create(Discord, model.Team);
|
|
||||||
|
|
||||||
CustomInstallUrl = model.CustomInstallUrl.IsSpecified ? model.CustomInstallUrl.Value : null;
|
|
||||||
RoleConnectionsVerificationUrl = model.RoleConnectionsUrl.IsSpecified ? model.RoleConnectionsUrl.Value : null;
|
|
||||||
VerifyKey = model.VerifyKey;
|
|
||||||
|
|
||||||
if (model.PartialGuild.IsSpecified)
|
|
||||||
Guild = PartialGuildExtensions.Create(model.PartialGuild.Value);
|
|
||||||
|
|
||||||
InteractionsEndpointUrl = model.InteractionsEndpointUrl.IsSpecified ? model.InteractionsEndpointUrl.Value : null;
|
|
||||||
|
|
||||||
if (model.RedirectUris.IsSpecified)
|
|
||||||
RedirectUris = model.RedirectUris.Value.ToImmutableArray();
|
|
||||||
|
|
||||||
ApproximateGuildCount = model.ApproximateGuildCount.IsSpecified ? model.ApproximateGuildCount.Value : null;
|
|
||||||
|
|
||||||
DiscoverabilityState = model.DiscoverabilityState.GetValueOrDefault(ApplicationDiscoverabilityState.None);
|
|
||||||
DiscoveryEligibilityFlags = model.DiscoveryEligibilityFlags.GetValueOrDefault(DiscoveryEligibilityFlags.None);
|
|
||||||
ExplicitContentFilterLevel = model.ExplicitContentFilter.GetValueOrDefault(ApplicationExplicitContentFilterLevel.Disabled);
|
|
||||||
IsHook = model.IsHook;
|
|
||||||
|
|
||||||
InteractionEventTypes = model.InteractionsEventTypes.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
|
|
||||||
InteractionsVersion = model.InteractionsVersion.GetValueOrDefault(ApplicationInteractionsVersion.Version1);
|
|
||||||
|
|
||||||
IsMonetized = model.IsMonetized;
|
|
||||||
MonetizationEligibilityFlags = model.MonetizationEligibilityFlags.GetValueOrDefault(ApplicationMonetizationEligibilityFlags.None);
|
|
||||||
MonetizationState = model.MonetizationState.GetValueOrDefault(ApplicationMonetizationState.None);
|
|
||||||
|
|
||||||
RpcState = model.RpcState.GetValueOrDefault(ApplicationRpcState.Disabled);
|
|
||||||
StoreState = model.StoreState.GetValueOrDefault(ApplicationStoreState.None);
|
|
||||||
VerificationState = model.VerificationState.GetValueOrDefault(ApplicationVerificationState.Ineligible);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <exception cref="InvalidOperationException">Unable to update this object from a different application token.</exception>
|
|
||||||
public async Task UpdateAsync()
|
|
||||||
{
|
|
||||||
var response = await Discord.ApiClient.GetMyApplicationAsync().ConfigureAwait(false);
|
|
||||||
if (response.Id != Id)
|
|
||||||
throw new InvalidOperationException("Unable to update this object from a different application token.");
|
|
||||||
Update(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name of the application.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// Name of the application.
|
|
||||||
/// </returns>
|
|
||||||
public override string ToString() => Name;
|
|
||||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
|
||||||
}
|
}
|
||||||
|
internal static RestApplication Create(BaseDiscordClient discord, Model model)
|
||||||
|
{
|
||||||
|
var entity = new RestApplication(discord, model.Id);
|
||||||
|
entity.Update(model);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
internal void Update(Model model)
|
||||||
|
{
|
||||||
|
Description = model.Description;
|
||||||
|
RPCOrigins = model.RPCOrigins.IsSpecified ? model.RPCOrigins.Value.ToImmutableArray() : ImmutableArray<string>.Empty;
|
||||||
|
Name = model.Name;
|
||||||
|
_iconId = model.Icon;
|
||||||
|
IsBotPublic = model.IsBotPublic.IsSpecified ? model.IsBotPublic.Value : null;
|
||||||
|
BotRequiresCodeGrant = model.BotRequiresCodeGrant.IsSpecified ? model.BotRequiresCodeGrant.Value : null;
|
||||||
|
Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray<string>.Empty;
|
||||||
|
PrivacyPolicy = model.PrivacyPolicy;
|
||||||
|
TermsOfService = model.TermsOfService;
|
||||||
|
|
||||||
|
InstallParams = model.InstallParams.IsSpecified
|
||||||
|
? new ApplicationInstallParams(model.InstallParams.Value.Scopes, (GuildPermission)model.InstallParams.Value.Permission)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (model.Flags.IsSpecified)
|
||||||
|
Flags = model.Flags.Value;
|
||||||
|
if (model.Owner.IsSpecified)
|
||||||
|
Owner = RestUser.Create(Discord, model.Owner.Value);
|
||||||
|
if (model.Team != null)
|
||||||
|
Team = RestTeam.Create(Discord, model.Team);
|
||||||
|
|
||||||
|
CustomInstallUrl = model.CustomInstallUrl.IsSpecified ? model.CustomInstallUrl.Value : null;
|
||||||
|
RoleConnectionsVerificationUrl = model.RoleConnectionsUrl.IsSpecified ? model.RoleConnectionsUrl.Value : null;
|
||||||
|
VerifyKey = model.VerifyKey;
|
||||||
|
|
||||||
|
if (model.PartialGuild.IsSpecified)
|
||||||
|
Guild = PartialGuildExtensions.Create(model.PartialGuild.Value);
|
||||||
|
|
||||||
|
InteractionsEndpointUrl = model.InteractionsEndpointUrl.IsSpecified ? model.InteractionsEndpointUrl.Value : null;
|
||||||
|
|
||||||
|
if (model.RedirectUris.IsSpecified)
|
||||||
|
RedirectUris = model.RedirectUris.Value.ToImmutableArray();
|
||||||
|
|
||||||
|
ApproximateGuildCount = model.ApproximateGuildCount.IsSpecified ? model.ApproximateGuildCount.Value : null;
|
||||||
|
|
||||||
|
DiscoverabilityState = model.DiscoverabilityState.GetValueOrDefault(ApplicationDiscoverabilityState.None);
|
||||||
|
DiscoveryEligibilityFlags = model.DiscoveryEligibilityFlags.GetValueOrDefault(DiscoveryEligibilityFlags.None);
|
||||||
|
ExplicitContentFilterLevel = model.ExplicitContentFilter.GetValueOrDefault(ApplicationExplicitContentFilterLevel.Disabled);
|
||||||
|
IsHook = model.IsHook;
|
||||||
|
|
||||||
|
InteractionEventTypes = model.InteractionsEventTypes.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
|
||||||
|
InteractionsVersion = model.InteractionsVersion.GetValueOrDefault(ApplicationInteractionsVersion.Version1);
|
||||||
|
|
||||||
|
IsMonetized = model.IsMonetized;
|
||||||
|
MonetizationEligibilityFlags = model.MonetizationEligibilityFlags.GetValueOrDefault(ApplicationMonetizationEligibilityFlags.None);
|
||||||
|
MonetizationState = model.MonetizationState.GetValueOrDefault(ApplicationMonetizationState.None);
|
||||||
|
|
||||||
|
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>
|
||||||
|
public async Task UpdateAsync()
|
||||||
|
{
|
||||||
|
var response = await Discord.ApiClient.GetMyApplicationAsync().ConfigureAwait(false);
|
||||||
|
if (response.Id != Id)
|
||||||
|
throw new InvalidOperationException("Unable to update this object from a different application token.");
|
||||||
|
Update(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the application.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// 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; }
|
public bool IsDefaultPermission { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use ContextTypes instead.")]
|
||||||
public bool IsEnabledInDm { get; private set; }
|
public bool IsEnabledInDm { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -79,6 +80,12 @@ namespace Discord.WebSocket
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public string DescriptionLocalized { get; private set; }
|
public string DescriptionLocalized { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<ApplicationIntegrationType> IntegrationTypes { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyCollection<InteractionContextType> ContextTypes { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DateTimeOffset CreatedAt
|
public DateTimeOffset CreatedAt
|
||||||
=> SnowflakeUtils.FromSnowflake(Id);
|
=> SnowflakeUtils.FromSnowflake(Id);
|
||||||
@@ -131,9 +138,14 @@ namespace Discord.WebSocket
|
|||||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||||
|
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
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));
|
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||||
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||||
|
|
||||||
|
IntegrationTypes = model.IntegrationTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||||
|
ContextTypes = model.ContextTypes.GetValueOrDefault(null)?.ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -73,9 +73,18 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ulong ApplicationId { get; private set; }
|
public ulong ApplicationId { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public InteractionContextType? ContextType { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public GuildPermissions Permissions { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
||||||
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
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)
|
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
|
||||||
: base(client, id)
|
: base(client, id)
|
||||||
{
|
{
|
||||||
@@ -149,6 +158,13 @@ namespace Discord.WebSocket
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
Entitlements = model.Entitlements.Select(x => RestEntitlement.Create(Discord, x)).ToImmutableArray();
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ namespace Discord.WebSocket
|
|||||||
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
IReadOnlyCollection<IMessageComponent> IMessage.Components => Components;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
[Obsolete("This property will be deprecated soon. Use IUserMessage.InteractionMetadata instead.")]
|
||||||
IMessageInteraction IMessage.Interaction => Interaction;
|
IMessageInteraction IMessage.Interaction => Interaction;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IUserMessage ReferencedMessage => _referencedMessage;
|
public IUserMessage ReferencedMessage => _referencedMessage;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IMessageInteractionMetadata InteractionMetadata { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MessageResolvedData ResolvedData { get; internal set; }
|
public MessageResolvedData ResolvedData { get; internal set; }
|
||||||
|
|
||||||
@@ -203,6 +206,9 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
ResolvedData = new MessageResolvedData(users, members, roles, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.InteractionMetadata.IsSpecified)
|
||||||
|
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user