poggers (#2796)
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a message attachment found in a <see cref="IUserMessage"/>.
|
||||
/// </summary>
|
||||
public interface IAttachment
|
||||
public interface IAttachment : ISnowflakeEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ID of this attachment.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A snowflake ID associated with this attachment.
|
||||
/// </returns>
|
||||
ulong Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filename of this attachment.
|
||||
/// </summary>
|
||||
@@ -85,5 +80,20 @@ namespace Discord
|
||||
/// Gets flags related to this to this attachment.
|
||||
/// </summary>
|
||||
public AttachmentFlags Flags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets users who participated in the clip.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<IUser> ClipParticipants { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the clip. <see langword="null"/> if the clip has no title set.
|
||||
/// </summary>
|
||||
public string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the timestamp of the clip. <see langword="null"/> if the attachment is not a clip.
|
||||
/// </summary>
|
||||
public DateTimeOffset? ClipCreatedAt { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
@@ -42,4 +43,13 @@ internal class Attachment
|
||||
|
||||
[JsonProperty("flags")]
|
||||
public Optional<AttachmentFlags> Flags { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public Optional<string> Title { get; set; }
|
||||
|
||||
[JsonProperty("clip_created_at")]
|
||||
public Optional<DateTimeOffset> ClipCreatedAt { get; set; }
|
||||
|
||||
[JsonProperty("clip_participants")]
|
||||
public Optional<User[]> ClipParticipants { get; set; }
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Discord.Rest
|
||||
{
|
||||
foreach (var attachment in resolved.Attachments.Value)
|
||||
{
|
||||
var discordAttachment = Attachment.Create(attachment.Value);
|
||||
var discordAttachment = Attachment.Create(attachment.Value, discord);
|
||||
|
||||
Attachments.Add(ulong.Parse(attachment.Key), discordAttachment);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.Attachment;
|
||||
|
||||
namespace Discord
|
||||
@@ -32,11 +37,21 @@ namespace Discord
|
||||
/// <inheritdoc />
|
||||
public double? Duration { get; }
|
||||
|
||||
/// <inheritdoc cref="IAttachment.ClipParticipants" />
|
||||
public IReadOnlyCollection<RestUser> ClipParticipants { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Title { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset? ClipCreatedAt { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public AttachmentFlags Flags { get; }
|
||||
|
||||
internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width,
|
||||
bool? ephemeral, string description, string contentType, double? duration, string waveform, AttachmentFlags flags)
|
||||
bool? ephemeral, string description, string contentType, double? duration, string waveform, AttachmentFlags flags, string title,
|
||||
IReadOnlyCollection<RestUser> clipParticipants, DateTimeOffset? clipCreatedAt)
|
||||
{
|
||||
Id = id;
|
||||
Filename = filename;
|
||||
@@ -51,19 +66,29 @@ namespace Discord
|
||||
Duration = duration;
|
||||
Waveform = waveform;
|
||||
Flags = flags;
|
||||
Title = title;
|
||||
ClipParticipants = clipParticipants;
|
||||
ClipCreatedAt = clipCreatedAt;
|
||||
}
|
||||
internal static Attachment Create(Model model)
|
||||
|
||||
internal static Attachment Create(Model model, BaseDiscordClient discord)
|
||||
{
|
||||
return new Attachment(model.Id, model.Filename, model.Url, model.ProxyUrl, model.Size,
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null,
|
||||
model.Height.IsSpecified ? model.Height.Value : null,
|
||||
model.Width.IsSpecified ? model.Width.Value : null,
|
||||
model.Ephemeral.ToNullable(), model.Description.GetValueOrDefault(),
|
||||
model.ContentType.GetValueOrDefault(),
|
||||
model.DurationSeconds.IsSpecified ? model.DurationSeconds.Value : null,
|
||||
model.Waveform.GetValueOrDefault(null),
|
||||
model.Flags.GetValueOrDefault(AttachmentFlags.None));
|
||||
model.Flags.GetValueOrDefault(AttachmentFlags.None),
|
||||
model.Title.GetValueOrDefault(null),
|
||||
model.ClipParticipants.GetValueOrDefault(Array.Empty<API.User>()).Select(x => RestUser.Create(discord, x)).ToImmutableArray(),
|
||||
model.ClipCreatedAt.IsSpecified ? model.ClipCreatedAt.Value : null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the filename of this attachment.
|
||||
/// </summary>
|
||||
@@ -72,5 +97,8 @@ namespace Discord
|
||||
/// </returns>
|
||||
public override string ToString() => Filename;
|
||||
private string DebuggerDisplay => $"{Filename} ({Size} bytes)";
|
||||
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<IUser> IAttachment.ClipParticipants => ClipParticipants;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Discord.Rest
|
||||
{
|
||||
var attachments = ImmutableArray.CreateBuilder<Attachment>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
attachments.Add(Attachment.Create(value[i]));
|
||||
attachments.Add(Attachment.Create(value[i], Discord));
|
||||
_attachments = attachments.ToImmutable();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
foreach (var attachment in resolved.Attachments.Value)
|
||||
{
|
||||
var discordAttachment = Attachment.Create(attachment.Value);
|
||||
var discordAttachment = Attachment.Create(attachment.Value, discord);
|
||||
|
||||
Attachments.Add(ulong.Parse(attachment.Key), discordAttachment);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var attachments = ImmutableArray.CreateBuilder<Attachment>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
attachments.Add(Attachment.Create(value[i]));
|
||||
attachments.Add(Attachment.Create(value[i], Discord));
|
||||
_attachments = attachments.ToImmutable();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user