-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscordEmbed.luau
137 lines (121 loc) · 3.19 KB
/
DiscordEmbed.luau
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
135
136
137
local DiscordEmbed = {}
DiscordEmbed.__index = DiscordEmbed
--[=[
@class DiscordEmbed
This is an internal class that is created with :addEmbed()
]=]
--- @prop embed {any}
--- @within DiscordEmbed
--[=[
Creates a new discord embed class
@return class
]=]
function DiscordEmbed.new()
local self = setmetatable({}, DiscordEmbed)
self.embed = {}
return self
end
--[=[
Sets the embed title
@param title string -- Title of the embed
@return DiscordEmbed
]=]
function DiscordEmbed:setTitle(title)
self.embed.title = title
return self
end
--[=[
Sets the embed description
@param description string -- Description text
@return DiscordEmbed
]=]
function DiscordEmbed:setDescription(description)
self.embed.description = description
return self
end
--[=[
Sets the embed URL
@param url string -- URL to be attached to the embed title
@return DiscordEmbed
]=]
function DiscordEmbed:setURL(url)
self.embed.url = url
return self
end
--[=[
Sets the embed color
@param hexColor string -- Hexadecimal color (as a string)
@return DiscordEmbed
]=]
function DiscordEmbed:setColor(hexColor)
self.embed.color = tonumber(hexColor, 16)
return self
end
--[=[
Sets the embed author
@param name string -- Name of the author
@param icon_url string -- (Optional) URL for the author icon
@param url string -- (Optional) URL for the author link
@return DiscordEmbed
]=]
function DiscordEmbed:setAuthor(name, icon_url, url)
self.embed.author = { name = name, icon_url = icon_url, url = url }
return self
end
--[=[
Sets the embed footer
@param text string -- Footer text
@param icon_url string -- (Optional) URL for the footer icon
@return DiscordEmbed
]=]
function DiscordEmbed:setFooter(text, icon_url)
self.embed.footer = { text = text, icon_url = icon_url }
return self
end
--[=[
Sets the embed thumbnail
@param url string -- URL of the thumbnail image
@return DiscordEmbed
]=]
function DiscordEmbed:setThumbnail(url)
self.embed.thumbnail = { url = url }
return self
end
--[=[
Sets the embed image
@param url string -- URL of the image
@return DiscordEmbed
]=]
function DiscordEmbed:setImage(url)
self.embed.image = { url = url }
return self
end
--[=[
Adds a field to the embed
@param name string -- Name of the field
@param value string -- Value of the field
@param inline boolean -- Whether the field is inline (default is false)
@return DiscordEmbed
]=]
function DiscordEmbed:addField(name, value, inline)
self.embed.fields = self.embed.fields or {}
table.insert(self.embed.fields, { name = name, value = value, inline = inline or false })
return self
end
--[=[
Sets the embed timestamp
@param timestamp string -- ISO 8601 timestamp (optional, defaults to current UTC time)
@return DiscordEmbed
]=]
function DiscordEmbed:setTimestamp(timestamp)
self.embed.timestamp = timestamp or os.date("!%Y-%m-%dT%H:%M:%SZ")
return self
end
--[=[
Builds the embed data for sending in a Discord message
@return table -- Returns the embed data as a table
]=]
function DiscordEmbed:build()
return self.embed
end
return DiscordEmbed