Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions discord_webhooks/embeds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion discord_webhooks/meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<meta>
<info version="2.0.0" author="Fernando" name="mta-discord-webhooks" description="simple scripts to use Discord Webhooks in your MTA server" type="script"/>
<info version="2.0.1" author="Fernando" name="mta-discord-webhooks" description="simple scripts to use Discord Webhooks in your MTA server" type="script"/>
<!-- DOCUMENTATION:
https://github.com/Fernando-A-Rocha/mta-discord-webhooks
-->
Expand Down