/
Attachment.cs
104 lines (94 loc) · 3.85 KB
/
Attachment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
{
/// <inheritdoc cref="IAttachment"/>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class Attachment : IAttachment
{
/// <inheritdoc />
public ulong Id { get; }
/// <inheritdoc />
public string Filename { get; }
/// <inheritdoc />
public string Url { get; }
/// <inheritdoc />
public string ProxyUrl { get; }
/// <inheritdoc />
public int Size { get; }
/// <inheritdoc />
public int? Height { get; }
/// <inheritdoc />
public int? Width { get; }
/// <inheritdoc />
public bool Ephemeral { get; }
/// <inheritdoc />
public string Description { get; }
/// <inheritdoc />
public string ContentType { get; }
/// <inheritdoc />
public string Waveform { get; }
/// <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, string title,
IReadOnlyCollection<RestUser> clipParticipants, DateTimeOffset? clipCreatedAt)
{
Id = id;
Filename = filename;
Url = url;
ProxyUrl = proxyUrl;
Size = size;
Height = height;
Width = width;
Ephemeral = ephemeral.GetValueOrDefault(false);
Description = description;
ContentType = contentType;
Duration = duration;
Waveform = waveform;
Flags = flags;
Title = title;
ClipParticipants = clipParticipants;
ClipCreatedAt = clipCreatedAt;
}
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 : 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.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>
/// <returns>
/// A string containing the filename of this attachment.
/// </returns>
public override string ToString() => Filename;
private string DebuggerDisplay => $"{Filename} ({Size} bytes)";
/// <inheritdoc />
IReadOnlyCollection<IUser> IAttachment.ClipParticipants => ClipParticipants;
}
}