Show mana costs as emojis in mtg

This commit is contained in:
Runebaas 2018-02-13 22:29:37 +01:00
parent 91d178049b
commit 6fd36e0bb2
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
@ -12,10 +13,12 @@ namespace Geekbot.net.Commands
public class Magicthegathering : ModuleBase public class Magicthegathering : ModuleBase
{ {
private readonly IErrorHandler _errorHandler; private readonly IErrorHandler _errorHandler;
private readonly IEmojiConverter _emojiConverter;
public Magicthegathering(IErrorHandler errorHandler) public Magicthegathering(IErrorHandler errorHandler, IEmojiConverter emojiConverter)
{ {
_errorHandler = errorHandler; _errorHandler = errorHandler;
_emojiConverter = emojiConverter;
} }
[Command("mtg", RunMode = RunMode.Async)] [Command("mtg", RunMode = RunMode.Async)]
@ -51,7 +54,7 @@ namespace Geekbot.net.Commands
if (!string.IsNullOrEmpty(card.Loyalty)) eb.AddInlineField("Loyality", card.Loyalty); if (!string.IsNullOrEmpty(card.Loyalty)) eb.AddInlineField("Loyality", card.Loyalty);
if (!string.IsNullOrEmpty(card.Toughness)) eb.AddInlineField("Thoughness", card.Toughness); if (!string.IsNullOrEmpty(card.Toughness)) eb.AddInlineField("Thoughness", card.Toughness);
if (!string.IsNullOrEmpty(card.ManaCost)) eb.AddInlineField("Cost", card.ManaCost); if (!string.IsNullOrEmpty(card.ManaCost)) eb.AddInlineField("Cost", ManaConverter(card.ManaCost));
if (!string.IsNullOrEmpty(card.Rarity)) eb.AddInlineField("Rarity", card.Rarity); if (!string.IsNullOrEmpty(card.Rarity)) eb.AddInlineField("Rarity", card.Rarity);
if (card.Legalities != null) if (card.Legalities != null)
@ -84,5 +87,21 @@ namespace Geekbot.net.Commands
return new Color(255, 252, 214); return new Color(255, 252, 214);
} }
} }
private string ManaConverter(string mana)
{
var rgx = new Regex("{(\\d)}");
var groups = rgx.Match(mana).Groups;
if (groups.Count == 2)
{
mana = mana.Replace(groups[0].Value, _emojiConverter.numberToEmoji(int.Parse(groups[1].Value)));
}
return mana
.Replace("{W}", ":sunny:")
.Replace("{U}", ":droplet:")
.Replace("{B}", ":skull:")
.Replace("{R}", ":fire:")
.Replace("{G}", ":deciduous_tree:");
}
} }
} }