-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.lua
executable file
·134 lines (111 loc) · 2.47 KB
/
embed.lua
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
local json = require "json"
Embed = {
title = nil,
description = nil,
url = nil,
timestamp = nil,
color = nil,
footer = nil,
image = nil,
thumbnail = nil,
video = nil,
provider = nil,
author = nil,
fields = {}
}
function Embed:create(o)
setmetatable(o, {__index = Embed})
return o
end
function Embed:setTitle(title)
self.title = title
return self
end
function Embed:setDescription(description)
self.description = description
return self
end
function Embed:setURL(url)
self.url = url
return self
end
function Embed:setTimestamp(timestamp)
local regex = "^(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d)$"
if string.find(timestamp, regex) == nil then
warn("Invalid timestamp provided: " .. timestamp)
return self
end
self.timestamp = timestamp
return self
end
function Embed:setColor(color)
self.color = color
return self
end
function Embed:setFooter(text, icon_url)
self.footer = {
text = text,
icon_url = icon_url
}
return self
end
function Embed:setImage(url, width, height)
self.image = {
url = url,
width = width,
height = height
}
return self
end
function Embed:setThumbnail(url, width, height)
self.thumbnail = {
url = url,
width = width,
height = height
}
return self
end
function Embed:setVideo(url, width, height)
self.video = {
url = url,
width = width,
height = height
}
return self
end
function Embed:setProvider(name, url)
self.provider = {
name = name,
url = url
}
return self
end
function Embed:setAuthor(name, url, icon_url)
self.author = {
name = name,
url = url,
icon_url = icon_url
}
return self
end
function Embed:addField(name, value, inline)
if inline == nil then
inline = false
end
self.fields[#self.fields+1] = {
name = name,
value = value,
inline = inline
}
return self
end
function Embed:toJSON()
local embed = {}
for k, v in pairs(self) do
if type(v) ~= "function" then
embed[k] = v
end
end
return embed
end
return Embed