-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscordWebhook.lua
More file actions
94 lines (94 loc) · 2.36 KB
/
discordWebhook.lua
File metadata and controls
94 lines (94 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
local dw = {}
function dw.sendMessage(url, username, avatar, content, embeds)
local json = {
content = content,
username = username,
["avatar_url"] = avatar,
embeds = embeds
}
local data = http.post(url.."?wait=true", textutils.serialiseJSON(json), {["Content-Type"] = "application/json"})
return textutils.unserialiseJSON(data.readAll())
end
function dw.editMessage(url, id, content, embeds)
local json = {
content = content,
embeds = embeds
}
http.request({
url = url.."/messages/"..id,
body = textutils.serialiseJSON(json),
headers = {["Content-Type"]="application/json"},
method = "PATCH"
})
end
function dw.createEmbed()
local out = {
title= "",
color= "",
description= "",
fields= {},
author= {},
footer= {},
timestamp= "",
thumbnail= {}
}
function out:setTitle(title)
out.title = title
return out
end
function out:setDescription(description)
out.description = description
return out
end
function out:setColor(color)
out.color = color
return out
end
function out:addField(name, value, inline)
table.insert(out.fields, {
name = name,
value = value,
inline = inline
})
return out
end
function out:setAuthor(name, avatar)
out.author = {
name = name,
["icon_url"] = avatar
}
return out
end
function out:setFooter(text, avatar)
out.footer = {
text = text,
["icon_url"] = avatar
}
return out
end
function out:setTimestamp()
local date = os.date("!%Y-%m-%dT%H:%M:%S.") .. string.format("%03d", (os.clock() * 1000)) .. "Z"
out.timestamp = date
return out
end
function out:setThumbnail(url)
out.thumbnail = {
url = url,
}
return out
end
function out:sendable()
return {
title = out.title,
color = out.color,
description = out.description,
fields = out.fields,
author = out.author,
footer = out.footer,
timestamp = out.timestamp,
thumbnail = out.thumbnail
}
end
return out
end
return dw