2020-11-01 16:53:00 +00:00
|
|
|
-- Norbunny
|
|
|
|
-- November 1, 2020
|
|
|
|
|
|
|
|
local httpService = game:GetService("HttpService")
|
|
|
|
|
|
|
|
local RoHook = {}
|
|
|
|
RoHook.__index = RoHook
|
|
|
|
|
2020-11-01 18:04:56 +00:00
|
|
|
function RoHook.new(url, username, avatar)
|
|
|
|
assert(url, "URL cannot be nil.")
|
|
|
|
|
|
|
|
local self = {
|
|
|
|
url = url,
|
|
|
|
username = username,
|
|
|
|
avatarUrl = avatar
|
|
|
|
}
|
2020-11-01 16:53:00 +00:00
|
|
|
|
2020-11-01 18:04:56 +00:00
|
|
|
setmetatable(self, RoHook)
|
2020-11-01 16:53:00 +00:00
|
|
|
|
2020-11-01 18:04:56 +00:00
|
|
|
return self
|
2020-11-01 16:53:00 +00:00
|
|
|
end
|
|
|
|
|
2020-11-01 18:40:36 +00:00
|
|
|
function RoHook:setUsername(username)
|
|
|
|
self.username = username
|
2020-11-01 16:53:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function RoHook:setAvatar(url)
|
2020-11-01 18:40:36 +00:00
|
|
|
self.avatarUrl = url
|
2020-11-01 16:53:00 +00:00
|
|
|
end
|
|
|
|
|
2020-11-01 18:04:56 +00:00
|
|
|
function RoHook:send(data)
|
2020-11-01 18:40:36 +00:00
|
|
|
local request = {
|
|
|
|
username = self.username,
|
|
|
|
avatar_url = self.avatarUrl
|
|
|
|
}
|
2020-11-01 16:53:00 +00:00
|
|
|
|
|
|
|
if data.ClassName == "RichEmbed" then
|
2020-11-01 18:40:36 +00:00
|
|
|
request.embeds = {data}
|
2020-11-01 16:53:00 +00:00
|
|
|
|
|
|
|
elseif data.ClassName == "Message" then
|
2020-11-01 18:04:56 +00:00
|
|
|
print("Sending Message")
|
|
|
|
end
|
|
|
|
|
|
|
|
local success, res = pcall(function()
|
|
|
|
local response = httpService:RequestAsync({
|
|
|
|
Url = self.url,
|
|
|
|
Method = "POST",
|
|
|
|
Headers = {
|
|
|
|
["Content-Type"] = "application/json"
|
|
|
|
},
|
|
|
|
|
|
|
|
Body = httpService:JSONEncode(request)
|
|
|
|
})
|
|
|
|
|
|
|
|
return response
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not success then
|
|
|
|
error(string.format("POST request failed: %s", res))
|
|
|
|
else
|
|
|
|
assert(res.Success, string.format("Server replied with %s - %s", res.StatusCode, res.StatusMessage))
|
2020-11-01 16:53:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return RoHook
|