mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-19 21:31:28 +00:00
Refactor reaction emojis into a separate class, add support for animations and standard emojis via twemoji
Closes #71
This commit is contained in:
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 string EmojiId { get; }
|
||||
public Emoji Emoji { get; }
|
||||
|
||||
public string EmojiName { get; }
|
||||
|
||||
public Reaction(int count, string emojiId, string emojiName)
|
||||
public Reaction(int count, Emoji emoji)
|
||||
{
|
||||
Count = count;
|
||||
EmojiId = emojiId;
|
||||
EmojiName = emojiName;
|
||||
Emoji = emoji;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user