48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using DSharpPlus;
|
|
using DSharpPlus.Entities;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace T3k3rg0.Helpers
|
|
{
|
|
public static class EmojiExtractor
|
|
{
|
|
public static async Task<DiscordEmoji?> ExtractAsync(string emojInput, DiscordClient client)
|
|
{
|
|
try
|
|
{
|
|
var unicodeEmoji = DiscordEmoji.FromUnicode(emojInput);
|
|
return unicodeEmoji;
|
|
}
|
|
catch { }
|
|
|
|
try
|
|
{
|
|
var namedEmoji = DiscordEmoji.FromName(client, emojInput);
|
|
return namedEmoji;
|
|
}
|
|
catch { }
|
|
|
|
try
|
|
{
|
|
ulong emojiId;
|
|
|
|
// Ha teljes emojiformátumban van (pl. <:nev:123456789012345678>)
|
|
var match = System.Text.RegularExpressions.Regex.Match(emojInput, @"<a?:\w+:(\d{17,20})>");
|
|
if (match.Success && ulong.TryParse(match.Groups[1].Value, out emojiId))
|
|
{
|
|
return DiscordEmoji.FromGuildEmote(client, emojiId);
|
|
}
|
|
|
|
// Ha csak simán az ID-t írta be
|
|
if (ulong.TryParse(emojInput, out emojiId))
|
|
{
|
|
return DiscordEmoji.FromGuildEmote(client, emojiId);
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|