From d4eba75036e32d6dd24f06de1b656e7306923098 Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Mon, 19 Jul 2021 02:07:19 +0300 Subject: [PATCH] Normalize namings ("...Type" -> "...Kind") --- .../Commands/Base/TokenCommandBase.cs | 4 +- DiscordChatExporter.Core/Discord/AuthToken.cs | 10 ++--- .../{AuthTokenType.cs => AuthTokenKind.cs} | 2 +- .../Discord/Data/Channel.cs | 38 +++++++++---------- .../Data/{ChannelType.cs => ChannelKind.cs} | 2 +- .../Discord/Data/Message.cs | 28 +++++++------- .../Discord/DiscordClient.cs | 2 +- .../Exporting/Writers/JsonMessageWriter.cs | 4 +- .../ViewModels/RootViewModel.cs | 4 +- 9 files changed, 47 insertions(+), 47 deletions(-) rename DiscordChatExporter.Core/Discord/{AuthTokenType.cs => AuthTokenKind.cs} (73%) rename DiscordChatExporter.Core/Discord/Data/{ChannelType.cs => ChannelKind.cs} (93%) diff --git a/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs index 51c87ea..e75826b 100644 --- a/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs @@ -16,8 +16,8 @@ namespace DiscordChatExporter.Cli.Commands.Base private AuthToken GetAuthToken() => new( IsBotToken - ? AuthTokenType.Bot - : AuthTokenType.User, + ? AuthTokenKind.Bot + : AuthTokenKind.User, TokenValue ); diff --git a/DiscordChatExporter.Core/Discord/AuthToken.cs b/DiscordChatExporter.Core/Discord/AuthToken.cs index f8e8bd2..b8870f5 100644 --- a/DiscordChatExporter.Core/Discord/AuthToken.cs +++ b/DiscordChatExporter.Core/Discord/AuthToken.cs @@ -4,19 +4,19 @@ namespace DiscordChatExporter.Core.Discord { public class AuthToken { - public AuthTokenType Type { get; } + public AuthTokenKind Kind { get; } public string Value { get; } - public AuthToken(AuthTokenType type, string value) + public AuthToken(AuthTokenKind kind, string value) { - Type = type; + Kind = kind; Value = value; } - public AuthenticationHeaderValue GetAuthenticationHeader() => Type switch + public AuthenticationHeaderValue GetAuthenticationHeader() => Kind switch { - AuthTokenType.Bot => new AuthenticationHeaderValue("Bot", Value), + AuthTokenKind.Bot => new AuthenticationHeaderValue("Bot", Value), _ => new AuthenticationHeaderValue(Value) }; diff --git a/DiscordChatExporter.Core/Discord/AuthTokenType.cs b/DiscordChatExporter.Core/Discord/AuthTokenKind.cs similarity index 73% rename from DiscordChatExporter.Core/Discord/AuthTokenType.cs rename to DiscordChatExporter.Core/Discord/AuthTokenKind.cs index b52ff6f..301692b 100644 --- a/DiscordChatExporter.Core/Discord/AuthTokenType.cs +++ b/DiscordChatExporter.Core/Discord/AuthTokenKind.cs @@ -1,6 +1,6 @@ namespace DiscordChatExporter.Core.Discord { - public enum AuthTokenType + public enum AuthTokenKind { User, Bot diff --git a/DiscordChatExporter.Core/Discord/Data/Channel.cs b/DiscordChatExporter.Core/Discord/Data/Channel.cs index bb75ac8..58fb03e 100644 --- a/DiscordChatExporter.Core/Discord/Data/Channel.cs +++ b/DiscordChatExporter.Core/Discord/Data/Channel.cs @@ -12,14 +12,14 @@ namespace DiscordChatExporter.Core.Discord.Data { public Snowflake Id { get; } - public ChannelType Type { get; } + public ChannelKind Kind { get; } - public bool IsTextChannel => Type is - ChannelType.GuildTextChat or - ChannelType.DirectTextChat or - ChannelType.DirectGroupTextChat or - ChannelType.GuildNews or - ChannelType.GuildStore; + public bool IsTextChannel => Kind is + ChannelKind.GuildTextChat or + ChannelKind.DirectTextChat or + ChannelKind.DirectGroupTextChat or + ChannelKind.GuildNews or + ChannelKind.GuildStore; public bool IsVoiceChannel => !IsTextChannel; @@ -35,7 +35,7 @@ namespace DiscordChatExporter.Core.Discord.Data public Channel( Snowflake id, - ChannelType type, + ChannelKind kind, Snowflake guildId, ChannelCategory category, string name, @@ -43,7 +43,7 @@ namespace DiscordChatExporter.Core.Discord.Data string? topic) { Id = id; - Type = type; + Kind = kind; GuildId = guildId; Category = category; Name = name; @@ -56,15 +56,15 @@ namespace DiscordChatExporter.Core.Discord.Data public partial class Channel { - private static ChannelCategory GetFallbackCategory(ChannelType channelType) => new( + private static ChannelCategory GetFallbackCategory(ChannelKind channelKind) => new( Snowflake.Zero, - channelType switch + channelKind switch { - ChannelType.GuildTextChat => "Text", - ChannelType.DirectTextChat => "Private", - ChannelType.DirectGroupTextChat => "Group", - ChannelType.GuildNews => "News", - ChannelType.GuildStore => "Store", + ChannelKind.GuildTextChat => "Text", + ChannelKind.DirectTextChat => "Private", + ChannelKind.DirectGroupTextChat => "Group", + ChannelKind.GuildNews => "News", + ChannelKind.GuildStore => "Store", _ => "Default" }, null @@ -75,7 +75,7 @@ namespace DiscordChatExporter.Core.Discord.Data var id = json.GetProperty("id").GetString().Pipe(Snowflake.Parse); var guildId = json.GetPropertyOrNull("guild_id")?.GetString().Pipe(Snowflake.Parse); var topic = json.GetPropertyOrNull("topic")?.GetString(); - var type = (ChannelType) json.GetProperty("type").GetInt32(); + var kind = (ChannelKind) json.GetProperty("type").GetInt32(); var name = // Guild channel @@ -87,9 +87,9 @@ namespace DiscordChatExporter.Core.Discord.Data return new Channel( id, - type, + kind, guildId ?? Guild.DirectMessages.Id, - category ?? GetFallbackCategory(type), + category ?? GetFallbackCategory(kind), name, position ?? json.GetPropertyOrNull("position")?.GetInt32(), topic diff --git a/DiscordChatExporter.Core/Discord/Data/ChannelType.cs b/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs similarity index 93% rename from DiscordChatExporter.Core/Discord/Data/ChannelType.cs rename to DiscordChatExporter.Core/Discord/Data/ChannelKind.cs index 18ac9ff..38d6fbc 100644 --- a/DiscordChatExporter.Core/Discord/Data/ChannelType.cs +++ b/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs @@ -2,7 +2,7 @@ { // https://discord.com/developers/docs/resources/channel#channel-object-channel-types // Order of enum fields needs to match the order in the docs. - public enum ChannelType + public enum ChannelKind { GuildTextChat = 0, DirectTextChat, diff --git a/DiscordChatExporter.Core/Discord/Data/Message.cs b/DiscordChatExporter.Core/Discord/Data/Message.cs index fcff27a..667ae45 100644 --- a/DiscordChatExporter.Core/Discord/Data/Message.cs +++ b/DiscordChatExporter.Core/Discord/Data/Message.cs @@ -9,7 +9,7 @@ using JsonExtensions.Reading; namespace DiscordChatExporter.Core.Discord.Data { // https://discord.com/developers/docs/resources/channel#message-object-message-types - public enum MessageType + public enum MessageKind { Default = 0, RecipientAdd = 1, @@ -27,7 +27,7 @@ namespace DiscordChatExporter.Core.Discord.Data { public Snowflake Id { get; } - public MessageType Type { get; } + public MessageKind Kind { get; } public User Author { get; } @@ -55,7 +55,7 @@ namespace DiscordChatExporter.Core.Discord.Data public Message( Snowflake id, - MessageType type, + MessageKind kind, User author, DateTimeOffset timestamp, DateTimeOffset? editedTimestamp, @@ -70,7 +70,7 @@ namespace DiscordChatExporter.Core.Discord.Data Message? referencedMessage) { Id = id; - Type = type; + Kind = kind; Author = author; Timestamp = timestamp; EditedTimestamp = editedTimestamp; @@ -97,21 +97,21 @@ namespace DiscordChatExporter.Core.Discord.Data var timestamp = json.GetProperty("timestamp").GetDateTimeOffset(); var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset(); var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")?.GetDateTimeOffset(); - var type = (MessageType) json.GetProperty("type").GetInt32(); + var kind = (MessageKind) json.GetProperty("type").GetInt32(); var isPinned = json.GetPropertyOrNull("pinned")?.GetBoolean() ?? false; var messageReference = json.GetPropertyOrNull("message_reference")?.Pipe(MessageReference.Parse); var referencedMessage = json.GetPropertyOrNull("referenced_message")?.Pipe(Parse); - var content = type switch + var content = kind switch { - MessageType.RecipientAdd => "Added a recipient.", - MessageType.RecipientRemove => "Removed a recipient.", - MessageType.Call => + MessageKind.RecipientAdd => "Added a recipient.", + MessageKind.RecipientRemove => "Removed a recipient.", + MessageKind.Call => $"Started a call that lasted {callEndedTimestamp?.Pipe(t => t - timestamp).Pipe(t => (int) t.TotalMinutes) ?? 0} minutes.", - MessageType.ChannelNameChange => "Changed the channel name.", - MessageType.ChannelIconChange => "Changed the channel icon.", - MessageType.ChannelPinnedMessage => "Pinned a message.", - MessageType.GuildMemberJoin => "Joined the server.", + MessageKind.ChannelNameChange => "Changed the channel name.", + MessageKind.ChannelIconChange => "Changed the channel icon.", + MessageKind.ChannelPinnedMessage => "Pinned a message.", + MessageKind.GuildMemberJoin => "Joined the server.", _ => json.GetPropertyOrNull("content")?.GetString() ?? "" }; @@ -133,7 +133,7 @@ namespace DiscordChatExporter.Core.Discord.Data return new Message( id, - type, + kind, author, timestamp, editedTimestamp, diff --git a/DiscordChatExporter.Core/Discord/DiscordClient.cs b/DiscordChatExporter.Core/Discord/DiscordClient.cs index 7fbb11f..3b4ddb3 100644 --- a/DiscordChatExporter.Core/Discord/DiscordClient.cs +++ b/DiscordChatExporter.Core/Discord/DiscordClient.cs @@ -126,7 +126,7 @@ namespace DiscordChatExporter.Core.Discord .ToArray(); var categories = responseOrdered - .Where(j => j.GetProperty("type").GetInt32() == (int) ChannelType.GuildCategory) + .Where(j => j.GetProperty("type").GetInt32() == (int) ChannelKind.GuildCategory) .Select((j, index) => ChannelCategory.Parse(j, index + 1)) .ToDictionary(j => j.Id.ToString(), StringComparer.Ordinal); diff --git a/DiscordChatExporter.Core/Exporting/Writers/JsonMessageWriter.cs b/DiscordChatExporter.Core/Exporting/Writers/JsonMessageWriter.cs index 6a259d1..8ea1427 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/JsonMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/Writers/JsonMessageWriter.cs @@ -192,7 +192,7 @@ namespace DiscordChatExporter.Core.Exporting.Writers // Channel _writer.WriteStartObject("channel"); _writer.WriteString("id", Context.Request.Channel.Id.ToString()); - _writer.WriteString("type", Context.Request.Channel.Type.ToString()); + _writer.WriteString("type", Context.Request.Channel.Kind.ToString()); _writer.WriteString("categoryId", Context.Request.Channel.Category.Id.ToString()); _writer.WriteString("category", Context.Request.Channel.Category.Name); _writer.WriteString("name", Context.Request.Channel.Name); @@ -218,7 +218,7 @@ namespace DiscordChatExporter.Core.Exporting.Writers // Metadata _writer.WriteString("id", message.Id.ToString()); - _writer.WriteString("type", message.Type.ToString()); + _writer.WriteString("type", message.Kind.ToString()); _writer.WriteString("timestamp", message.Timestamp); _writer.WriteString("timestampEdited", message.EditedTimestamp); _writer.WriteString("callEndedTimestamp", message.CallEndedTimestamp); diff --git a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs index 4dcf201..57968e5 100644 --- a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs @@ -111,7 +111,7 @@ namespace DiscordChatExporter.Gui.ViewModels if (_settingsService.LastToken is not null) { - IsBotToken = _settingsService.LastToken.Type == AuthTokenType.Bot; + IsBotToken = _settingsService.LastToken.Kind == AuthTokenKind.Bot; TokenValue = _settingsService.LastToken.Value; } @@ -157,7 +157,7 @@ namespace DiscordChatExporter.Gui.ViewModels return; var token = new AuthToken( - IsBotToken ? AuthTokenType.Bot : AuthTokenType.User, + IsBotToken ? AuthTokenKind.Bot : AuthTokenKind.User, tokenValue );