mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-31 14:58:22 -04:00
parent
90c68e3cde
commit
b36071cddd
4 changed files with 41 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DiscordChatExporter.Core.Discord.Data.Common;
|
using DiscordChatExporter.Core.Discord.Data.Common;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
@ -14,6 +15,7 @@ public partial record Channel(
|
||||||
ChannelCategory Category,
|
ChannelCategory Category,
|
||||||
string Name,
|
string Name,
|
||||||
int? Position,
|
int? Position,
|
||||||
|
string? IconUrl,
|
||||||
string? Topic,
|
string? Topic,
|
||||||
Snowflake? LastMessageId) : IHasId
|
Snowflake? LastMessageId) : IHasId
|
||||||
{
|
{
|
||||||
|
@ -35,6 +37,15 @@ public partial record Channel
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private static string GetIconUrl(Snowflake id, string iconHash)
|
||||||
|
{
|
||||||
|
var extension = iconHash.StartsWith("a_", StringComparison.Ordinal)
|
||||||
|
? "gif"
|
||||||
|
: "png";
|
||||||
|
|
||||||
|
return $"https://cdn.discordapp.com/icons/{id}/{iconHash}.{extension}";
|
||||||
|
}
|
||||||
|
|
||||||
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? positionHint = null)
|
||||||
{
|
{
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
|
@ -59,6 +70,9 @@ public partial record Channel
|
||||||
positionHint ??
|
positionHint ??
|
||||||
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
json.GetPropertyOrNull("position")?.GetInt32OrNull();
|
||||||
|
|
||||||
|
// Only available on group DMs
|
||||||
|
var iconUrl = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull()?.Pipe(h => GetIconUrl(id, h));
|
||||||
|
|
||||||
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
||||||
|
|
||||||
var lastMessageId = json
|
var lastMessageId = json
|
||||||
|
@ -73,6 +87,7 @@ public partial record Channel
|
||||||
category ?? GetFallbackCategory(kind),
|
category ?? GetFallbackCategory(kind),
|
||||||
name,
|
name,
|
||||||
position,
|
position,
|
||||||
|
iconUrl,
|
||||||
topic,
|
topic,
|
||||||
lastMessageId
|
lastMessageId
|
||||||
);
|
);
|
||||||
|
|
|
@ -32,10 +32,9 @@ public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId
|
||||||
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
var id = json.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse);
|
||||||
var name = json.GetProperty("name").GetNonNullString();
|
var name = json.GetProperty("name").GetNonNullString();
|
||||||
|
|
||||||
var iconHash = json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull();
|
var iconUrl =
|
||||||
var iconUrl = !string.IsNullOrWhiteSpace(iconHash)
|
json.GetPropertyOrNull("icon")?.GetNonWhiteSpaceStringOrNull()?.Pipe(h => GetIconUrl(id, h)) ??
|
||||||
? GetIconUrl(id, iconHash)
|
GetDefaultIconUrl();
|
||||||
: GetDefaultIconUrl();
|
|
||||||
|
|
||||||
return new Guild(id, name, iconUrl);
|
return new Guild(id, name, iconUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,12 @@ internal class JsonMessageWriter : MessageWriter
|
||||||
_writer.WriteStartObject("guild");
|
_writer.WriteStartObject("guild");
|
||||||
_writer.WriteString("id", Context.Request.Guild.Id.ToString());
|
_writer.WriteString("id", Context.Request.Guild.Id.ToString());
|
||||||
_writer.WriteString("name", Context.Request.Guild.Name);
|
_writer.WriteString("name", Context.Request.Guild.Name);
|
||||||
_writer.WriteString("iconUrl", await Context.ResolveAssetUrlAsync(Context.Request.Guild.IconUrl, cancellationToken));
|
|
||||||
|
_writer.WriteString(
|
||||||
|
"iconUrl",
|
||||||
|
await Context.ResolveAssetUrlAsync(Context.Request.Guild.IconUrl, cancellationToken)
|
||||||
|
);
|
||||||
|
|
||||||
_writer.WriteEndObject();
|
_writer.WriteEndObject();
|
||||||
|
|
||||||
// Channel
|
// Channel
|
||||||
|
@ -255,6 +260,15 @@ internal class JsonMessageWriter : MessageWriter
|
||||||
_writer.WriteString("category", Context.Request.Channel.Category.Name);
|
_writer.WriteString("category", Context.Request.Channel.Category.Name);
|
||||||
_writer.WriteString("name", Context.Request.Channel.Name);
|
_writer.WriteString("name", Context.Request.Channel.Name);
|
||||||
_writer.WriteString("topic", Context.Request.Channel.Topic);
|
_writer.WriteString("topic", Context.Request.Channel.Topic);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(Context.Request.Channel.IconUrl))
|
||||||
|
{
|
||||||
|
_writer.WriteString(
|
||||||
|
"iconUrl",
|
||||||
|
await Context.ResolveAssetUrlAsync(Context.Request.Channel.IconUrl, cancellationToken)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_writer.WriteEndObject();
|
_writer.WriteEndObject();
|
||||||
|
|
||||||
// Date range
|
// Date range
|
||||||
|
@ -295,7 +309,12 @@ internal class JsonMessageWriter : MessageWriter
|
||||||
_writer.WriteString("nickname", Context.TryGetMember(message.Author.Id)?.Nick ?? message.Author.Name);
|
_writer.WriteString("nickname", Context.TryGetMember(message.Author.Id)?.Nick ?? message.Author.Name);
|
||||||
_writer.WriteString("color", Context.TryGetUserColor(message.Author.Id)?.ToHex());
|
_writer.WriteString("color", Context.TryGetUserColor(message.Author.Id)?.ToHex());
|
||||||
_writer.WriteBoolean("isBot", message.Author.IsBot);
|
_writer.WriteBoolean("isBot", message.Author.IsBot);
|
||||||
_writer.WriteString("avatarUrl", await Context.ResolveAssetUrlAsync(message.Author.AvatarUrl, cancellationToken));
|
|
||||||
|
_writer.WriteString(
|
||||||
|
"avatarUrl",
|
||||||
|
await Context.ResolveAssetUrlAsync(message.Author.AvatarUrl, cancellationToken)
|
||||||
|
);
|
||||||
|
|
||||||
_writer.WriteEndObject();
|
_writer.WriteEndObject();
|
||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
|
|
|
@ -851,7 +851,7 @@
|
||||||
|
|
||||||
<div class="preamble">
|
<div class="preamble">
|
||||||
<div class="preamble__guild-icon-container">
|
<div class="preamble__guild-icon-container">
|
||||||
<img class="preamble__guild-icon" src="@await ResolveAssetUrlAsync(ExportContext.Request.Guild.IconUrl)" alt="Guild icon" loading="lazy">
|
<img class="preamble__guild-icon" src="@await ResolveAssetUrlAsync(ExportContext.Request.Channel.IconUrl ?? ExportContext.Request.Guild.IconUrl)" alt="Guild icon" loading="lazy">
|
||||||
</div>
|
</div>
|
||||||
<div class="preamble__entries-container">
|
<div class="preamble__entries-container">
|
||||||
<div class="preamble__entry">@ExportContext.Request.Guild.Name</div>
|
<div class="preamble__entry">@ExportContext.Request.Guild.Name</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue