Add support for embeds (#46)

This commit is contained in:
Malcolm Diller
2018-05-06 03:09:25 -07:00
committed by Alexey Golub
parent 3b7da21c24
commit d958f613a3
17 changed files with 1117 additions and 228 deletions

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Drawing;
// https://discordapp.com/developers/docs/resources/channel#embed-object
namespace DiscordChatExporter.Core.Models
{
public class Embed : IMentionable
{
public string Title { get; }
public string Type { get; }
public string Description { get; }
public string Url { get; }
public DateTime? TimeStamp { get; }
public Color? Color { get; }
public EmbedFooter Footer { get; }
public EmbedImage Image { get; }
public EmbedImage Thumbnail { get; }
public EmbedVideo Video { get; }
public EmbedProvider Provider { get; }
public EmbedAuthor Author { get; }
public IReadOnlyList<EmbedField> Fields { get; }
public List<User> MentionedUsers { get; }
public List<Role> MentionedRoles { get; }
public List<Channel> MentionedChannels { get; }
public Embed(string title, string type, string description,
string url, DateTime? timeStamp, Color? color,
EmbedFooter footer, EmbedImage image, EmbedImage thumbnail,
EmbedVideo video, EmbedProvider provider, EmbedAuthor author,
List<EmbedField> fields, List<User> mentionedUsers,
List<Role> mentionedRoles, List<Channel> mentionedChannels)
{
Title = title;
Type = type;
Description = description;
Url = url;
TimeStamp = timeStamp;
Color = color;
Footer = footer;
Image = image;
Thumbnail = thumbnail;
Video = video;
Provider = provider;
Author = author;
Fields = fields;
MentionedUsers = mentionedUsers;
MentionedRoles = mentionedRoles;
MentionedChannels = mentionedChannels;
}
public override string ToString()
{
return Description;
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-author-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedAuthor
{
public string Name { get; }
public string Url { get; }
public string IconUrl { get; }
public string ProxyIconUrl { get; }
public EmbedAuthor(string name, string url, string iconUrl, string proxyIconUrl)
{
Name = name;
Url = url;
IconUrl = iconUrl;
ProxyIconUrl = proxyIconUrl;
}
public override string ToString()
{
return Name;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-field-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedField
{
public string Name { get; }
public string Value { get; }
public bool? Inline { get; }
public EmbedField(string name, string value, bool? inline)
{
Name = name;
Value = value;
Inline = inline;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-footer-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedFooter
{
public string Text { get; }
public string IconUrl { get; }
public string ProxyIconUrl { get; }
public EmbedFooter(string text, string iconUrl, string proxyIconUrl)
{
Text = text;
IconUrl = iconUrl;
ProxyIconUrl = proxyIconUrl;
}
public override string ToString()
{
return Text;
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-image-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedImage
{
public string Url { get; }
public string ProxyUrl { get; }
public int? Height { get; }
public int? Width { get; }
public EmbedImage(string url, string proxyUrl, int? height, int? width)
{
Url = url;
ProxyUrl = proxyUrl;
Height = height;
Width = width;
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-provider-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedProvider
{
public string Name { get; }
public string Url { get; }
public EmbedProvider(string name, string url)
{
Name = name;
Url = url;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
// https://discordapp.com/developers/docs/resources/channel#embed-object-embed-video-structure
namespace DiscordChatExporter.Core.Models
{
public class EmbedVideo
{
public string Url { get; }
public int? Height { get; }
public int? Width { get; }
public EmbedVideo(string url, int? height, int? width)
{
Url = url;
Height = height;
Width = width;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordChatExporter.Core.Models
{
interface IMentionable
{
List<User> MentionedUsers { get; }
List<Role> MentionedRoles { get; }
List<Channel> MentionedChannels { get; }
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace DiscordChatExporter.Core.Models
{
public class Message
public class Message : IMentionable
{
public string Id { get; }
@@ -21,17 +21,20 @@ namespace DiscordChatExporter.Core.Models
public IReadOnlyList<Attachment> Attachments { get; }
public IReadOnlyList<User> MentionedUsers { get; }
public IReadOnlyList<Embed> Embeds { get; }
public IReadOnlyList<Role> MentionedRoles { get; }
public List<User> MentionedUsers { get; }
public IReadOnlyList<Channel> MentionedChannels { get; }
public List<Role> MentionedRoles { get; }
public List<Channel> MentionedChannels { get; }
public Message(string id, string channelId, MessageType type,
User author, DateTime timeStamp,
DateTime? editedTimeStamp, string content,
IReadOnlyList<Attachment> attachments, IReadOnlyList<User> mentionedUsers,
IReadOnlyList<Role> mentionedRoles, IReadOnlyList<Channel> mentionedChannels)
IReadOnlyList<Attachment> attachments, IReadOnlyList<Embed> embeds,
List<User> mentionedUsers, List<Role> mentionedRoles,
List<Channel> mentionedChannels)
{
Id = id;
ChannelId = channelId;
@@ -41,6 +44,7 @@ namespace DiscordChatExporter.Core.Models
EditedTimeStamp = editedTimeStamp;
Content = content;
Attachments = attachments;
Embeds = embeds;
MentionedUsers = mentionedUsers;
MentionedRoles = mentionedRoles;
MentionedChannels = mentionedChannels;

View File

@@ -2,7 +2,7 @@
namespace DiscordChatExporter.Core.Models
{
public class User
public partial class User
{
public string Id { get; }
@@ -33,4 +33,12 @@ namespace DiscordChatExporter.Core.Models
return FullName;
}
}
public partial class User
{
public static User CreateUnknownUser(string id)
{
return new User(id, 0, "Unknown", null);
}
}
}