2018-05-03 00:56:06 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Utf8Json;
|
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Lib.Converters
|
|
|
|
|
{
|
|
|
|
|
public class MtgManaConverter : IMtgManaConverter
|
|
|
|
|
{
|
2020-02-08 15:58:17 +01:00
|
|
|
|
private readonly Dictionary<string, string> _manaDict;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
|
|
|
|
|
public MtgManaConverter()
|
|
|
|
|
{
|
|
|
|
|
// these emotes can be found at https://discord.gg/bz8HyA7
|
|
|
|
|
var mtgEmojis = File.ReadAllText(Path.GetFullPath("./Lib/Converters/MtgManaEmojis.json"));
|
|
|
|
|
_manaDict = JsonSerializer.Deserialize<Dictionary<string, string>>(mtgEmojis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ConvertMana(string mana)
|
|
|
|
|
{
|
|
|
|
|
var rgx = Regex.Matches(mana, @"(\{(.*?)\})");
|
|
|
|
|
foreach (Match manaTypes in rgx)
|
|
|
|
|
{
|
|
|
|
|
var m = _manaDict.GetValueOrDefault(manaTypes.Value);
|
|
|
|
|
if (!string.IsNullOrEmpty(m))
|
|
|
|
|
{
|
|
|
|
|
mana = mana.Replace(manaTypes.Value, m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mana;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|