Add command line interface and change solution structure (#26)

This commit is contained in:
Alexey Golub
2018-01-12 20:28:36 +01:00
committed by GitHub
parent 7da82f9ef4
commit 8515efe11b
73 changed files with 489 additions and 199 deletions

View File

@@ -0,0 +1,24 @@
namespace DiscordChatExporter.Core.Models
{
public class Attachment
{
public string Id { get; }
public AttachmentType Type { get; }
public string Url { get; }
public string FileName { get; }
public long FileSize { get; }
public Attachment(string id, AttachmentType type, string url, string fileName, long fileSize)
{
Id = id;
Type = type;
Url = url;
FileName = fileName;
FileSize = fileSize;
}
}
}

View File

@@ -0,0 +1,8 @@
namespace DiscordChatExporter.Core.Models
{
public enum AttachmentType
{
Other,
Image
}
}

View File

@@ -0,0 +1,37 @@
namespace DiscordChatExporter.Core.Models
{
public partial class Channel
{
public string Id { get; }
public string GuildId { get; }
public string Name { get; }
public string Topic { get; }
public ChannelType Type { get; }
public Channel(string id, string guildId, string name, string topic, ChannelType type)
{
Id = id;
GuildId = guildId;
Name = name;
Topic = topic;
Type = type;
}
public override string ToString()
{
return Name;
}
}
public partial class Channel
{
public static Channel CreateDeletedChannel(string id)
{
return new Channel(id, null, "deleted-channel", null, ChannelType.GuildTextChat);
}
}
}

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Models
{
public class ChannelChatLog
{
public Guild Guild { get; }
public Channel Channel { get; }
public IReadOnlyList<MessageGroup> MessageGroups { get; }
public int TotalMessageCount { get; }
public ChannelChatLog(Guild guild, Channel channel, IReadOnlyList<MessageGroup> messageGroups,
int totalMessageCount)
{
Guild = guild;
Channel = channel;
MessageGroups = messageGroups;
TotalMessageCount = totalMessageCount;
}
}
}

View File

@@ -0,0 +1,11 @@
namespace DiscordChatExporter.Core.Models
{
public enum ChannelType
{
GuildTextChat,
DirectTextChat,
GuildVoiceChat,
DirectGroupTextChat,
Category
}
}

View File

@@ -0,0 +1,9 @@
namespace DiscordChatExporter.Core.Models
{
public enum ExportFormat
{
PlainText,
HtmlDark,
HtmlLight
}
}

View File

@@ -0,0 +1,31 @@
using System;
namespace DiscordChatExporter.Core.Models
{
public static class Extensions
{
public static string GetFileExtension(this ExportFormat format)
{
if (format == ExportFormat.PlainText)
return "txt";
if (format == ExportFormat.HtmlDark)
return "html";
if (format == ExportFormat.HtmlLight)
return "html";
throw new ArgumentOutOfRangeException(nameof(format));
}
public static string GetDisplayName(this ExportFormat format)
{
if (format == ExportFormat.PlainText)
return "Plain Text";
if (format == ExportFormat.HtmlDark)
return "HTML (Dark)";
if (format == ExportFormat.HtmlLight)
return "HTML (Light)";
throw new ArgumentOutOfRangeException(nameof(format));
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Models
{
public partial class Guild
{
public string Id { get; }
public string Name { get; }
public string IconHash { get; }
public string IconUrl => IconHash.IsNotBlank()
? $"https://cdn.discordapp.com/icons/{Id}/{IconHash}.png"
: "https://cdn.discordapp.com/embed/avatars/0.png";
public IReadOnlyList<Role> Roles { get; }
public Guild(string id, string name, string iconHash, IReadOnlyList<Role> roles)
{
Id = id;
Name = name;
IconHash = iconHash;
Roles = roles;
}
public override string ToString()
{
return Name;
}
}
public partial class Guild
{
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", null, new Role[0]);
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Models
{
public class Message
{
public string Id { get; }
public string ChannelId { get; }
public MessageType Type { get; }
public User Author { get; }
public DateTime TimeStamp { get; }
public DateTime? EditedTimeStamp { get; }
public string Content { get; }
public IReadOnlyList<Attachment> Attachments { get; }
public IReadOnlyList<User> MentionedUsers { get; }
public IReadOnlyList<Role> MentionedRoles { get; }
public IReadOnlyList<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)
{
Id = id;
ChannelId = channelId;
Type = type;
Author = author;
TimeStamp = timeStamp;
EditedTimeStamp = editedTimeStamp;
Content = content;
Attachments = attachments;
MentionedUsers = mentionedUsers;
MentionedRoles = mentionedRoles;
MentionedChannels = mentionedChannels;
}
public override string ToString()
{
return Content;
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Models
{
public class MessageGroup
{
public User Author { get; }
public DateTime TimeStamp { get; }
public IReadOnlyList<Message> Messages { get; }
public MessageGroup(User author, DateTime timeStamp, IReadOnlyList<Message> messages)
{
Author = author;
TimeStamp = timeStamp;
Messages = messages;
}
}
}

View File

@@ -0,0 +1,14 @@
namespace DiscordChatExporter.Core.Models
{
public enum MessageType
{
Default,
RecipientAdd,
RecipientRemove,
Call,
ChannelNameChange,
ChannelIconChange,
ChannelPinnedMessage,
GuildMemberJoin
}
}

View File

@@ -0,0 +1,28 @@
namespace DiscordChatExporter.Core.Models
{
public partial class Role
{
public string Id { get; }
public string Name { get; }
public Role(string id, string name)
{
Id = id;
Name = name;
}
public override string ToString()
{
return Name;
}
}
public partial class Role
{
public static Role CreateDeletedRole(string id)
{
return new Role(id, "deleted-role");
}
}
}

View File

@@ -0,0 +1,34 @@
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Models
{
public class User
{
public string Id { get; }
public int Discriminator { get; }
public string Name { get; }
public string FullyQualifiedName => $"{Name}#{Discriminator:0000}";
public string AvatarHash { get; }
public string AvatarUrl => AvatarHash.IsNotBlank()
? $"https://cdn.discordapp.com/avatars/{Id}/{AvatarHash}.png"
: $"https://cdn.discordapp.com/embed/avatars/{Discriminator % 5}.png";
public User(string id, int discriminator, string name, string avatarHash)
{
Id = id;
Discriminator = discriminator;
Name = name;
AvatarHash = avatarHash;
}
public override string ToString()
{
return FullyQualifiedName;
}
}
}