/
Embed.cs
76 lines (71 loc) · 2.52 KB
/
Embed.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
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
namespace Discord
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class Embed : IEmbed
{
public EmbedType Type { get; }
public string Description { get; internal set; }
public string Url { get; internal set; }
public string Title { get; internal set; }
public DateTimeOffset? Timestamp { get; internal set; }
public Color? Color { get; internal set; }
public EmbedImage? Image { get; internal set; }
public EmbedVideo? Video { get; internal set; }
public EmbedAuthor? Author { get; internal set; }
public EmbedFooter? Footer { get; internal set; }
public EmbedProvider? Provider { get; internal set; }
public EmbedThumbnail? Thumbnail { get; internal set; }
public ImmutableArray<EmbedField> Fields { get; internal set; }
internal Embed(EmbedType type)
{
Type = type;
Fields = ImmutableArray.Create<EmbedField>();
}
internal Embed(EmbedType type,
string title,
string description,
string url,
DateTimeOffset? timestamp,
Color? color,
EmbedImage? image,
EmbedVideo? video,
EmbedAuthor? author,
EmbedFooter? footer,
EmbedProvider? provider,
EmbedThumbnail? thumbnail,
ImmutableArray<EmbedField> fields)
{
Type = type;
Title = title;
Description = description;
Url = url;
Color = color;
Timestamp = timestamp;
Image = image;
Video = video;
Author = author;
Footer = footer;
Provider = provider;
Thumbnail = thumbnail;
Fields = fields;
}
public int Length
{
get
{
int titleLength = Title?.Length ?? 0;
int authorLength = Author?.Name?.Length ?? 0;
int descriptionLength = Description?.Length ?? 0;
int footerLength = Footer?.Text?.Length ?? 0;
int fieldSum = Fields.Sum(f => f.Name?.Length + f.Value?.ToString().Length) ?? 0;
return titleLength + authorLength + descriptionLength + footerLength + fieldSum;
}
}
public override string ToString() => Title;
private string DebuggerDisplay => $"{Title} ({Type})";
}
}