Files
Discord.Net/src/Discord.Net.Rest/API/Common/ButtonComponent.cs
Mihail Gribkov 4ab96c7721 yep (#3121)
2025-05-09 18:18:16 +03:00

77 lines
2.0 KiB
C#

using Newtonsoft.Json;
namespace Discord.API
{
internal class ButtonComponent : IInteractableComponent
{
[JsonProperty("type")]
public ComponentType Type { get; set; }
[JsonProperty("id")]
public Optional<int> Id { get; set; }
[JsonProperty("style")]
public ButtonStyle Style { get; set; }
[JsonProperty("label")]
public Optional<string> Label { get; set; }
[JsonProperty("emoji")]
public Optional<Emoji> Emote { get; set; }
[JsonProperty("custom_id")]
public Optional<string> CustomId { get; set; }
[JsonProperty("url")]
public Optional<string> Url { get; set; }
[JsonProperty("disabled")]
public Optional<bool> Disabled { get; set; }
[JsonProperty("sku_id")]
public Optional<ulong> SkuId { get; set; }
public ButtonComponent() { }
public ButtonComponent(Discord.ButtonComponent c)
{
Type = c.Type;
Style = c.Style;
Label = c.Label;
CustomId = c.CustomId;
Url = c.Url;
Disabled = c.IsDisabled;
SkuId = c.SkuId ?? Optional<ulong>.Unspecified;
Id = c.Id ?? Optional<int>.Unspecified;
if (c.Emote != null)
{
if (c.Emote is Emote e)
{
Emote = new Emoji
{
Name = e.Name,
Animated = e.Animated,
Id = e.Id
};
}
else
{
Emote = new Emoji
{
Name = c.Emote.Name
};
}
}
}
[JsonIgnore]
string IInteractableComponent.CustomId => CustomId.GetValueOrDefault();
[JsonIgnore]
int? IMessageComponent.Id => Id.ToNullable();
IMessageComponentBuilder IMessageComponent.ToBuilder() => null;
}
}