From f8dae724118a82154442943f1b21ed418a61a8c9 Mon Sep 17 00:00:00 2001 From: Oleksii Holub Date: Thu, 9 Nov 2017 17:57:32 +0200 Subject: [PATCH] Refactor --- DiscordChatExporter/Models/Channel.cs | 10 +++++++++- DiscordChatExporter/Models/Role.cs | 10 +++++++++- DiscordChatExporter/Services/DataService.cs | 5 ++--- DiscordChatExporter/Services/ExportService.cs | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/DiscordChatExporter/Models/Channel.cs b/DiscordChatExporter/Models/Channel.cs index ff1b190..43568d1 100644 --- a/DiscordChatExporter/Models/Channel.cs +++ b/DiscordChatExporter/Models/Channel.cs @@ -1,6 +1,6 @@ namespace DiscordChatExporter.Models { - public class Channel + public partial class Channel { public string Id { get; } @@ -23,4 +23,12 @@ return Name; } } + + public partial class Channel + { + public static Channel CreateDeletedChannel(string id) + { + return new Channel(id, "deleted-channel", null, ChannelType.GuildTextChat); + } + } } \ No newline at end of file diff --git a/DiscordChatExporter/Models/Role.cs b/DiscordChatExporter/Models/Role.cs index a714f5e..55b031c 100644 --- a/DiscordChatExporter/Models/Role.cs +++ b/DiscordChatExporter/Models/Role.cs @@ -1,6 +1,6 @@ namespace DiscordChatExporter.Models { - public class Role + public partial class Role { public string Id { get; } @@ -17,4 +17,12 @@ return Name; } } + + public partial class Role + { + public static Role CreateDeletedRole(string id) + { + return new Role(id, "deleted-role"); + } + } } \ No newline at end of file diff --git a/DiscordChatExporter/Services/DataService.cs b/DiscordChatExporter/Services/DataService.cs index 578544e..2597fe7 100644 --- a/DiscordChatExporter/Services/DataService.cs +++ b/DiscordChatExporter/Services/DataService.cs @@ -121,7 +121,7 @@ namespace DiscordChatExporter.Services // Get role mentions var mentionedRoles = token["mention_roles"] .Values() - .Select(i => _roleCache.GetOrDefault(i) ?? new Role(i, "deleted-role")) + .Select(i => _roleCache.GetOrDefault(i) ?? Role.CreateDeletedRole(id)) .ToArray(); // Get channel mentions @@ -129,8 +129,7 @@ namespace DiscordChatExporter.Services .Cast() .Select(m => m.Groups[1].Value) .ExceptBlank() - .Select(i => _channelCache.GetOrDefault(i) ?? - new Channel(i, "deleted-channel", null, ChannelType.GuildTextChat)) + .Select(i => _channelCache.GetOrDefault(i) ?? Channel.CreateDeletedChannel(id)) .ToArray(); return new Message(id, type, author, timeStamp, editedTimeStamp, content, attachments, diff --git a/DiscordChatExporter/Services/ExportService.cs b/DiscordChatExporter/Services/ExportService.cs index 43200ad..67e8e69 100644 --- a/DiscordChatExporter/Services/ExportService.cs +++ b/DiscordChatExporter/Services/ExportService.cs @@ -188,7 +188,7 @@ namespace DiscordChatExporter.Services return ExportAsHtmlAsync(filePath, log, css); } - throw new NotImplementedException(); + throw new ArgumentOutOfRangeException(nameof(format)); } }