Add support for attachments (#2088)

* Enforce valid button styles

* support command option type 11

* missing '.'

* Added type converter.

Co-authored-by: Cat <lumitydev@gmail.com>
Co-authored-by: CottageDwellingCat <80918250+CottageDwellingCat@users.noreply.github.com>

Co-authored-by: FeroxFoxxo <feroxfoxxo@gmail.com>
Co-authored-by: Cat <lumitydev@gmail.com>
Co-authored-by: CottageDwellingCat <80918250+CottageDwellingCat@users.noreply.github.com>
This commit is contained in:
Quin Lynch
2022-02-09 00:13:15 -04:00
committed by GitHub
parent d142710d2a
commit 33efd8981d
8 changed files with 48 additions and 1 deletions

View File

@@ -18,5 +18,7 @@ namespace Discord.API
public Optional<Dictionary<string, Role>> Roles { get; set; }
[JsonProperty("messages")]
public Optional<Dictionary<string, Message>> Messages { get; set; }
[JsonProperty("attachments")]
public Optional<Dictionary<string, Attachment>> Attachments { get; set; }
}
}

View File

@@ -19,6 +19,9 @@ namespace Discord.Rest
internal readonly Dictionary<ulong, RestMessage> Messages
= new Dictionary<ulong, RestMessage>();
internal readonly Dictionary<ulong, Attachment> Attachments
= new Dictionary<ulong, Attachment>();
internal async Task PopulateAsync(DiscordRestClient discord, RestGuild guild, IRestMessageChannel channel, T model)
{
var resolved = model.Resolved.Value;
@@ -91,6 +94,16 @@ namespace Discord.Rest
Messages.Add(message.Id, message);
}
}
if (resolved.Attachments.IsSpecified)
{
foreach (var attachment in resolved.Attachments.Value)
{
var discordAttachment = Attachment.Create(attachment.Value);
Attachments.Add(ulong.Parse(attachment.Key), discordAttachment);
}
}
}
}
}

View File

@@ -43,6 +43,7 @@ namespace Discord.Rest
case ApplicationCommandOptionType.Role:
case ApplicationCommandOptionType.Channel:
case ApplicationCommandOptionType.Mentionable:
case ApplicationCommandOptionType.Attachment:
if (ulong.TryParse($"{model.Value.Value}", out var valueId))
{
switch (Type)
@@ -80,6 +81,9 @@ namespace Discord.Rest
}
}
break;
case ApplicationCommandOptionType.Attachment:
Value = data.ResolvableData.Attachments.FirstOrDefault(x => x.Key == valueId).Value;
break;
default:
Value = model.Value.Value;
break;