mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-28 20:23:42 +00:00
Add command line interface and change solution structure (#26)
This commit is contained in:
24
DiscordChatExporter.Core/Models/Attachment.cs
Normal file
24
DiscordChatExporter.Core/Models/Attachment.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
DiscordChatExporter.Core/Models/AttachmentType.cs
Normal file
8
DiscordChatExporter.Core/Models/AttachmentType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public enum AttachmentType
|
||||
{
|
||||
Other,
|
||||
Image
|
||||
}
|
||||
}
|
||||
37
DiscordChatExporter.Core/Models/Channel.cs
Normal file
37
DiscordChatExporter.Core/Models/Channel.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
DiscordChatExporter.Core/Models/ChannelChatLog.cs
Normal file
24
DiscordChatExporter.Core/Models/ChannelChatLog.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
DiscordChatExporter.Core/Models/ChannelType.cs
Normal file
11
DiscordChatExporter.Core/Models/ChannelType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public enum ChannelType
|
||||
{
|
||||
GuildTextChat,
|
||||
DirectTextChat,
|
||||
GuildVoiceChat,
|
||||
DirectGroupTextChat,
|
||||
Category
|
||||
}
|
||||
}
|
||||
9
DiscordChatExporter.Core/Models/ExportFormat.cs
Normal file
9
DiscordChatExporter.Core/Models/ExportFormat.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public enum ExportFormat
|
||||
{
|
||||
PlainText,
|
||||
HtmlDark,
|
||||
HtmlLight
|
||||
}
|
||||
}
|
||||
31
DiscordChatExporter.Core/Models/Extensions.cs
Normal file
31
DiscordChatExporter.Core/Models/Extensions.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
38
DiscordChatExporter.Core/Models/Guild.cs
Normal file
38
DiscordChatExporter.Core/Models/Guild.cs
Normal 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]);
|
||||
}
|
||||
}
|
||||
54
DiscordChatExporter.Core/Models/Message.cs
Normal file
54
DiscordChatExporter.Core/Models/Message.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
DiscordChatExporter.Core/Models/MessageGroup.cs
Normal file
21
DiscordChatExporter.Core/Models/MessageGroup.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
DiscordChatExporter.Core/Models/MessageType.cs
Normal file
14
DiscordChatExporter.Core/Models/MessageType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public enum MessageType
|
||||
{
|
||||
Default,
|
||||
RecipientAdd,
|
||||
RecipientRemove,
|
||||
Call,
|
||||
ChannelNameChange,
|
||||
ChannelIconChange,
|
||||
ChannelPinnedMessage,
|
||||
GuildMemberJoin
|
||||
}
|
||||
}
|
||||
28
DiscordChatExporter.Core/Models/Role.cs
Normal file
28
DiscordChatExporter.Core/Models/Role.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
34
DiscordChatExporter.Core/Models/User.cs
Normal file
34
DiscordChatExporter.Core/Models/User.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user