From 90550541a68b23646231938287526f09198fa38b Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Thu, 18 Nov 2021 19:31:10 +0300 Subject: [PATCH 01/12] added interaction specific interfaces --- .../IMessageCommandInteraction.cs | 13 ++++++ .../IMessageCommandInteractionData.cs | 13 ++++++ .../ContextMenus/IUserCommandInteraction.cs | 13 ++++++ .../IUserCommandInteractionData.cs | 13 ++++++ .../IComponentInteraction.cs | 18 +++++++++ .../IComponentInteractionData.cs | 25 ++++++++++++ .../SlashCommands/IAutocompleteInteraction.cs | 13 ++++++ .../IAutocompleteInteractionData.cs | 40 +++++++++++++++++++ .../SlashCommands/ISlashCommandInteraction.cs | 13 ++++++ .../MessageCommands/RestMessageCommand.cs | 6 ++- .../MessageCommands/RestMessageCommandData.cs | 6 ++- .../UserCommands/RestUserCommand.cs | 6 ++- .../UserCommands/RestUserCommandData.cs | 6 ++- .../MessageComponents/RestMessageComponent.cs | 9 ++++- .../RestMessageComponentData.cs | 2 +- .../RestAutocompleteInteraction.cs | 7 ++-- .../RestAutocompleteInteractionData.cs | 2 +- .../SlashCommands/RestSlashCommand.cs | 6 ++- .../MessageCommands/SocketMessageCommand.cs | 6 ++- .../SocketMessageCommandData.cs | 6 ++- .../UserCommands/SocketUserCommand.cs | 6 ++- .../UserCommands/SocketUserCommandData.cs | 6 ++- .../SocketMessageComponent.cs | 9 ++++- .../SocketMessageComponentData.cs | 2 +- .../SocketAutocompleteInteraction.cs | 6 ++- .../SocketAutocompleteInteractionData.cs | 2 +- .../SlashCommands/SocketSlashCommand.cs | 6 ++- 27 files changed, 231 insertions(+), 29 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs create mode 100644 src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs new file mode 100644 index 000000000..2f73fcbe0 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a Message Command interaction received over the gateway. + /// + public interface IMessageCommandInteraction : IDiscordInteraction + { + /// + /// Gets the data associated with this interaction. + /// + new IMessageCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs new file mode 100644 index 000000000..311eef2d6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents the data tied with the interaction. + /// + public interface IMessageCommandInteractionData : IApplicationCommandInteractionData + { + /// + /// Gets the message associated with this message command. + /// + IMessage Message { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs new file mode 100644 index 000000000..9dd8e7aa4 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a User Command interaction received over the gateway. + /// + public interface IUserCommandInteraction : IDiscordInteraction + { + /// + /// Gets the data associated with this interaction. + /// + new IUserCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs new file mode 100644 index 000000000..36e482ec9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents the data tied with the interaction. + /// + public interface IUserCommandInteractionData : IApplicationCommandInteractionData + { + /// + /// Gets the user who this command targets. + /// + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs new file mode 100644 index 000000000..2a46e8f18 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Represents an interaction type for Message Components. + /// + public interface IComponentInteraction : IDiscordInteraction + { + /// + /// Gets the data received with this interaction, contains the button that was clicked. + /// + new IComponentInteractionData Data { get; } + + /// + /// Gets the message that contained the trigger for this interaction. + /// + IUserMessage Message { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs new file mode 100644 index 000000000..99b9b6f6c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents the data sent with the . + /// + public interface IComponentInteractionData : IDiscordInteractionData + { + /// + /// Gets the components Custom Id that was clicked. + /// + string CustomId { get; } + + /// + /// Gets the type of the component clicked. + /// + ComponentType Type { get; } + + /// + /// Gets the value(s) of a interaction response. + /// + IReadOnlyCollection Values { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs new file mode 100644 index 000000000..08f4a5f2e --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a received over the gateway. + /// + public interface IAutocompleteInteraction : IDiscordInteraction + { + /// + /// The autocomplete data of this interaction. + /// + new IAutocompleteInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs new file mode 100644 index 000000000..e6d1e9fae --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents data for a slash commands autocomplete interaction. + /// + public interface IAutocompleteInteractionData : IDiscordInteractionData + { + /// + /// Gets the name of the invoked command. + /// + string CommandName { get; } + + /// + /// Gets the id of the invoked command. + /// + ulong CommandId { get; } + + /// + /// Gets the type of the invoked command. + /// + ApplicationCommandType Type { get; } + + /// + /// Gets the version of the invoked command. + /// + ulong Version { get; } + + /// + /// Gets the current autocomplete option that is actively being filled out. + /// + AutocompleteOption Current { get; } + + /// + /// Gets a collection of all the other options the executing users has filled out. + /// + IReadOnlyCollection Options { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs new file mode 100644 index 000000000..e616aac7f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a slash command interaction received over the gateway. + /// + public interface ISlashCommandInteraction : IDiscordInteraction + { + /// + /// The data associated with this interaction. + /// + new IApplicationCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs index e19dabf53..c587ac881 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs @@ -7,7 +7,7 @@ namespace Discord.Rest /// /// Represents a REST-based message command interaction. /// - public class RestMessageCommand : RestCommandBase, IDiscordInteraction + public class RestMessageCommand : RestCommandBase, IMessageCommandInteraction, IDiscordInteraction { /// /// The data associated with this interaction. @@ -38,6 +38,8 @@ internal override async Task UpdateAsync(DiscordRestClient client, Model model) Data = await RestMessageCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false); } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IMessageCommandInteraction + /// + IMessageCommandInteractionData IMessageCommandInteraction.Data => Data; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs index 3ced005f6..ee528bc65 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs @@ -10,7 +10,7 @@ namespace Discord.Rest /// /// Represents the data for a . /// - public class RestMessageCommandData : RestCommandBaseData, IDiscordInteractionData + public class RestMessageCommandData : RestCommandBaseData, IMessageCommandInteractionData, IDiscordInteractionData { /// /// Gets the message associated with this message command. @@ -34,5 +34,9 @@ internal RestMessageCommandData(DiscordRestClient client, Model model) await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); return entity; } + + //IMessageCommandInteractionData + /// + IMessage IMessageCommandInteractionData.Message => Message; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs index d3ff22b21..52466debf 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs @@ -11,7 +11,7 @@ namespace Discord.Rest /// /// Represents a REST-based user command. /// - internal class RestUserCommand : RestCommandBase, IDiscordInteraction + internal class RestUserCommand : RestCommandBase, IUserCommandInteraction, IDiscordInteraction { /// /// Gets the data associated with this interaction. @@ -41,6 +41,8 @@ internal override async Task UpdateAsync(DiscordRestClient client, Model model) Data = await RestUserCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false); } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IUserCommandInteractionData + /// + IUserCommandInteractionData IUserCommandInteraction.Data => Data; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs index dc9301dfc..5ceec6bca 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs @@ -8,7 +8,7 @@ namespace Discord.Rest /// /// Represents the data for a . /// - public class RestUserCommandData : RestCommandBaseData, IDiscordInteractionData + public class RestUserCommandData : RestCommandBaseData, IUserCommandInteractionData, IDiscordInteractionData { /// /// Gets the user who this command targets. @@ -32,5 +32,9 @@ internal RestUserCommandData(DiscordRestClient client, Model model) await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); return entity; } + + //IUserCommandInteractionData + /// + IUser IUserCommandInteractionData.User => Member; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs index 513f67201..da843468b 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs @@ -13,7 +13,7 @@ namespace Discord.Rest /// /// Represents a REST-based message component. /// - internal class RestMessageComponent : RestInteraction, IDiscordInteraction + internal class RestMessageComponent : RestInteraction, IComponentInteraction, IDiscordInteraction { /// /// Gets the data received with this interaction, contains the button that was clicked. @@ -442,6 +442,11 @@ public override string Defer(bool ephemeral = false, RequestOptions options = nu return SerializePayload(response); } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IComponentInteraction + /// + IComponentInteractionData IComponentInteraction.Data => Data; + + /// + IUserMessage IComponentInteraction.Message => Message; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs index f8aa24937..e865c208c 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs @@ -10,7 +10,7 @@ namespace Discord.Rest /// /// Represents data for a . /// - public class RestMessageComponentData : IDiscordInteractionData + public class RestMessageComponentData : IComponentInteractionData, IDiscordInteractionData { /// /// Gets the components Custom Id that was clicked. diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs index d3e99fcb9..3b879cd4e 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs @@ -12,7 +12,7 @@ namespace Discord.Rest /// /// Represents a REST-based autocomplete interaction. /// - public class RestAutocompleteInteraction : RestInteraction, IDiscordInteraction + public class RestAutocompleteInteraction : RestInteraction, IAutocompleteInteraction, IDiscordInteraction { /// /// Gets the autocomplete data of this interaction. @@ -128,7 +128,8 @@ public override Task FollowupWithFileAsync(string filePath, public override string Respond(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException("Autocomplete interactions cannot be deferred!"); - IDiscordInteractionData IDiscordInteraction.Data => Data; - + //IAutocompleteInteraction + /// + IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs index 10c4f403e..135eb88ea 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs @@ -11,7 +11,7 @@ namespace Discord.Rest /// /// Represents the data for a . /// - public class RestAutocompleteInteractionData : IDiscordInteractionData + public class RestAutocompleteInteractionData : IAutocompleteInteractionData { /// /// Gets the name of the invoked command. diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs index a5971c8e6..4e4989d29 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs @@ -11,7 +11,7 @@ namespace Discord.Rest /// /// Represents a REST-based slash command. /// - public class RestSlashCommand : RestCommandBase, IDiscordInteraction + public class RestSlashCommand : RestCommandBase, ISlashCommandInteraction, IDiscordInteraction { /// /// Gets the data associated with this interaction. @@ -39,6 +39,8 @@ internal override async Task UpdateAsync(DiscordRestClient client, Model model) Data = await RestSlashCommandData.CreateAsync(client, dataModel, Guild, Channel); } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //ISlashCommandInteraction + /// + IApplicationCommandInteractionData ISlashCommandInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs index 99c45b6c3..ef42533f0 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs @@ -6,7 +6,7 @@ namespace Discord.WebSocket /// /// Represents a Websocket-based slash command received over the gateway. /// - public class SocketMessageCommand : SocketCommandBase, IDiscordInteraction + public class SocketMessageCommand : SocketCommandBase, IMessageCommandInteraction, IDiscordInteraction { /// /// The data associated with this interaction. @@ -34,6 +34,8 @@ internal SocketMessageCommand(DiscordSocketClient client, Model model, ISocketMe return entity; } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IMessageCommandInteraction + /// + IMessageCommandInteractionData IMessageCommandInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs index dc2ab3a19..71a30b44a 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs @@ -7,7 +7,7 @@ namespace Discord.WebSocket /// /// Represents the data tied with the interaction. /// - public class SocketMessageCommandData : SocketCommandBaseData, IDiscordInteractionData + public class SocketMessageCommandData : SocketCommandBaseData, IMessageCommandInteractionData, IDiscordInteractionData { /// /// Gets the message associated with this message command. @@ -31,5 +31,9 @@ internal SocketMessageCommandData(DiscordSocketClient client, Model model, ulong entity.Update(model); return entity; } + + //IMessageCommandInteractionData + /// + IMessage IMessageCommandInteractionData.Message => Message; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs index b77331790..22bbb5f4a 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs @@ -6,7 +6,7 @@ namespace Discord.WebSocket /// /// Represents a Websocket-based slash command received over the gateway. /// - public class SocketUserCommand : SocketCommandBase, IDiscordInteraction + public class SocketUserCommand : SocketCommandBase, IUserCommandInteraction, IDiscordInteraction { /// /// The data associated with this interaction. @@ -34,6 +34,8 @@ internal SocketUserCommand(DiscordSocketClient client, Model model, ISocketMessa return entity; } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IUserCommandInteraction + /// + IUserCommandInteractionData IUserCommandInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs index 1c6637b7e..28eea4f3d 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs @@ -7,7 +7,7 @@ namespace Discord.WebSocket /// /// Represents the data tied with the interaction. /// - public class SocketUserCommandData : SocketCommandBaseData, IDiscordInteractionData + public class SocketUserCommandData : SocketCommandBaseData, IUserCommandInteractionData, IDiscordInteractionData { /// /// Gets the user who this command targets. @@ -31,5 +31,9 @@ internal SocketUserCommandData(DiscordSocketClient client, Model model, ulong? g entity.Update(model); return entity; } + + //IUserCommandInteractionData + /// + IUser IUserCommandInteractionData.User => User; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs index 1b8e69ed6..b9d936a3c 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs @@ -13,7 +13,7 @@ namespace Discord.WebSocket /// /// Represents a Websocket-based interaction type for Message Components. /// - public class SocketMessageComponent : SocketInteraction, IDiscordInteraction + public class SocketMessageComponent : SocketInteraction, IComponentInteraction, IDiscordInteraction { /// /// Gets the data received with this interaction, contains the button that was clicked. @@ -422,6 +422,11 @@ public override async Task DeferAsync(bool ephemeral = false, RequestOptions opt } } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IComponentInteraction + /// + IComponentInteractionData IComponentInteraction.Data => Data; + + /// + IUserMessage IComponentInteraction.Message => Message; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs index 79f1cee57..71e1d0395 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs @@ -6,7 +6,7 @@ namespace Discord.WebSocket /// /// Represents the data sent with a . /// - public class SocketMessageComponentData : IDiscordInteractionData + public class SocketMessageComponentData : IComponentInteractionData { /// /// Gets the components Custom Id that was clicked. diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs index 6d24329b5..e938c6d7c 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs @@ -11,7 +11,7 @@ namespace Discord.WebSocket /// /// Represents a received over the gateway. /// - public class SocketAutocompleteInteraction : SocketInteraction, IDiscordInteraction + public class SocketAutocompleteInteraction : SocketInteraction, IAutocompleteInteraction, IDiscordInteraction { /// /// The autocomplete data of this interaction. @@ -115,6 +115,8 @@ public override Task FollowupWithFileAsync(string filePath, public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException("Autocomplete interactions cannot be deferred!"); - IDiscordInteractionData IDiscordInteraction.Data => Data; + //IAutocompleteInteraction + /// + IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs index b0527700f..1d9803c02 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs @@ -8,7 +8,7 @@ namespace Discord.WebSocket /// /// Represents data for a slash commands autocomplete interaction. /// - public class SocketAutocompleteInteractionData : IDiscordInteractionData + public class SocketAutocompleteInteractionData : IAutocompleteInteractionData, IDiscordInteractionData { /// /// Gets the name of the invoked command. diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs index 6aa65974f..beb4c4979 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs @@ -6,7 +6,7 @@ namespace Discord.WebSocket /// /// Represents a Websocket-based slash command received over the gateway. /// - public class SocketSlashCommand : SocketCommandBase, IDiscordInteraction + public class SocketSlashCommand : SocketCommandBase, ISlashCommandInteraction, IDiscordInteraction { /// /// The data associated with this interaction. @@ -34,6 +34,8 @@ internal SocketSlashCommand(DiscordSocketClient client, Model model, ISocketMess return entity; } - IDiscordInteractionData IDiscordInteraction.Data => Data; + //ISlashCommandInteraction + /// + IApplicationCommandInteractionData ISlashCommandInteraction.Data => Data; } } From e2f3ae4e1e14c4db83df9e4fe3216e65d1d83ddc Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Thu, 18 Nov 2021 20:05:05 +0300 Subject: [PATCH 02/12] fix build error --- .../MessageCommands/SocketMessageCommand.cs | 4 ++++ .../ContextMenuCommands/UserCommands/SocketUserCommand.cs | 4 ++++ .../ContextMenuCommands/UserCommands/SocketUserCommandData.cs | 2 +- .../Interaction/MessageComponents/SocketMessageComponent.cs | 4 ++++ .../SlashCommands/SocketAutocompleteInteraction.cs | 4 ++++ .../Entities/Interaction/SlashCommands/SocketSlashCommand.cs | 4 ++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs index ef42533f0..0aa061439 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs @@ -37,5 +37,9 @@ internal SocketMessageCommand(DiscordSocketClient client, Model model, ISocketMe //IMessageCommandInteraction /// IMessageCommandInteractionData IMessageCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs index 22bbb5f4a..40ee5b537 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs @@ -37,5 +37,9 @@ internal SocketUserCommand(DiscordSocketClient client, Model model, ISocketMessa //IUserCommandInteraction /// IUserCommandInteractionData IUserCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs index 28eea4f3d..eaebbcb06 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs @@ -34,6 +34,6 @@ internal SocketUserCommandData(DiscordSocketClient client, Model model, ulong? g //IUserCommandInteractionData /// - IUser IUserCommandInteractionData.User => User; + IUser IUserCommandInteractionData.User => Member; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs index b9d936a3c..4cb096e3e 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs @@ -428,5 +428,9 @@ public override async Task DeferAsync(bool ephemeral = false, RequestOptions opt /// IUserMessage IComponentInteraction.Message => Message; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs index e938c6d7c..13ef87aa6 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs @@ -118,5 +118,9 @@ public override Task RespondAsync(string text = null, Embed[] embeds = null, boo //IAutocompleteInteraction /// IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs index beb4c4979..5343bb225 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs @@ -37,5 +37,9 @@ internal SocketSlashCommand(DiscordSocketClient client, Model model, ISocketMess //ISlashCommandInteraction /// IApplicationCommandInteractionData ISlashCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; } } From d1eb6c96cd7bea12042d7de6f268c8764059af4b Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Thu, 18 Nov 2021 21:36:08 +0300 Subject: [PATCH 03/12] implement change requests --- .../Interactions/ContextMenus/IMessageCommandInteraction.cs | 2 +- .../Interactions/ContextMenus/IUserCommandInteraction.cs | 2 +- .../Interactions/SlashCommands/IAutocompleteInteraction.cs | 4 ++-- .../Interactions/SlashCommands/ISlashCommandInteraction.cs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs index 2f73fcbe0..b1b331e8b 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs @@ -1,7 +1,7 @@ namespace Discord { /// - /// Represents a Message Command interaction received over the gateway. + /// Represents a Message Command interaction. /// public interface IMessageCommandInteraction : IDiscordInteraction { diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs index 9dd8e7aa4..f7cfd67f0 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs @@ -1,7 +1,7 @@ namespace Discord { /// - /// Represents a User Command interaction received over the gateway. + /// Represents a User Command interaction. /// public interface IUserCommandInteraction : IDiscordInteraction { diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs index 08f4a5f2e..bb5343d84 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs @@ -1,12 +1,12 @@ namespace Discord { /// - /// Represents a received over the gateway. + /// Represents a . /// public interface IAutocompleteInteraction : IDiscordInteraction { /// - /// The autocomplete data of this interaction. + /// Gets the autocomplete data of this interaction. /// new IAutocompleteInteractionData Data { get; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs index e616aac7f..556182987 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs @@ -1,12 +1,12 @@ namespace Discord { /// - /// Represents a slash command interaction received over the gateway. + /// Represents a slash command interaction. /// public interface ISlashCommandInteraction : IDiscordInteraction { /// - /// The data associated with this interaction. + /// Gets the data associated with this interaction. /// new IApplicationCommandInteractionData Data { get; } } From f2fc50f1f19a0b41144b6dc93080d2f3a01282fc Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Tue, 23 Nov 2021 12:43:11 +0300 Subject: [PATCH 04/12] add autocomplete respond method to IAutocompleteInteraction --- .../SlashCommands/IAutocompleteInteraction.cs | 19 +++++++++++++++++++ .../RestAutocompleteInteraction.cs | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs index bb5343d84..e5f7106f9 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + namespace Discord { /// @@ -9,5 +12,21 @@ public interface IAutocompleteInteraction : IDiscordInteraction /// Gets the autocomplete data of this interaction. /// new IAutocompleteInteractionData Data { get; } + + /// + /// Responds to this interaction with a set of choices. + /// + /// + /// The set of choices for the user to pick from. + /// + /// A max of 20 choices are allowed. Passing for this argument will show the executing user that + /// there is no choices for their autocompleted input. + /// + /// + /// The request options for this response. + /// + /// A task that represents the asynchronous operation of responding to this interaction. + /// + Task RespondAsync(IEnumerable result, RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs index 3b879cd4e..2af3ec7e2 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs @@ -131,5 +131,9 @@ public override string Respond(string text = null, Embed[] embeds = null, bool i //IAutocompleteInteraction /// IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; + + /// + Task IAutocompleteInteraction.RespondAsync(IEnumerable result, RequestOptions options) + => Task.FromResult(Respond(result, options)); } } From a9c15ffd6ab02651e83e72c275889502b60cfddc Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Thu, 25 Nov 2021 12:49:13 +0300 Subject: [PATCH 05/12] fix sharded client current user --- src/Discord.Net.WebSocket/DiscordShardedClient.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index 307f9a009..1e71ce853 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -495,9 +495,12 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary) client.GuildScheduledEventUserAdd += (arg1, arg2) => _guildScheduledEventUserAdd.InvokeAsync(arg1, arg2); client.GuildScheduledEventUserRemove += (arg1, arg2) => _guildScheduledEventUserRemove.InvokeAsync(arg1, arg2); } -#endregion + #endregion #region IDiscordClient + /// + ISelfUser IDiscordClient.CurrentUser => CurrentUser; + /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); From 83c86e918823b8b2ceff94d4b7284f24ee54577a Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:06:06 +0300 Subject: [PATCH 06/12] fix generic typeconverter picking priority --- .../interactions_framework/typeconverters.md | 4 ++-- .../InteractionService.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/guides/interactions_framework/typeconverters.md b/docs/guides/interactions_framework/typeconverters.md index c06f40386..12ca7dab5 100644 --- a/docs/guides/interactions_framework/typeconverters.md +++ b/docs/guides/interactions_framework/typeconverters.md @@ -40,8 +40,8 @@ This method is used by Interaction Service to search for alternative Type Conver Interaction Services determines the most suitable `TypeConverter` for a parameter type in the following order: 1. It searches for a `TypeConverter` that is registered to specifically target that parameter type -2. It searches for a `TypeConverter` that returns `true` when its `CanConvertTo()` method is invoked for thaty parameter type. -3. It searches for a generic `TypeConverter` with a matching type constraint. If there are more multiple matches, the one whose type constraint is the most specialized will be chosen. +2. It searches for a generic `TypeConverter` with a matching type constraint. If there are more multiple matches, the one whose type constraint is the most specialized will be chosen. +3. It searches for a `TypeConverter` that returns `true` when its `CanConvertTo()` method is invoked for thaty parameter type. > Alternatively, you can use the generic variant (`TypeConverter`) of the `TypeConverter` base class which implements the following method body for `CanConvertTo()` method diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index 0740f7507..510a5952d 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -631,9 +631,6 @@ internal TypeConverter GetTypeConverter (Type type, IServiceProvider services = if (_typeConverters.TryGetValue(type, out var specific)) return specific; - else if (_typeConverters.Any(x => x.Value.CanConvertTo(type))) - return _typeConverters.First(x => x.Value.CanConvertTo(type)).Value; - else if (_genericTypeConverters.Any(x => x.Key.IsAssignableFrom(type))) { services ??= EmptyServiceProvider.Instance; @@ -644,6 +641,9 @@ internal TypeConverter GetTypeConverter (Type type, IServiceProvider services = return converter; } + else if (_typeConverters.Any(x => x.Value.CanConvertTo(type))) + return _typeConverters.First(x => x.Value.CanConvertTo(type)).Value; + throw new ArgumentException($"No type {nameof(TypeConverter)} is defined for this {type.FullName}", "type"); } @@ -861,16 +861,14 @@ public void Dispose ( ) private Type GetMostSpecificTypeConverter (Type type) { - var scorePairs = new Dictionary(); - var validConverters = _genericTypeConverters.Where(x => x.Key.IsAssignableFrom(type)); + if (_genericTypeConverters.TryGetValue(type, out var matching)) + return matching; - foreach (var typeConverterPair in validConverters) - { - var score = validConverters.Count(x => typeConverterPair.Key.IsAssignableFrom(x.Key)); - scorePairs.Add(typeConverterPair.Value, score); - } + var typeInterfaces = type.GetInterfaces(); + var candidates = _genericTypeConverters.Where(x => x.Key.IsAssignableFrom(type)) + .OrderByDescending(x => typeInterfaces.Count(y => y.IsAssignableFrom(x.Key))); - return scorePairs.OrderBy(x => x.Value).ElementAt(0).Key; + return candidates.First().Value; } private void EnsureClientReady() From 40a8e82a9cfc3a917dd0826dae2a4bd20548575a Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:07:42 +0300 Subject: [PATCH 07/12] Revert "fix sharded client current user" This reverts commit a9c15ffd6ab02651e83e72c275889502b60cfddc. --- src/Discord.Net.WebSocket/DiscordShardedClient.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index 1e71ce853..307f9a009 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -495,12 +495,9 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary) client.GuildScheduledEventUserAdd += (arg1, arg2) => _guildScheduledEventUserAdd.InvokeAsync(arg1, arg2); client.GuildScheduledEventUserRemove += (arg1, arg2) => _guildScheduledEventUserRemove.InvokeAsync(arg1, arg2); } - #endregion +#endregion #region IDiscordClient - /// - ISelfUser IDiscordClient.CurrentUser => CurrentUser; - /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); From 5ea1fa0a218a17fd3220323e9b94666efdd4dd1c Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:08:31 +0300 Subject: [PATCH 08/12] Revert "add autocomplete respond method to IAutocompleteInteraction" This reverts commit f2fc50f1f19a0b41144b6dc93080d2f3a01282fc. --- .../SlashCommands/IAutocompleteInteraction.cs | 19 ------------------- .../RestAutocompleteInteraction.cs | 4 ---- 2 files changed, 23 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs index e5f7106f9..bb5343d84 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - namespace Discord { /// @@ -12,21 +9,5 @@ public interface IAutocompleteInteraction : IDiscordInteraction /// Gets the autocomplete data of this interaction. /// new IAutocompleteInteractionData Data { get; } - - /// - /// Responds to this interaction with a set of choices. - /// - /// - /// The set of choices for the user to pick from. - /// - /// A max of 20 choices are allowed. Passing for this argument will show the executing user that - /// there is no choices for their autocompleted input. - /// - /// - /// The request options for this response. - /// - /// A task that represents the asynchronous operation of responding to this interaction. - /// - Task RespondAsync(IEnumerable result, RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs index 2af3ec7e2..3b879cd4e 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs @@ -131,9 +131,5 @@ public override string Respond(string text = null, Embed[] embeds = null, bool i //IAutocompleteInteraction /// IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; - - /// - Task IAutocompleteInteraction.RespondAsync(IEnumerable result, RequestOptions options) - => Task.FromResult(Respond(result, options)); } } From fa389c2db3b3dc6f3007d7577f56fbc89913f593 Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:38:08 +0300 Subject: [PATCH 09/12] fix command parsing for names with spaces --- src/Discord.Net.Interactions/Map/CommandMap.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Interactions/Map/CommandMap.cs b/src/Discord.Net.Interactions/Map/CommandMap.cs index 6fd79ea81..aa5c7fcfc 100644 --- a/src/Discord.Net.Interactions/Map/CommandMap.cs +++ b/src/Discord.Net.Interactions/Map/CommandMap.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Discord.Interactions { @@ -46,8 +47,13 @@ public void RemoveCommand(T command) _root.RemoveCommand(key, 0); } - public SearchResult GetCommand(string input) => - GetCommand(input.Split(_seperators)); + public SearchResult GetCommand(string input) + { + if(_seperators.Any()) + return GetCommand(input.Split(_seperators)); + else + return GetCommand(new string[] { input }); + } public SearchResult GetCommand(string[] input) => _root.GetCommand(input, 0); From e05a0c44b73280a0460e561ff0184714cf024f7f Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sat, 27 Nov 2021 16:12:30 +0300 Subject: [PATCH 10/12] add SlashCommandExecuted event invoke to failed type conversion --- src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs index fad015550..116a07ab4 100644 --- a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs @@ -81,7 +81,10 @@ private async Task ExecuteAsync (IInteractionContext context, IEnumerab var readResult = await typeConverter.ReadAsync(context, arg, services).ConfigureAwait(false); if (!readResult.IsSuccess) + { + await InvokeModuleEvent(context, readResult).ConfigureAwait(false); return readResult; + } args[i] = readResult.Value; } From 6ac8cd0da60b440874cf29abc7202cdc49fd0538 Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sat, 27 Nov 2021 16:28:40 +0300 Subject: [PATCH 11/12] update interactions sample app --- samples/04_interactions_framework/CommandHandler.cs | 2 -- samples/04_interactions_framework/Program.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/samples/04_interactions_framework/CommandHandler.cs b/samples/04_interactions_framework/CommandHandler.cs index 735557da5..8e5c3af94 100644 --- a/samples/04_interactions_framework/CommandHandler.cs +++ b/samples/04_interactions_framework/CommandHandler.cs @@ -138,8 +138,6 @@ private async Task HandleInteraction (SocketInteraction arg) // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original // response, or at least let the user know that something went wrong during the command execution. - if(arg.Type == InteractionType.ApplicationCommand) - await arg.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync()); } } } diff --git a/samples/04_interactions_framework/Program.cs b/samples/04_interactions_framework/Program.cs index 5dedbfae9..20bbbbacc 100644 --- a/samples/04_interactions_framework/Program.cs +++ b/samples/04_interactions_framework/Program.cs @@ -68,7 +68,7 @@ static ServiceProvider ConfigureServices ( IConfiguration configuration ) return new ServiceCollection() .AddSingleton(configuration) .AddSingleton() - .AddSingleton(x => new InteractionService(x.GetRequiredService())) + .AddSingleton() .AddSingleton() .BuildServiceProvider(); } From f7a9785decb3b37c0f50d83486ea9018d294e0cf Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sat, 27 Nov 2021 16:30:08 +0300 Subject: [PATCH 12/12] Revert "update interactions sample app" This reverts commit 6ac8cd0da60b440874cf29abc7202cdc49fd0538. --- samples/04_interactions_framework/CommandHandler.cs | 2 ++ samples/04_interactions_framework/Program.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/04_interactions_framework/CommandHandler.cs b/samples/04_interactions_framework/CommandHandler.cs index 8e5c3af94..735557da5 100644 --- a/samples/04_interactions_framework/CommandHandler.cs +++ b/samples/04_interactions_framework/CommandHandler.cs @@ -138,6 +138,8 @@ private async Task HandleInteraction (SocketInteraction arg) // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original // response, or at least let the user know that something went wrong during the command execution. + if(arg.Type == InteractionType.ApplicationCommand) + await arg.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync()); } } } diff --git a/samples/04_interactions_framework/Program.cs b/samples/04_interactions_framework/Program.cs index 20bbbbacc..5dedbfae9 100644 --- a/samples/04_interactions_framework/Program.cs +++ b/samples/04_interactions_framework/Program.cs @@ -68,7 +68,7 @@ static ServiceProvider ConfigureServices ( IConfiguration configuration ) return new ServiceCollection() .AddSingleton(configuration) .AddSingleton() - .AddSingleton() + .AddSingleton(x => new InteractionService(x.GetRequiredService())) .AddSingleton() .BuildServiceProvider(); }