invalid hex error

This commit is contained in:
Master Kwoth
2017-06-15 20:04:15 +02:00
parent 06693b9b34
commit 4e7b7a6ee5
3 changed files with 20 additions and 12 deletions

View File

@@ -637,9 +637,21 @@ namespace NadekoBot.Modules.Searches
color = color?.Trim().Replace("#", "");
if (string.IsNullOrWhiteSpace(color))
return;
ImageSharp.Color clr;
try
{
clr = ImageSharp.Color.FromHex(color);
}
catch
{
await ReplyErrorLocalized("hex_invalid").ConfigureAwait(false);
return;
}
var img = new ImageSharp.Image(50, 50);
img.BackgroundColor(ImageSharp.Color.FromHex(color));
img.BackgroundColor(clr);
await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png").ConfigureAwait(false);
}