Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 88 additions & 7 deletions Sources/DiscordKitBot/Embed/BotEmbed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public struct BotEmbed: Codable {
case url
case timestamp
case color
case fields
case footer
case image
case thumbnail
case video
case provider
case author
case fields
}

// Always rich as that's the only type supported
Expand All @@ -54,6 +59,11 @@ public struct BotEmbed: Codable {
fileprivate(set) var timestamp: Date?
fileprivate(set) var color: Int?
fileprivate(set) var footer: EmbedFooter?
fileprivate(set) var image: EmbedMedia?
fileprivate(set) var thumbnail: EmbedMedia?
fileprivate(set) var video: EmbedMedia?
fileprivate(set) var provider: EmbedProvider?
fileprivate(set) var author: EmbedAuthor?
private let fields: [Field]?

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

func footer(_ text: String) -> Self {
var embed = self
embed.footer = .init(text: text)
return embed
}

func url(_ url: URL?) -> Self {
var embed = self
embed.url = url
Expand All @@ -103,4 +107,81 @@ public extension BotEmbed {
embed.color = color
return embed
}

func footer(_ footer: EmbedFooter?) -> Self {
var embed = self
embed.footer = footer
return embed
}

func footer(text: String, iconURL: String? = nil, proxyIconURL: String? = nil) -> Self {
return footer(.init(text: text, icon_url: iconURL, proxy_icon_url: proxyIconURL))
}

func footer(_ text: String) -> Self {
return footer(text: text)
}

func image(_ image: EmbedMedia?) -> Self {
var embed = self
embed.image = image
return embed
}

// TODO: accept URL in addition to string
func image(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
return image(.init(url: url, proxy_url: proxyURL, height: height, width: width))
}

func image(_ url: String) -> Self {
return image(url: url)
}

func thumbnail(_ thumbnail: EmbedMedia?) -> Self {
var embed = self
embed.thumbnail = thumbnail
return embed
}

func thumbnail(_ url: String) -> Self {
return thumbnail(url: url)
}

func thumbnail(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
return thumbnail(.init(url: url, proxy_url: proxyURL, height: height, width: width))
}

func video(_ video: EmbedMedia?) -> Self {
var embed = self
embed.video = video
return embed
}

func video(url: String, proxyURL: String? = nil, height: Int? = nil, width: Int? = nil) -> Self {
return video(.init(url: url, proxy_url: proxyURL, height: height, width: width))
}

func video(_ url: String) -> Self {
return video(url: url)
}

func provider(_ provider: EmbedProvider?) -> Self {
var embed = self
embed.provider = provider
return embed
}

func provider(name: String, url: String? = nil) -> Self {
return provider(.init(name: name, url: url))
}

func author(_ author: EmbedAuthor?) -> Self {
var embed = self
embed.author = author
return embed
}

func author(name: String, url: String? = nil, iconURL: String? = nil, proxyIconURL: String? = nil) -> Self {
return author(.init(name: name, url: url, icon_url: iconURL, proxy_icon_url: proxyIconURL))
}
}
19 changes: 19 additions & 0 deletions Sources/DiscordKitCore/Objects/Data/Embed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,37 @@ public struct EmbedFooter: Codable, Equatable, Hashable {
}

public struct EmbedMedia: Codable, Equatable, Hashable {
public init(url: String, proxy_url: String? = nil, height: Int? = nil, width: Int? = nil) {
self.url = url
self.proxy_url = proxy_url
self.height = height
self.width = width
}

public let url: String
public let proxy_url: String?
public let height: Int?
public let width: Int?
}

public struct EmbedProvider: Codable, Equatable, Hashable {
public init(name: String?, url: String?) {
self.name = name
self.url = url
}

public let name: String?
public let url: String?
}

public struct EmbedAuthor: Codable, Equatable, Hashable {
public init(name: String, url: String?, icon_url: String?, proxy_icon_url: String?) {
self.name = name
self.url = url
self.icon_url = icon_url
self.proxy_icon_url = proxy_icon_url
}

public let name: String
public let url: String?
public let icon_url: String?
Expand Down