Discord embed limitiations
Added embed limitations warnings & cut limit exceeding strings.
This commit is contained in:
parent
59696c994a
commit
eac88a6501
38
RoHook.lua
38
RoHook.lua
|
@ -54,7 +54,11 @@ local function getAvatar()
|
|||
end
|
||||
|
||||
function module.newMessage(message)
|
||||
message = message
|
||||
|
||||
if(message and string.len(message) > 2000) then
|
||||
warn("A message cannot be longer than 2000 characters.")
|
||||
message = string.sub(message, 1, 2000)
|
||||
end
|
||||
|
||||
local content = {
|
||||
content = message,
|
||||
|
@ -99,6 +103,16 @@ function module.newMessage(message)
|
|||
timestamp = "" --"YYYY-MM-DDTHH:MM:SS.MSSZ"
|
||||
}
|
||||
|
||||
if(title and string.len(title) > 256) then
|
||||
warn("Title cannot be longer than 265 characters.")
|
||||
title = string.sub(title, 1, 256)
|
||||
end
|
||||
|
||||
if(description and string.len(description > 2048)) then
|
||||
warn("Description cannot be longer than 2048 characters.")
|
||||
description = string.sub(description, 1, 2048)
|
||||
end
|
||||
|
||||
table.insert(content.embeds, embed)
|
||||
|
||||
function embed.setColor(rgb)
|
||||
|
@ -107,6 +121,17 @@ function module.newMessage(message)
|
|||
|
||||
function embed.addField(name, value, inline)
|
||||
if(not name or not value) then error("Name and value cannot be nil") end
|
||||
|
||||
if(string.len(name) > 256) then
|
||||
warn("Field name cannot be longer than 256 characters.")
|
||||
name = string.sub(name, 1, 256)
|
||||
end
|
||||
|
||||
if(string.len(value) > 1024) then
|
||||
warn("Field value cannot be longer than 1024 characters.")
|
||||
value = string.sub(value, 1, 1024)
|
||||
end
|
||||
|
||||
inline = inline or false
|
||||
|
||||
local field = {
|
||||
|
@ -121,6 +146,12 @@ function module.newMessage(message)
|
|||
|
||||
function embed.setAuthor(name, url, icon_url)
|
||||
if(not name and icon_url) then error("Name cannot be nil") end
|
||||
|
||||
if(string.len(name) > 256) then
|
||||
warn("Author name cannot be longer than 256 characters.")
|
||||
name = string.sub(name, 1, 256)
|
||||
end
|
||||
|
||||
embed.author.name = name
|
||||
embed.author.url = url
|
||||
embed.author.icon_url = icon_url
|
||||
|
@ -141,6 +172,11 @@ function module.newMessage(message)
|
|||
function embed.setFooter(text, url)
|
||||
if(not text) then error("Text cannot be nil!") end
|
||||
|
||||
if(string.len(text) > 2048) then
|
||||
warn("Footer text cannot be longer than 2048 characters.")
|
||||
text = string.sub(text, 1, 2048)
|
||||
end
|
||||
|
||||
embed.footer.text = text
|
||||
embed.footer.icon_url = url
|
||||
end
|
||||
|
|
Reference in New Issue