Skip to content

Commit 46ca058

Browse files
Complete bot embed support
1 parent 339ced9 commit 46ca058

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

Sources/DiscordKitBot/Embed/BotEmbed.swift

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ public struct BotEmbed: Codable {
4040
case url
4141
case timestamp
4242
case color
43-
case fields
4443
case footer
44+
case image
45+
case thumbnail
46+
case video
47+
case provider
48+
case author
49+
case fields
4550
}
4651

4752
// Always rich as that's the only type supported
@@ -54,6 +59,11 @@ public struct BotEmbed: Codable {
5459
fileprivate(set) var timestamp: Date?
5560
fileprivate(set) var color: Int?
5661
fileprivate(set) var footer: EmbedFooter?
62+
fileprivate(set) var image: EmbedMedia?
63+
fileprivate(set) var thumbnail: EmbedMedia?
64+
fileprivate(set) var video: EmbedMedia?
65+
fileprivate(set) var provider: EmbedProvider?
66+
fileprivate(set) var author: EmbedAuthor?
5767
private let fields: [Field]?
5868

5969
public init(fields: [Field]? = nil) {
@@ -77,12 +87,6 @@ public extension BotEmbed {
7787
return embed
7888
}
7989

80-
func footer(_ text: String) -> Self {
81-
var embed = self
82-
embed.footer = .init(text: text)
83-
return embed
84-
}
85-
8690
func url(_ url: URL?) -> Self {
8791
var embed = self
8892
embed.url = url
@@ -103,4 +107,81 @@ public extension BotEmbed {
103107
embed.color = color
104108
return embed
105109
}
110+
111+
func footer(_ footer: EmbedFooter?) -> Self {
112+
var embed = self
113+
embed.footer = footer
114+
return embed
115+
}
116+
117+
func footer(text: String, iconURL: String? = nil, proxyIconURL: String? = nil) -> Self {
118+
return footer(.init(text: text, icon_url: iconURL, proxy_icon_url: proxyIconURL))
119+
}
120+
121+
func footer(_ text: String) -> Self {
122+
return footer(text: text)
123+
}
124+
125+
func image(_ image: EmbedMedia?) -> Self {
126+
var embed = self
127+
embed.image = image
128+
return embed
129+
}
130+
131+
// TODO: accept URL in addition to string
132+
func image(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
133+
return image(.init(url: url, proxy_url: proxyURL, height: height, width: width))
134+
}
135+
136+
func image(_ url: String) -> Self {
137+
return image(url: url)
138+
}
139+
140+
func thumbnail(_ thumbnail: EmbedMedia?) -> Self {
141+
var embed = self
142+
embed.thumbnail = thumbnail
143+
return embed
144+
}
145+
146+
func thumbnail(_ url: String) -> Self {
147+
return thumbnail(url: url)
148+
}
149+
150+
func thumbnail(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
151+
return thumbnail(.init(url: url, proxy_url: proxyURL, height: height, width: width))
152+
}
153+
154+
func video(_ video: EmbedMedia?) -> Self {
155+
var embed = self
156+
embed.video = video
157+
return embed
158+
}
159+
160+
func video(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
161+
return video(.init(url: url, proxy_url: proxyURL, height: height, width: width))
162+
}
163+
164+
func video(_ url: String) -> Self {
165+
return video(url: url)
166+
}
167+
168+
func provider(_ provider: EmbedProvider?) -> Self {
169+
var embed = self
170+
embed.provider = provider
171+
return embed
172+
}
173+
174+
func provider(name: String, url: String? = nil) -> Self {
175+
return provider(.init(name: name, url: url))
176+
}
177+
178+
func author(_ author: EmbedAuthor?) -> Self {
179+
var embed = self
180+
embed.author = author
181+
return embed
182+
}
183+
184+
func author(name: String, url: String? = nil, iconURL: String? = nil, proxyIconURL: String? = nil) -> Self {
185+
return author(.init(name: name, url: url, icon_url: iconURL, proxy_icon_url: proxyIconURL))
186+
}
106187
}

Sources/DiscordKitCore/Objects/Data/Embed.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,37 @@ public struct EmbedFooter: Codable, Equatable, Hashable {
6666
}
6767

6868
public struct EmbedMedia: Codable, Equatable, Hashable {
69+
public init(url: String, proxy_url: String? = nil, height: Int? = nil, width: Int? = nil) {
70+
self.url = url
71+
self.proxy_url = proxy_url
72+
self.height = height
73+
self.width = width
74+
}
75+
6976
public let url: String
7077
public let proxy_url: String?
7178
public let height: Int?
7279
public let width: Int?
7380
}
7481

7582
public struct EmbedProvider: Codable, Equatable, Hashable {
83+
public init(name: String?, url: String?) {
84+
self.name = name
85+
self.url = url
86+
}
87+
7688
public let name: String?
7789
public let url: String?
7890
}
7991

8092
public struct EmbedAuthor: Codable, Equatable, Hashable {
93+
public init(name: String, url: String?, icon_url: String?, proxy_icon_url: String?) {
94+
self.name = name
95+
self.url = url
96+
self.icon_url = icon_url
97+
self.proxy_icon_url = proxy_icon_url
98+
}
99+
81100
public let name: String
82101
public let url: String?
83102
public let icon_url: String?

0 commit comments

Comments
 (0)