using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace EmojiTranslator {
public static class EmojiLib {
private static readonly HttpClient client = new HttpClient();
private static Dictionary<string, string> _emojis = new Dictionary<string, string>();
public static async Task LoadEmojisAsync(string apiKey) {
try {
var response = await client.GetStringAsync($"https://emoji-api.com/emojis?access_key={apiKey}");
var emojis = JsonConvert.DeserializeObject<List<Emoji>>(response);
_emojis.Clear();
foreach (var emoji in emojis) {
if (!string.IsNullOrEmpty(emoji.Character)) {
_emojis[emoji.Slug.ToLower()] = emoji.Character;
_emojis[emoji.UnicodeName.ToLower()] = emoji.Character;
}
}
Console.WriteLine($"Loaded {_emojis.Count} emojis.");
} catch (Exception ex) {
Console.WriteLine($"Error loading emojis: {ex.Message}");
_emojis["pizza"] = ":pizza:"; _emojis["computer"] = ":computer:"; _emojis["happy"] = ":blush:";
}
}
public static Dictionary<string, string> Emojis => _emojis;
public class Emoji {
[JsonProperty("slug")] public string Slug { get; set; }
[JsonProperty("character")] public string Character { get; set; }
[JsonProperty("unicodeName")] public string UnicodeName { get; set; }
}
}
}