diff --git a/DisCatSharp/Entities/Interaction/Components/DiscordLinkButtonComponent.cs b/DisCatSharp/Entities/Interaction/Components/DiscordLinkButtonComponent.cs index c56973cd6..e0d56f2ae 100644 --- a/DisCatSharp/Entities/Interaction/Components/DiscordLinkButtonComponent.cs +++ b/DisCatSharp/Entities/Interaction/Components/DiscordLinkButtonComponent.cs @@ -1,86 +1,106 @@ // This file is part of the DisCatSharp project. // // Copyright (c) 2021 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using DisCatSharp.Enums; using Newtonsoft.Json; namespace DisCatSharp.Entities { /// /// Represents a link button. Clicking a link button does not send an interaction. /// public class DiscordLinkButtonComponent : DiscordComponent { /// /// The url to open when pressing this button. /// [JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)] public string Url { get; set; } /// /// The text to add to this button. If this is not specified, must be. /// [JsonProperty("label", NullValueHandling = NullValueHandling.Ignore)] public string Label { get; set; } /// /// Whether this button can be pressed. /// [JsonProperty("disabled", NullValueHandling = NullValueHandling.Ignore)] public bool Disabled { get; set; } /// /// The emoji to add to the button. Can be used in conjunction with a label, or as standalone. Must be added if label is not specified. /// [JsonProperty("emoji", NullValueHandling = NullValueHandling.Ignore)] public DiscordComponentEmoji Emoji { get; set; } /// /// Gets the style. /// [JsonProperty("style", NullValueHandling = NullValueHandling.Ignore)] internal int Style { get; } = 5; // Link = 5; Discord throws 400 otherwise // + /// + /// Enables this component if it was disabled before. + /// + /// The current component. + public DiscordLinkButtonComponent Enable() + { + this.Disabled = false; + return this; + } + + /// + /// Disables this component. + /// + /// The current component. + public DiscordLinkButtonComponent Disable() + { + this.Disabled = true; + return this; + } + /// /// Constructs a new . This type of button does not send back and interaction when pressed. /// /// The url to set the button to. /// The text to display on the button. Can be left blank if is set. /// Whether or not this button can be pressed. /// The emoji to set with this button. This is required if is null or empty. public DiscordLinkButtonComponent(string url, string label, bool disabled = false, DiscordComponentEmoji emoji = null) : this() { this.Url = url; this.Label = label; this.Disabled = disabled; this.Emoji = emoji; } /// /// Initializes a new instance of the class. /// internal DiscordLinkButtonComponent() { this.Type = ComponentType.Button; } } } diff --git a/DisCatSharp/Entities/Interaction/Components/DiscordSelectComponent.cs b/DisCatSharp/Entities/Interaction/Components/DiscordSelectComponent.cs index 5b0e61684..9f9fd1fd4 100644 --- a/DisCatSharp/Entities/Interaction/Components/DiscordSelectComponent.cs +++ b/DisCatSharp/Entities/Interaction/Components/DiscordSelectComponent.cs @@ -1,93 +1,113 @@ // This file is part of the DisCatSharp project. // // Copyright (c) 2021 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Collections.Generic; using System.Linq; using DisCatSharp.Enums; using Newtonsoft.Json; namespace DisCatSharp.Entities { /// /// A select menu with multiple options to choose from. /// public sealed class DiscordSelectComponent : DiscordComponent { /// /// The options to pick from on this component. /// [JsonProperty("options", NullValueHandling = NullValueHandling.Ignore)] public IReadOnlyList Options { get; internal set; } = Array.Empty(); /// /// The text to show when no option is selected. /// [JsonProperty("placeholder", NullValueHandling = NullValueHandling.Ignore)] public string Placeholder { get; internal set; } /// /// The minimum amount of options that can be selected. Must be less than or equal to . Defaults to one. /// [JsonProperty("min_values", NullValueHandling = NullValueHandling.Ignore)] public int? MinimumSelectedValues { get; internal set; } /// /// The maximum amount of options that can be selected. Must be greater than or equal to zero or . Defaults to one. /// [JsonProperty("max_values", NullValueHandling = NullValueHandling.Ignore)] public int? MaximumSelectedValues { get; internal set; } /// /// Whether this select can be used. /// [JsonProperty("disabled", NullValueHandling = NullValueHandling.Ignore)] public bool Disabled { get; internal set; } + /// + /// Enables this component if it was disabled before. + /// + /// The current component. + public DiscordSelectComponent Enable() + { + this.Disabled = false; + return this; + } + + /// + /// Disables this component. + /// + /// The current component. + public DiscordSelectComponent Disable() + { + this.Disabled = true; + return this; + } + /// /// Constructs a new . /// /// The Id to assign to the button. This is sent back when a user presses it. /// Array of options /// Text to show if no option is slected. /// Minmum count of selectable options. /// Maximum count of selectable options. /// Whether this button should be initialized as being disabled. User sees a greyed out button that cannot be interacted with. public DiscordSelectComponent(string customId, string placeholder, IEnumerable options, int minOptions = 1, int maxOptions = 1, bool disabled = false) : this() { this.CustomId = customId; this.Disabled = disabled; this.Options = options.ToArray(); this.Placeholder = placeholder; this.MinimumSelectedValues = minOptions; this.MaximumSelectedValues = maxOptions; } /// /// Initializes a new instance of the class. /// internal DiscordSelectComponent() { this.Type = ComponentType.Select; } } }