Skip to content

Commit

Permalink
Add support for gif stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Nov 29, 2023
1 parent cfbbc4b commit d0873ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion DiscordChatExporter.Core/Discord/Data/Sticker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
namespace DiscordChatExporter.Core.Discord.Data;

// https://discord.com/developers/docs/resources/sticker#sticker-resource
public record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
public partial record Sticker(Snowflake Id, string Name, StickerFormat Format, string SourceUrl)
{
public bool IsImage => Format != StickerFormat.Lottie;
}

public partial record Sticker
{
public static Sticker Parse(JsonElement json)
{
Expand All @@ -22,6 +27,7 @@ public static Sticker Parse(JsonElement json)
StickerFormat.Png => "png",
StickerFormat.Apng => "png",
StickerFormat.Lottie => "json",
StickerFormat.Gif => "gif",
_ => throw new InvalidOperationException($"Unknown sticker format '{format}'.")
}
);
Expand Down
3 changes: 2 additions & 1 deletion DiscordChatExporter.Core/Discord/Data/StickerFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum StickerFormat
{
Png = 1,
Apng = 2,
Lottie = 3
Lottie = 3,
Gif = 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
@foreach (var sticker in message.Stickers)
{
<div class="chatlog__sticker" title="@sticker.Name">
@if (sticker.Format is StickerFormat.Png or StickerFormat.Apng)
@if (sticker.IsImage)
{
<img class="chatlog__sticker--media" src="@await ResolveAssetUrlAsync(sticker.SourceUrl)" alt="Sticker">
}
Expand Down

0 comments on commit d0873ec

Please sign in to comment.