mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-24 19:54:22 -04:00
Refactor reaction emojis into a separate class, add support for animations and standard emojis via twemoji
Closes #71
This commit is contained in:
parent
f09f30c7bd
commit
847a05a269
3 changed files with 47 additions and 13 deletions
43
DiscordChatExporter.Core/Models/Emoji.cs
Normal file
43
DiscordChatExporter.Core/Models/Emoji.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using Tyrrrz.Extensions;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Models
|
||||||
|
{
|
||||||
|
// https://discordapp.com/developers/docs/resources/emoji#emoji-object
|
||||||
|
|
||||||
|
public class Emoji
|
||||||
|
{
|
||||||
|
public string Id { get; }
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
public bool IsAnimated { get; }
|
||||||
|
|
||||||
|
public string ImageUrl
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Custom emoji
|
||||||
|
if (Id.IsNotBlank())
|
||||||
|
{
|
||||||
|
// Animated
|
||||||
|
if (IsAnimated)
|
||||||
|
return $"https://cdn.discordapp.com/emojis/{Id}.gif";
|
||||||
|
|
||||||
|
// Non-animated
|
||||||
|
return $"https://cdn.discordapp.com/emojis/{Id}.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard unicode emoji (via twemoji)
|
||||||
|
var codePoint = char.ConvertToUtf32(Name, 0).ToString("x");
|
||||||
|
return $"https://twemoji.maxcdn.com/2/72x72/{codePoint}.png";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Emoji(string id, string name, bool isAnimated)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
IsAnimated = isAnimated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,15 +6,12 @@
|
||||||
{
|
{
|
||||||
public int Count { get; }
|
public int Count { get; }
|
||||||
|
|
||||||
public string EmojiId { get; }
|
public Emoji Emoji { get; }
|
||||||
|
|
||||||
public string EmojiName { get; }
|
public Reaction(int count, Emoji emoji)
|
||||||
|
|
||||||
public Reaction(int count, string emojiId, string emojiName)
|
|
||||||
{
|
{
|
||||||
Count = count;
|
Count = count;
|
||||||
EmojiId = emojiId;
|
Emoji = emoji;
|
||||||
EmojiName = emojiName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -196,13 +196,7 @@
|
||||||
{{~ for reaction in message.Reactions ~}}
|
{{~ for reaction in message.Reactions ~}}
|
||||||
<div class="chatlog__reaction">
|
<div class="chatlog__reaction">
|
||||||
<span class="chatlog__reaction-emoji">
|
<span class="chatlog__reaction-emoji">
|
||||||
{{~ # Custom emoji ~}}
|
<img class="emoji emoji--small" title="{{ reaction.Emoji.Name }}" src="{{ reaction.Emoji.ImageUrl }}" />
|
||||||
{{~ if reaction.EmojiId ~}}
|
|
||||||
<img class="emoji emoji--small" title="{{ reaction.EmojiName }}" src="https://cdn.discordapp.com/emojis/{{ reaction.EmojiId }}.png" />
|
|
||||||
{{~ # Default emoji ~}}
|
|
||||||
{{~ else ~}}
|
|
||||||
{{ reaction.EmojiName }}
|
|
||||||
{{~ end ~}}
|
|
||||||
</span>
|
</span>
|
||||||
<span class="chatlog__reaction-count">{{ reaction.Count }}</span>
|
<span class="chatlog__reaction-count">{{ reaction.Count }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue