|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using DiscordChatExporter.Core.Discord.Data.Common;
|
|
|
|
@ -11,73 +10,21 @@ using JsonExtensions.Reading;
|
|
|
|
|
namespace DiscordChatExporter.Core.Discord.Data
|
|
|
|
|
{
|
|
|
|
|
// https://discord.com/developers/docs/resources/channel#message-object
|
|
|
|
|
public partial class Message : IHasId
|
|
|
|
|
{
|
|
|
|
|
public Snowflake Id { get; }
|
|
|
|
|
|
|
|
|
|
public MessageKind Kind { get; }
|
|
|
|
|
|
|
|
|
|
public User Author { get; }
|
|
|
|
|
|
|
|
|
|
public DateTimeOffset Timestamp { get; }
|
|
|
|
|
|
|
|
|
|
public DateTimeOffset? EditedTimestamp { get; }
|
|
|
|
|
|
|
|
|
|
public DateTimeOffset? CallEndedTimestamp { get; }
|
|
|
|
|
|
|
|
|
|
public bool IsPinned { get; }
|
|
|
|
|
|
|
|
|
|
public string Content { get; }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<Attachment> Attachments { get; }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<Embed> Embeds { get; }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<Reaction> Reactions { get; }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<User> MentionedUsers { get; }
|
|
|
|
|
|
|
|
|
|
public MessageReference? Reference { get; }
|
|
|
|
|
|
|
|
|
|
public Message? ReferencedMessage { get; }
|
|
|
|
|
|
|
|
|
|
public Message(
|
|
|
|
|
Snowflake id,
|
|
|
|
|
MessageKind kind,
|
|
|
|
|
User author,
|
|
|
|
|
DateTimeOffset timestamp,
|
|
|
|
|
DateTimeOffset? editedTimestamp,
|
|
|
|
|
DateTimeOffset? callEndedTimestamp,
|
|
|
|
|
bool isPinned,
|
|
|
|
|
string content,
|
|
|
|
|
IReadOnlyList<Attachment> attachments,
|
|
|
|
|
IReadOnlyList<Embed> embeds,
|
|
|
|
|
IReadOnlyList<Reaction> reactions,
|
|
|
|
|
IReadOnlyList<User> mentionedUsers,
|
|
|
|
|
MessageReference? messageReference,
|
|
|
|
|
Message? referencedMessage)
|
|
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
Kind = kind;
|
|
|
|
|
Author = author;
|
|
|
|
|
Timestamp = timestamp;
|
|
|
|
|
EditedTimestamp = editedTimestamp;
|
|
|
|
|
CallEndedTimestamp = callEndedTimestamp;
|
|
|
|
|
IsPinned = isPinned;
|
|
|
|
|
Content = content;
|
|
|
|
|
Attachments = attachments;
|
|
|
|
|
Embeds = embeds;
|
|
|
|
|
Reactions = reactions;
|
|
|
|
|
MentionedUsers = mentionedUsers;
|
|
|
|
|
Reference = messageReference;
|
|
|
|
|
ReferencedMessage = referencedMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ExcludeFromCodeCoverage]
|
|
|
|
|
public override string ToString() => Content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class Message
|
|
|
|
|
public record Message(
|
|
|
|
|
Snowflake Id,
|
|
|
|
|
MessageKind Kind,
|
|
|
|
|
User Author,
|
|
|
|
|
DateTimeOffset Timestamp,
|
|
|
|
|
DateTimeOffset? EditedTimestamp,
|
|
|
|
|
DateTimeOffset? CallEndedTimestamp,
|
|
|
|
|
bool IsPinned,
|
|
|
|
|
string Content,
|
|
|
|
|
IReadOnlyList<Attachment> Attachments,
|
|
|
|
|
IReadOnlyList<Embed> Embeds,
|
|
|
|
|
IReadOnlyList<Reaction> Reactions,
|
|
|
|
|
IReadOnlyList<User> MentionedUsers,
|
|
|
|
|
MessageReference? Reference,
|
|
|
|
|
Message? ReferencedMessage) : IHasId
|
|
|
|
|
{
|
|
|
|
|
public static Message Parse(JsonElement json)
|
|
|
|
|
{
|
|
|
|
@ -85,8 +32,9 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|
|
|
|
var author = json.GetProperty("author").Pipe(User.Parse);
|
|
|
|
|
var timestamp = json.GetProperty("timestamp").GetDateTimeOffset();
|
|
|
|
|
var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset();
|
|
|
|
|
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")?.GetDateTimeOffset();
|
|
|
|
|
var kind = (MessageKind) json.GetProperty("type").GetInt32();
|
|
|
|
|
var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")
|
|
|
|
|
?.GetDateTimeOffset();
|
|
|
|
|
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);
|
|
|
|
@ -96,7 +44,7 @@ namespace DiscordChatExporter.Core.Discord.Data
|
|
|
|
|
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.",
|
|
|
|
|
$"Started a call that lasted {callEndedTimestamp?.Pipe(t => t - timestamp).Pipe(t => (int)t.TotalMinutes) ?? 0} minutes.",
|
|
|
|
|
MessageKind.ChannelNameChange => "Changed the channel name.",
|
|
|
|
|
MessageKind.ChannelIconChange => "Changed the channel icon.",
|
|
|
|
|
MessageKind.ChannelPinnedMessage => "Pinned a message.",
|
|
|
|
|