Added setWebhookUsername & setWebhookAvatar.

This commit is contained in:
Norberto A 2020-02-29 16:40:32 +00:00 committed by GitHub
parent 0d13bdab4b
commit 0301ad9a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 29 deletions

View File

@ -21,39 +21,54 @@ end
local module = {} local module = {}
-- Your webhook's URL module.webhookConfig = {
module.webhookUrl = "" webhookUrl = "https://canary.discordapp.com/api/webhooks/682537382519635974/VfS2r9dRsPW4Q-Ti4FPhnoeWY1KdeLeS6F4bTA2oqWzKrqqQQ2qII0UVJtouBnHml52P",
}
function module.newMessage(message) function module.newMessage(message)
message = message message = message
local content = { local content = {
["content"] = message, content = message,
["embeds"] = {} embeds = {},
avatar_url = "",
username= "",
} }
function content.setWebhookUsername(name)
if(not name) then error("Name cannot be nil.") end
content.username = name
end
function content.setWebhookAvatar(url)
if(not url) then error("URL cannot be nil.") end
content.avatar_url = url
end
function content.addEmbed(title, description) function content.addEmbed(title, description)
local embed = { local embed = {
["title"] = title, title = title,
["description"] = description, description = description,
["color"] = 0, color = 0,
["fields"] = {}, fields = {},
["thumbnail"] = { thumbnail = {
["url" ]= "" url= ""
}, },
["image"] = { image= {
["url"] = "" url = ""
}, },
["author"] = { author = {
["name"] = "", name = "",
["url"] = "", url = "",
["icon_url"] = "" icon_url = ""
}, },
["footer"] = { footer = {
["text"] = "", text = "",
["icon_url"] = "" icon_url = ""
}, },
["timestamp"] = "" --"YYYY-MM-DDTHH:MM:SS.MSSZ" timestamp = "" --"YYYY-MM-DDTHH:MM:SS.MSSZ"
} }
table.insert(content.embeds, embed) table.insert(content.embeds, embed)
@ -67,9 +82,9 @@ function module.newMessage(message)
inline = inline or false inline = inline or false
local field = { local field = {
["name"] = name, name = name,
["value"] = value, value = value,
["inline"] = inline inline = inline
} }
table.insert(embed.fields, field) table.insert(embed.fields, field)
@ -117,7 +132,7 @@ function module:send(content)
content = httpService:JSONEncode(content) content = httpService:JSONEncode(content)
local success, data = pcall(function() local success, data = pcall(function()
return httpService:PostAsync(module.webhookUrl, content) return httpService:PostAsync(module.webhookConfig.webhookUrl, content)
end) end)
return success, data return success, data