using System; using System.Globalization; namespace Maki { public class DiscordColour { public int Raw = 0; public byte Red { get => (byte)(Raw >> 16 & 0xFF); set { Raw &= ~0xFF0000; Raw |= value << 16; } } public byte Green { get => (byte)(Raw >> 8 & 0xFF); set { Raw &= ~0xFF00; Raw |= value << 8; } } public byte Blue { get => (byte)(Raw & 0xFF); set { Raw &= ~0xFF; Raw |= value; } } public string Hex => $"{Red:X2}{Green:X2}{Blue:X2}"; public override string ToString() => $"#{Hex}"; public DiscordColour(int raw) { Raw = raw; } public DiscordColour(byte red, byte green, byte blue) { Raw |= red << 16; Raw |= green << 8; Raw |= blue; } public DiscordColour(string hex) { hex = hex.ToUpper(); if (hex.Length == 3) hex = new string(hex[0], 2) + new string(hex[1], 2) + new string(hex[2], 2); if (hex.Length != 6) throw new FormatException("Invalid hex colour format!"); Red = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber); Green = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber); Blue = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber); } } }