From 043e7aeb08891107e4462f62630489ac009a17c2 Mon Sep 17 00:00:00 2001
From: Fernando Rocha <34967844+Fernando-A-Rocha@users.noreply.github.com>
Date: Mon, 13 Nov 2023 21:19:14 +0000
Subject: [PATCH 1/2] Fix color range checks
to accept Hex and Decimal colors
---
discord_webhooks/embeds.lua | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/discord_webhooks/embeds.lua b/discord_webhooks/embeds.lua
index c55c4aa..77737b0 100644
--- a/discord_webhooks/embeds.lua
+++ b/discord_webhooks/embeds.lua
@@ -170,13 +170,17 @@ local function iso_8061_timestamp(now)
end
-- Inverse of tocolor
-local function fromColor(color)
- local blue = bitExtract(color, 0, 8)
- local green = bitExtract(color, 8, 8)
- local red = bitExtract(color, 16, 8)
- -- local alpha = bitExtract(color, 24, 8) -- unsupported by Discord
+local function fromColor(hexColor)
+ local blue = bitExtract(hexColor, 0, 8)
+ local green = bitExtract(hexColor, 8, 8)
+ local red = bitExtract(hexColor, 16, 8)
+ -- local alpha = bitExtract(hexColor, 24, 8) -- unsupported by Discord
return { red, green, blue }
end
+local function fromColorDecimal(decColor)
+ local hexColor = string.format("0x%06X", decColor)
+ return fromColor(hexColor)
+end
local function rgbToHex(rgb)
local hexadecimal = '0x'
@@ -224,11 +228,14 @@ function validateEmbed(embed)
end
end
if (additional.color ~= nil) then
- -- check if in range of tocolor()
- if (additional.color >= 0) and (additional.color <= 0xFFFFFFFF) then
+ if (additional.color >= 0) and (additional.color <= 16777215) then
+ -- in decimal range
+ additional.color = rgbToHex(fromColorDecimal(additional.color))
+ elseif (additional.color >= -16777216) and (additional.color <= -1) then
+ -- in hexadecimal range
additional.color = rgbToHex(fromColor(additional.color))
else
- return false, "Invalid color. Expected a number between 0 and 0xFFFFFFFF, got '"..additional.color.."' - use tocolor(R,G,B) or 0xRRGGBB"
+ return false, "Invalid color. Expected color in hexadecimal or decimal, got '"..additional.color.."' - use tocolor(R,G,B,255) or 0xFFRRGGBB"
end
end
return true, additional
From d286adb44574e85a26e6a464435332dcec663b17 Mon Sep 17 00:00:00 2001
From: Fernando Rocha <34967844+Fernando-A-Rocha@users.noreply.github.com>
Date: Mon, 13 Nov 2023 21:19:53 +0000
Subject: [PATCH 2/2] Update meta.xml
---
discord_webhooks/meta.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/discord_webhooks/meta.xml b/discord_webhooks/meta.xml
index e438235..b21a26c 100644
--- a/discord_webhooks/meta.xml
+++ b/discord_webhooks/meta.xml
@@ -1,5 +1,5 @@
-
+