Normalize namings ("...Type" -> "...Kind")

pull/678/head
Tyrrrz 3 years ago
parent de773467b6
commit d4eba75036

@ -16,8 +16,8 @@ namespace DiscordChatExporter.Cli.Commands.Base
private AuthToken GetAuthToken() => new(
IsBotToken
? AuthTokenType.Bot
: AuthTokenType.User,
? AuthTokenKind.Bot
: AuthTokenKind.User,
TokenValue
);

@ -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)
};

@ -1,6 +1,6 @@
namespace DiscordChatExporter.Core.Discord
{
public enum AuthTokenType
public enum AuthTokenKind
{
User,
Bot

@ -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

@ -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,

@ -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,

@ -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);

@ -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);

@ -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
);

Loading…
Cancel
Save