2017-11-08 01:30:50 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Text;
|
2017-11-06 23:55:28 +01:00
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Lib
|
|
|
|
|
{
|
|
|
|
|
public class EmojiConverter : IEmojiConverter
|
|
|
|
|
{
|
2018-04-30 23:44:19 +02:00
|
|
|
|
public string NumberToEmoji(int number)
|
2017-11-06 23:55:28 +01:00
|
|
|
|
{
|
|
|
|
|
if (number == 10)
|
|
|
|
|
{
|
|
|
|
|
return "🔟";
|
|
|
|
|
}
|
2018-04-30 23:44:19 +02:00
|
|
|
|
var emojiMap = new[]
|
2018-01-19 00:59:21 +01:00
|
|
|
|
{
|
|
|
|
|
":zero:",
|
|
|
|
|
":one:",
|
|
|
|
|
":two:",
|
|
|
|
|
":three:",
|
|
|
|
|
":four:",
|
|
|
|
|
":five:",
|
|
|
|
|
":six:",
|
|
|
|
|
":seven:",
|
|
|
|
|
":eight:",
|
2018-04-30 23:44:19 +02:00
|
|
|
|
":nine:"
|
2018-01-19 00:59:21 +01:00
|
|
|
|
};
|
2017-11-06 23:55:28 +01:00
|
|
|
|
var numbers = number.ToString().ToCharArray();
|
|
|
|
|
var returnString = new StringBuilder();
|
|
|
|
|
foreach (var n in numbers)
|
|
|
|
|
{
|
|
|
|
|
returnString.Append(emojiMap[int.Parse(n.ToString())]);
|
|
|
|
|
}
|
|
|
|
|
return returnString.ToString();
|
|
|
|
|
}
|
2017-11-08 01:30:50 +01:00
|
|
|
|
|
2018-04-30 23:44:19 +02:00
|
|
|
|
public string TextToEmoji(string text)
|
2017-11-08 01:30:50 +01:00
|
|
|
|
{
|
|
|
|
|
var emojiMap = new Hashtable
|
|
|
|
|
{
|
2018-01-29 23:27:28 +01:00
|
|
|
|
['A'] = ":regional_indicator_a: ",
|
|
|
|
|
['B'] = ":b: ",
|
|
|
|
|
['C'] = ":regional_indicator_c: ",
|
|
|
|
|
['D'] = ":regional_indicator_d: ",
|
|
|
|
|
['E'] = ":regional_indicator_e: ",
|
|
|
|
|
['F'] = ":regional_indicator_f: ",
|
|
|
|
|
['G'] = ":regional_indicator_g: ",
|
|
|
|
|
['H'] = ":regional_indicator_h: ",
|
|
|
|
|
['I'] = ":regional_indicator_i: ",
|
|
|
|
|
['J'] = ":regional_indicator_j: ",
|
|
|
|
|
['K'] = ":regional_indicator_k: ",
|
|
|
|
|
['L'] = ":regional_indicator_l: ",
|
|
|
|
|
['M'] = ":regional_indicator_m: ",
|
|
|
|
|
['N'] = ":regional_indicator_n: ",
|
|
|
|
|
['O'] = ":regional_indicator_o: ",
|
|
|
|
|
['P'] = ":regional_indicator_p: ",
|
|
|
|
|
['Q'] = ":regional_indicator_q: ",
|
|
|
|
|
['R'] = ":regional_indicator_r: ",
|
|
|
|
|
['S'] = ":regional_indicator_s: ",
|
|
|
|
|
['T'] = ":regional_indicator_t: ",
|
|
|
|
|
['U'] = ":regional_indicator_u: ",
|
|
|
|
|
['V'] = ":regional_indicator_v: ",
|
|
|
|
|
['W'] = ":regional_indicator_w: ",
|
|
|
|
|
['X'] = ":regional_indicator_x: ",
|
|
|
|
|
['Y'] = ":regional_indicator_y: ",
|
|
|
|
|
['Z'] = ":regional_indicator_z: ",
|
|
|
|
|
['!'] = ":exclamation: ",
|
|
|
|
|
['?'] = ":question: ",
|
|
|
|
|
['#'] = ":hash: ",
|
|
|
|
|
['*'] = ":star2: ",
|
|
|
|
|
['+'] = ":heavy_plus_sign: ",
|
|
|
|
|
['0'] = ":zero: ",
|
|
|
|
|
['1'] = ":one: ",
|
|
|
|
|
['2'] = ":two: ",
|
|
|
|
|
['3'] = ":three: ",
|
|
|
|
|
['4'] = ":four: ",
|
|
|
|
|
['5'] = ":five: ",
|
|
|
|
|
['6'] = ":six: ",
|
|
|
|
|
['7'] = ":seven: ",
|
|
|
|
|
['8'] = ":eight: ",
|
|
|
|
|
['9'] = ":nine: ",
|
|
|
|
|
[' '] = " "
|
2017-11-08 01:30:50 +01:00
|
|
|
|
};
|
|
|
|
|
var letters = text.ToUpper().ToCharArray();
|
|
|
|
|
var returnString = new StringBuilder();
|
|
|
|
|
foreach (var n in letters)
|
|
|
|
|
{
|
|
|
|
|
var emoji = emojiMap[n] ?? n;
|
|
|
|
|
returnString.Append(emoji);
|
|
|
|
|
}
|
|
|
|
|
return returnString.ToString();
|
|
|
|
|
}
|
2017-11-06 23:55:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IEmojiConverter
|
|
|
|
|
{
|
2018-04-30 23:44:19 +02:00
|
|
|
|
string NumberToEmoji(int number);
|
|
|
|
|
string TextToEmoji(string text);
|
2017-11-06 23:55:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|