public async Task RandomColorAsync(Color color) { var colorImagePath = _colorService.GetColorImage(color.ToString()); using (var colorImage = LocalAttachment.File(colorImagePath, "colorImage.png")) { var eb = new LocalEmbed() .WithColor(color) .WithDescription($"Hex: {color.ToString()}\nRGB: {color.R} {color.G} {color.B}") .WithImageUrl("attachment://colorImage.png"); var mb = new LocalMessage() .WithAttachments(colorImage) .WithEmbeds(eb); await Response(mb); } File.Delete(colorImagePath); }
public async Task SearchColorAsync( [Description("The R component"), Range(0, 256)] int r, [Description("The G component"), Range(0, 256)] int g, [Description("The B component"), Range(0, 256)] int b) { var color = new Color(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b)); var result = await _colorService.GetColorInfo(color.ToString().Substring(1)); var colorImagePath = _colorService.GetColorImage(color.ToString()); using (var colorImage = LocalAttachment.File(colorImagePath, "colorImage.png")) { var eb = new LocalEmbed() .WithTitle(result.Name.Value) .WithColor(color) .WithImageUrl("attachment://colorImage.png"); if (result.Name.ExactMatchName) { eb.AddField("Hex value", result.Hex.Value); } else { eb.AddField("Closest Match Hex", result.Name.ClosestNamedHex); } eb.AddField("RGB", result.Rgb.Value) .AddField("HSL", result.Hsl.Value) .AddField("HSV", result.Hsv.Value) .AddField("CMYK", result.Cmyk.Value); var mb = new LocalMessage() .WithAttachments(colorImage) .WithEmbeds(eb); await Response(mb); } File.Delete(colorImagePath); }