From 6533a2ad367f48dbde5b9ffe7a8cacdececc7b77 Mon Sep 17 00:00:00 2001 From: quin lynch Date: Tue, 12 Oct 2021 01:00:24 -0300 Subject: [PATCH] Add IMessage.Interaction --- src/Discord.Net.Core/Discord.Net.Core.xml | 170 ++++++++++++++---- .../Entities/Messages/IMessage.cs | 10 +- .../Entities/Messages/IMessageInteraction.cs | 34 ++++ .../Entities/Messages/MessageInteraction.cs | 45 +++++ src/Discord.Net.Rest/API/Common/Message.cs | 1 + .../API/Common/MessageInteraction.cs | 21 +++ src/Discord.Net.Rest/Discord.Net.Rest.xml | 11 ++ .../Entities/Messages/RestMessage.cs | 16 ++ .../Discord.Net.WebSocket.xml | 18 +- .../Entities/Messages/SocketMessage.cs | 16 ++ 10 files changed, 297 insertions(+), 45 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs create mode 100644 src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs create mode 100644 src/Discord.Net.Rest/API/Common/MessageInteraction.cs diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index a12881481..0c89d5416 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -2277,7 +2277,7 @@ The options to be used when sending the request. - A task that represents the asynchronous join operation. + A task that represents the asynchronous join operation. @@ -2286,7 +2286,7 @@ The options to be used when sending the request. - A task that represents the asynchronous leave operation. + A task that represents the asynchronous leave operation. @@ -2296,7 +2296,7 @@ The to add. The options to be used when sending the request. - A task that represents the asynchronous operation of adding a member to a thread. + A task that represents the asynchronous operation of adding a member to a thread. @@ -2306,7 +2306,7 @@ The to remove from this thread. The options to be used when sending the request. - A task that represents the asynchronous operation of removing a user from this thread. + A task that represents the asynchronous operation of removing a user from this thread. @@ -2384,6 +2384,21 @@ Gets or sets the privacy level of the stage. + + + Specifies the privacy levels of a Stage instance. + + + + + The Stage instance is visible publicly, such as on Stage Discovery. + + + + + The Stage instance is visible to only guild members. + + Provides properties that are used to modify an with the specified changes. @@ -2457,7 +2472,7 @@ Three days (4320 minutes). - This option is explicity avaliable to nitro users. + This option is explicitly available to nitro users. @@ -2465,7 +2480,7 @@ One week (10080 minutes). - This option is explicity avaliable to nitro users. + This option is explicitly available to nitro users. @@ -4632,7 +4647,7 @@ - A . + A . @@ -4758,7 +4773,7 @@ - + Returns the maximum length a commands name allowed by Discord @@ -4860,7 +4875,7 @@ - The type of the command + The type of the command. @@ -5100,7 +5115,7 @@ - Represents an interface used to specify classes that they are a vaild data type of a class. + Represents an interface used to specify classes that they are a valid data type of a class. @@ -5111,7 +5126,7 @@ After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using or you can choose to send a deferred response with . If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. - You can read more about Response types Here + You can read more about Response types Here. @@ -5141,17 +5156,17 @@ - For components: ACK an interaction and edit the original message later; the user does not see a loading state + For components: ACK an interaction and edit the original message later; the user does not see a loading state. - For components: edit the message the component was attached to + For components: edit the message the component was attached to. - Respond with a set of choices to a autocomplete interaction + Respond with a set of choices to a autocomplete interaction. @@ -5181,7 +5196,7 @@ - Represents a Row for child components to live in. + Represents a Row for child components to live in. @@ -5220,7 +5235,7 @@ - Gets the URL for a button. + Gets the URL for a button. You cannot have a button with a URL and a CustomId. @@ -5762,7 +5777,7 @@ - Gets or sets the custom id of the current select menu. + Gets or sets the value of the current select menu. length exceeds . length subceeds 1. @@ -5860,22 +5875,22 @@ - Represents a type of a component + Represents a type of a component. - A container for other components + A container for other components. - A clickable button + A clickable button. - A select menu for picking from choices + A select menu for picking from choices. @@ -6061,7 +6076,7 @@ The description of this option. If this option is required for this command. If this option is the default option. - If this option is set to autocompleate. + If this option is set to autocomplete. The options of the option to add. The allowed channel types for this option. The choices of this option. @@ -6196,7 +6211,7 @@ - Adds a channnel type to the current option. + Adds a channel type to the current option. The to add. The current builder. @@ -7466,6 +7481,14 @@ The width of this attachment if it is a picture; otherwise null. + + + Gets whether or not this attachment is ephemeral. + + + if the attachment is ephemeral; otherwise . + + Represents a Discord embed object. @@ -7784,6 +7807,14 @@ A message's flags, if any is associated. + + + Gets the interaction this message is a response to. + + + A if the message is a response to an interaction; otherwise . + + Adds a reaction to this message. @@ -7891,6 +7922,31 @@ Paged collection of users. + + + Represents a partial within a message. + + + + + Gets the snowflake id of the interaction. + + + + + Gets the type of the interaction. + + + + + Gets the name of the application command used. + + + + + Gets the who invoked the interaction. + + Represents a generic reaction object. @@ -8082,6 +8138,32 @@ Flag given to messages that is an Interaction Response and the bot is "thinking" + + + Represents a partial within a message. + + The type of the user. + + + + Gets the snowflake id of the interaction. + + + + + Gets the type of the interaction. + + + + + Gets the name of the application command used. + + + + + Gets the who invoked the interaction. + + Properties that are used to modify an with the specified changes. @@ -8345,19 +8427,29 @@ - Defines the types of formats for stickers. + + Defines the types of formats for stickers. + - Default value for a sticker format type. + + Default value for a sticker format type. + - The sticker format type is png. + + The sticker format type is png. + - The sticker format type is apng. + + The sticker format type is apng. + - The sticker format type is lottie. + + The sticker format type is lottie. + @@ -8444,7 +8536,7 @@ If the is null then the default 0 will be used. - A string thats compatible in a discord message, ex: <t:1625944201:f> + A string that is compatible in a discord message, ex: <t:1625944201:f> @@ -9996,12 +10088,12 @@ - Gets whether this guild sticker can be used, may be false due to loss of Server Boosts + Gets whether this guild sticker can be used, may be false due to loss of Server Boosts. - Gets the standard sticker's sort order within its pack + Gets the standard sticker's sort order within its pack. @@ -10033,7 +10125,7 @@ Represents a discord sticker pack. - The type of the stickers within the collection + The type of the stickers within the collection. @@ -10092,7 +10184,7 @@ - Represents a type of sticker + Represents a type of sticker.. @@ -12970,20 +13062,20 @@ Not full URL validation right now. Just ensures protocol is present and that it's either http or https - should be used for url buttons + should be used for url buttons. - url to validate before sending to Discord. + The URL to validate before sending to Discord. A URL must include a protocol (http or https). - true if url is valid by our standard, false if null, throws an error upon invalid + true if URL is valid by our standard, false if null, throws an error upon invalid. Not full URL validation right now. Just Ensures the protocol is either http, https, or discord - should be used everything other than url buttons + should be used everything other than url buttons. - the url to validate before sending to discord + The URL to validate before sending to discord. A URL must include a protocol (either http, https, or discord). - true if the url is valid by our standard, false if null, throws an error upon invalid + true if the URL is valid by our standard, false if null, throws an error upon invalid. diff --git a/src/Discord.Net.Core/Entities/Messages/IMessage.cs b/src/Discord.Net.Core/Entities/Messages/IMessage.cs index af88554e7..f5f2ca007 100644 --- a/src/Discord.Net.Core/Entities/Messages/IMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IMessage.cs @@ -194,7 +194,15 @@ namespace Discord /// A message's flags, if any is associated. /// MessageFlags? Flags { get; } - + + /// + /// Gets the interaction this message is a response to. + /// + /// + /// A if the message is a response to an interaction; otherwise . + /// + IMessageInteraction Interaction { get; } + /// /// Adds a reaction to this message. /// diff --git a/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs b/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs new file mode 100644 index 000000000..ebd03b627 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a partial within a message. + /// + public interface IMessageInteraction + { + /// + /// Gets the snowflake id of the interaction. + /// + ulong Id { get; } + + /// + /// Gets the type of the interaction. + /// + InteractionType Type { get; } + + /// + /// Gets the name of the application command used. + /// + string Name { get; } + + /// + /// Gets the who invoked the interaction. + /// + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs b/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs new file mode 100644 index 000000000..cbbebd932 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a partial within a message. + /// + /// The type of the user. + public class MessageInteraction : IMessageInteraction where TUser : IUser + { + /// + /// Gets the snowflake id of the interaction. + /// + public ulong Id { get; } + + /// + /// Gets the type of the interaction. + /// + public InteractionType Type { get; } + + /// + /// Gets the name of the application command used. + /// + public string Name { get; } + + /// + /// Gets the who invoked the interaction. + /// + public TUser User { get; } + + internal MessageInteraction(ulong id, InteractionType type, string name, TUser user) + { + Id = id; + Type = type; + Name = name; + User = user; + } + + IUser IMessageInteraction.User => User; + } +} diff --git a/src/Discord.Net.Rest/API/Common/Message.cs b/src/Discord.Net.Rest/API/Common/Message.cs index c19dc8942..d33a03fe5 100644 --- a/src/Discord.Net.Rest/API/Common/Message.cs +++ b/src/Discord.Net.Rest/API/Common/Message.cs @@ -59,6 +59,7 @@ namespace Discord.API public Optional ReferencedMessage { get; set; } [JsonProperty("components")] public Optional Components { get; set; } + public Optional Interaction { get; set; } [JsonProperty("sticker_items")] public Optional StickerItems { get; set; } } diff --git a/src/Discord.Net.Rest/API/Common/MessageInteraction.cs b/src/Discord.Net.Rest/API/Common/MessageInteraction.cs new file mode 100644 index 000000000..48f278396 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/MessageInteraction.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class MessageInteraction + { + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("type")] + public InteractionType Type { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("user")] + public User User { get; set; } + } +} diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.xml b/src/Discord.Net.Rest/Discord.Net.Rest.xml index cd5187220..a8927268d 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.xml +++ b/src/Discord.Net.Rest/Discord.Net.Rest.xml @@ -4449,6 +4449,11 @@ + + + Gets the interaction this message is a response to. + + @@ -4489,6 +4494,9 @@ + + + @@ -5248,6 +5256,9 @@ + + + Returns the filename of this attachment. diff --git a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs index 22b109549..c48a60aac 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs @@ -70,6 +70,11 @@ namespace Discord.Rest public MessageApplication Application { get; private set; } /// public MessageReference Reference { get; private set; } + + /// + /// Gets the interaction this message is a response to. + /// + public MessageInteraction Interaction { get; private set; } /// public MessageFlags? Flags { get; private set; } /// @@ -212,6 +217,14 @@ namespace Discord.Rest else _reactions = ImmutableArray.Create(); + if (model.Interaction.IsSpecified) + { + Interaction = new MessageInteraction(model.Interaction.Value.Id, + model.Interaction.Value.Type, + model.Interaction.Value.Name, + RestUser.Create(Discord, model.Interaction.Value.User)); + } + if (model.UserMentions.IsSpecified) { var value = model.UserMentions.Value; @@ -257,6 +270,9 @@ namespace Discord.Rest /// IReadOnlyCollection IMessage.Components => Components; + /// + IMessageInteraction IMessage.Interaction => Interaction; + /// IReadOnlyCollection IMessage.Stickers => Stickers; diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index c2f7382f1..f3a05fafa 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -2664,7 +2664,7 @@ Downloads all users that have access to this thread. The options to be used when sending the request. - A task representing the asyncronous download operation. + A task representing the asynchronous download operation. @@ -2679,7 +2679,7 @@ The to add. The options to be used when sending the request. - A task that represents the asynchronous operation of adding a member to a thread. + A task that represents the asynchronous operation of adding a member to a thread. @@ -2689,7 +2689,7 @@ The to remove from this thread. The options to be used when sending the request. - A task that represents the asynchronous operation of removing a user from this thread. + A task that represents the asynchronous operation of removing a user from this thread. @@ -4081,7 +4081,7 @@ - Represents a Websocket-based received by the gateway + Represents a Websocket-based received by the gateway. @@ -4100,7 +4100,7 @@ - Represends a Websocket-based . + Represents a Websocket-based . @@ -4574,6 +4574,11 @@ + + + Gets the interaction this message is a response to. + + @@ -4667,6 +4672,9 @@ + + + diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs index a287610f5..bbadb8ce5 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs @@ -67,6 +67,11 @@ namespace Discord.WebSocket /// public IReadOnlyCollection Components { get; private set; } + /// + /// Gets the interaction this message is a response to. + /// + public MessageInteraction Interaction { get; private set; } + /// public MessageFlags? Flags { get; private set; } @@ -253,6 +258,14 @@ namespace Discord.WebSocket } } + if (model.Interaction.IsSpecified) + { + Interaction = new MessageInteraction(model.Interaction.Value.Id, + model.Interaction.Value.Type, + model.Interaction.Value.Name, + SocketGlobalUser.Create(Discord, state, model.Interaction.Value.User)); + } + if (model.Flags.IsSpecified) Flags = model.Flags.Value; } @@ -290,6 +303,9 @@ namespace Discord.WebSocket /// IReadOnlyCollection IMessage.Components => Components; + /// + IMessageInteraction IMessage.Interaction => Interaction; + /// IReadOnlyCollection IMessage.Stickers => Stickers;