Skip to content

Commit 61913de

Browse files
Complete bot embed support
1 parent 2da56fe commit 61913de

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
@@ -67,18 +67,37 @@ public struct EmbedFooter: Codable, Equatable, Hashable {
6767
}
6868

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

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

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

0 commit comments

Comments
 (0)