2020-02-28 19:04:47 +00:00
|
|
|
-- Script type: Module
|
|
|
|
-- Writen by github.com/Limesey, @Norbunny on Roblox.
|
|
|
|
|
2020-02-28 21:14:43 +00:00
|
|
|
-- services
|
2020-02-27 16:27:26 +00:00
|
|
|
local httpService = game:GetService("HttpService")
|
|
|
|
|
2020-03-01 16:06:52 +00:00
|
|
|
local module = {}
|
|
|
|
|
|
|
|
module.webhookConfig = {
|
|
|
|
webhookUrl = "",
|
|
|
|
overrideUsername = false,
|
|
|
|
overrideAvatar = false,
|
|
|
|
|
|
|
|
username = nil,
|
|
|
|
avatar = nil
|
|
|
|
}
|
|
|
|
|
2020-02-27 16:27:26 +00:00
|
|
|
local function getDate()
|
|
|
|
local date = os.date("!*t")
|
|
|
|
|
2020-03-03 14:22:08 +00:00
|
|
|
local function format(i)
|
|
|
|
if(string.len(i) == 1) then
|
|
|
|
return string.format("0%s", i)
|
|
|
|
else
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
2020-02-27 16:27:26 +00:00
|
|
|
|
2020-03-03 14:22:08 +00:00
|
|
|
local str = string.format("%s-%s-%sT%s:%s:%s.000Z", date.year, date.month, date.day, format(date.hour), format(date.min), format(date.sec))
|
2020-02-27 16:27:26 +00:00
|
|
|
return str
|
|
|
|
end
|
|
|
|
|
|
|
|
local function rgbToDec(rgb)
|
2020-02-28 21:14:43 +00:00
|
|
|
local rgbTotal = rgb.R * 65536 + rgb.G * 256 + rgb.B
|
2020-02-27 16:27:26 +00:00
|
|
|
|
2020-02-28 21:14:43 +00:00
|
|
|
return rgbTotal
|
2020-02-27 16:27:26 +00:00
|
|
|
end
|
|
|
|
|
2020-02-29 16:59:25 +00:00
|
|
|
|
|
|
|
local function getUsername()
|
|
|
|
local config = module.webhookConfig
|
|
|
|
|
|
|
|
if(config.overrideUsername) then
|
|
|
|
return config.username
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getAvatar()
|
|
|
|
local config = module.webhookConfig
|
|
|
|
|
|
|
|
if(config.overrideAvatar) then
|
|
|
|
return config.avatar
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-27 16:27:26 +00:00
|
|
|
function module.newMessage(message)
|
|
|
|
message = message
|
|
|
|
|
|
|
|
local content = {
|
2020-02-29 16:40:32 +00:00
|
|
|
content = message,
|
|
|
|
embeds = {},
|
2020-02-29 16:59:25 +00:00
|
|
|
username = getUsername() or "",
|
|
|
|
avatar_url = getAvatar() or "",
|
2020-02-27 16:27:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 16:40:32 +00:00
|
|
|
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
|
|
|
|
|
2020-02-27 16:27:26 +00:00
|
|
|
function content.addEmbed(title, description)
|
|
|
|
local embed = {
|
2020-02-29 16:40:32 +00:00
|
|
|
title = title,
|
|
|
|
description = description,
|
|
|
|
color = 0,
|
|
|
|
fields = {},
|
|
|
|
thumbnail = {
|
|
|
|
url= ""
|
2020-02-27 16:27:26 +00:00
|
|
|
},
|
2020-02-29 16:40:32 +00:00
|
|
|
image= {
|
|
|
|
url = ""
|
2020-02-27 16:27:26 +00:00
|
|
|
},
|
2020-02-29 16:40:32 +00:00
|
|
|
author = {
|
|
|
|
name = "",
|
|
|
|
url = "",
|
|
|
|
icon_url = ""
|
2020-02-27 16:27:26 +00:00
|
|
|
},
|
2020-02-29 16:40:32 +00:00
|
|
|
footer = {
|
|
|
|
text = "",
|
|
|
|
icon_url = ""
|
2020-02-27 16:27:26 +00:00
|
|
|
},
|
2020-02-29 16:40:32 +00:00
|
|
|
timestamp = "" --"YYYY-MM-DDTHH:MM:SS.MSSZ"
|
2020-02-27 16:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(content.embeds, embed)
|
|
|
|
|
|
|
|
function embed.setColor(rgb)
|
|
|
|
embed.color = rgbToDec(rgb)
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.addField(name, value, inline)
|
2020-02-29 16:40:32 +00:00
|
|
|
if(not name or not value) then error("Name and value cannot be nil") end
|
2020-02-27 16:27:26 +00:00
|
|
|
inline = inline or false
|
|
|
|
|
|
|
|
local field = {
|
2020-02-29 16:40:32 +00:00
|
|
|
name = name,
|
|
|
|
value = value,
|
|
|
|
inline = inline
|
2020-02-27 16:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(embed.fields, field)
|
|
|
|
return field
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.setAuthor(name, url, icon_url)
|
2020-02-29 16:40:32 +00:00
|
|
|
if(not name and icon_url) then error("Name cannot be nil") end
|
2020-02-27 16:27:26 +00:00
|
|
|
embed.author.name = name
|
|
|
|
embed.author.url = url
|
|
|
|
embed.author.icon_url = icon_url
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.setThumbnail(url)
|
2020-02-29 16:40:32 +00:00
|
|
|
if(not url) then error("URL cannot be nil") end
|
2020-02-27 16:27:26 +00:00
|
|
|
|
|
|
|
embed.thumbnail.url = url
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.setImage(url)
|
2020-02-29 16:40:32 +00:00
|
|
|
if(not url) then error("URL cannot be nil") end
|
2020-02-27 16:27:26 +00:00
|
|
|
|
|
|
|
embed.image.url = url
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.setFooter(text, url)
|
2020-02-29 16:40:32 +00:00
|
|
|
if(not text) then error("Text cannot be nil!") end
|
2020-02-27 16:27:26 +00:00
|
|
|
|
|
|
|
embed.footer.text = text
|
|
|
|
embed.footer.icon_url = url
|
|
|
|
end
|
|
|
|
|
|
|
|
function embed.setTimestamp()
|
|
|
|
embed.timestamp = getDate()
|
|
|
|
end
|
|
|
|
|
|
|
|
return embed
|
|
|
|
end
|
|
|
|
|
|
|
|
return content
|
|
|
|
end
|
|
|
|
|
|
|
|
function module:send(content)
|
|
|
|
|
|
|
|
content = httpService:JSONEncode(content)
|
|
|
|
|
|
|
|
local success, data = pcall(function()
|
2020-02-29 16:40:32 +00:00
|
|
|
return httpService:PostAsync(module.webhookConfig.webhookUrl, content)
|
2020-02-27 16:27:26 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
return success, data
|
|
|
|
end
|
|
|
|
|
|
|
|
return module
|