Add Support for emoji flags in the emoji converter
This commit is contained in:
parent
4fd62e9184
commit
bbb9b89422
2 changed files with 107 additions and 60 deletions
|
@ -1,17 +1,12 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Geekbot.Core.Converters
|
namespace Geekbot.Core.Converters
|
||||||
{
|
{
|
||||||
public class EmojiConverter : IEmojiConverter
|
public class EmojiConverter : IEmojiConverter
|
||||||
{
|
{
|
||||||
public string NumberToEmoji(int number)
|
private readonly string[] NumberEmojiMap =
|
||||||
{
|
|
||||||
if (number == 10)
|
|
||||||
{
|
|
||||||
return "🔟";
|
|
||||||
}
|
|
||||||
var emojiMap = new[]
|
|
||||||
{
|
{
|
||||||
":zero:",
|
":zero:",
|
||||||
":one:",
|
":one:",
|
||||||
|
@ -24,18 +19,24 @@ namespace Geekbot.Core.Converters
|
||||||
":eight:",
|
":eight:",
|
||||||
":nine:"
|
":nine:"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public string NumberToEmoji(int number)
|
||||||
|
{
|
||||||
|
if (number == 10)
|
||||||
|
{
|
||||||
|
return "🔟";
|
||||||
|
}
|
||||||
|
|
||||||
var numbers = number.ToString().ToCharArray();
|
var numbers = number.ToString().ToCharArray();
|
||||||
var returnString = new StringBuilder();
|
var returnString = new StringBuilder();
|
||||||
foreach (var n in numbers)
|
foreach (var n in numbers)
|
||||||
{
|
{
|
||||||
returnString.Append(emojiMap[int.Parse(n.ToString())]);
|
returnString.Append(NumberEmojiMap[int.Parse(n.ToString())]);
|
||||||
}
|
}
|
||||||
return returnString.ToString();
|
return returnString.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string TextToEmoji(string text)
|
private readonly Hashtable TextEmojiMap = new Hashtable
|
||||||
{
|
|
||||||
var emojiMap = new Hashtable
|
|
||||||
{
|
{
|
||||||
['A'] = ":regional_indicator_a: ",
|
['A'] = ":regional_indicator_a: ",
|
||||||
['B'] = ":b: ",
|
['B'] = ":b: ",
|
||||||
|
@ -80,11 +81,56 @@ namespace Geekbot.Core.Converters
|
||||||
['9'] = ":nine: ",
|
['9'] = ":nine: ",
|
||||||
[' '] = " "
|
[' '] = " "
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public string TextToEmoji(string text)
|
||||||
|
{
|
||||||
var letters = text.ToUpper().ToCharArray();
|
var letters = text.ToUpper().ToCharArray();
|
||||||
var returnString = new StringBuilder();
|
var returnString = new StringBuilder();
|
||||||
foreach (var n in letters)
|
foreach (var n in letters)
|
||||||
{
|
{
|
||||||
var emoji = emojiMap[n] ?? n;
|
var emoji = TextEmojiMap[n] ?? n;
|
||||||
|
returnString.Append(emoji);
|
||||||
|
}
|
||||||
|
return returnString.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Hashtable RegionalIndicatorMap = new Hashtable()
|
||||||
|
{
|
||||||
|
['A'] = new Rune(0x1F1E6),
|
||||||
|
['B'] = new Rune(0x1F1E7),
|
||||||
|
['C'] = new Rune(0x1F1E8),
|
||||||
|
['D'] = new Rune(0x1F1E9),
|
||||||
|
['E'] = new Rune(0x1F1EA),
|
||||||
|
['F'] = new Rune(0x1F1EB),
|
||||||
|
['G'] = new Rune(0x1F1EC),
|
||||||
|
['H'] = new Rune(0x1F1ED),
|
||||||
|
['I'] = new Rune(0x1F1EE),
|
||||||
|
['J'] = new Rune(0x1F1EF),
|
||||||
|
['K'] = new Rune(0x1F1F0),
|
||||||
|
['L'] = new Rune(0x1F1F1),
|
||||||
|
['M'] = new Rune(0x1F1F2),
|
||||||
|
['N'] = new Rune(0x1F1F3),
|
||||||
|
['O'] = new Rune(0x1F1F4),
|
||||||
|
['P'] = new Rune(0x1F1F5),
|
||||||
|
['Q'] = new Rune(0x1F1F6),
|
||||||
|
['R'] = new Rune(0x1F1F7),
|
||||||
|
['S'] = new Rune(0x1F1F8),
|
||||||
|
['T'] = new Rune(0x1F1F9),
|
||||||
|
['U'] = new Rune(0x1F1FA),
|
||||||
|
['V'] = new Rune(0x1F1FB),
|
||||||
|
['W'] = new Rune(0x1F1FC),
|
||||||
|
['X'] = new Rune(0x1F1FD),
|
||||||
|
['Y'] = new Rune(0x1F1FE),
|
||||||
|
['Z'] = new Rune(0x1F1FF)
|
||||||
|
};
|
||||||
|
|
||||||
|
public string CountryCodeToEmoji(string countryCode)
|
||||||
|
{
|
||||||
|
var letters = countryCode.ToUpper().ToCharArray();
|
||||||
|
var returnString = new StringBuilder();
|
||||||
|
foreach (var n in letters)
|
||||||
|
{
|
||||||
|
var emoji = RegionalIndicatorMap[n];
|
||||||
returnString.Append(emoji);
|
returnString.Append(emoji);
|
||||||
}
|
}
|
||||||
return returnString.ToString();
|
return returnString.ToString();
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
{
|
{
|
||||||
string NumberToEmoji(int number);
|
string NumberToEmoji(int number);
|
||||||
string TextToEmoji(string text);
|
string TextToEmoji(string text);
|
||||||
|
string CountryCodeToEmoji(string countryCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue