Skip to content

Commit dc16b00

Browse files
authored
feat: sticker packs types and endpoints (#27)
1 parent f75e3e7 commit dc16b00

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Sources/DiscordKitCore/Objects/Data/Sticker.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ public struct StickerItem: Codable, Identifiable {
3939
public let name: String
4040
public let format_type: StickerFormat
4141
}
42+
43+
public struct StickerPack: Codable, GatewayData {
44+
public let id: Snowflake
45+
public let stickers: [StickerItem]
46+
public let name: String
47+
public let sku_id: Snowflake
48+
public let cover_sticker_id: Snowflake?
49+
public let description: String
50+
public let banner_asset_id: HashedAsset?
51+
}

Sources/DiscordKitCore/REST/APISticker.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import Foundation
44

5+
private struct StickerPacks: Codable, GatewayData {
6+
public let sticker_packs: [StickerPack]
7+
}
8+
59
public extension DiscordREST {
610
/// Get Sticker
711
///
@@ -16,10 +20,11 @@ public extension DiscordREST {
1620
/// List Nitro Sticker Packs
1721
///
1822
/// > GET: `/sticker-packs`
19-
func listNitroStickerPacks<T: Decodable>() async throws -> T {
20-
return try await getReq(
23+
func listNitroStickerPacks() async throws -> [StickerPack] {
24+
let stickerPacks: StickerPacks = try await getReq(
2125
path: "sticker-packs"
2226
)
27+
return stickerPacks.sticker_packs
2328
}
2429
/// List Guild Stickers
2530
///

Sources/DiscordKitCore/Utils/HashedAsset.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ public extension HashedAsset {
8383
return HashedAsset.joinPaths(with: format, "icons", guildID, self)
8484
.setSize(size: size)
8585
}
86+
87+
/// Returns the icon URL of a sticker pack banner
88+
///
89+
/// > This resource will not be animated.
90+
///
91+
/// - Parameters:
92+
/// - format: Format of banner (PNG, JPEG, WebP)
93+
/// - size: Size of asset, a power of 2 from 16 to 4096
94+
func stickerPackBannerURL(
95+
with format: AssetFormat = .png,
96+
size: Int? = nil
97+
) -> URL {
98+
return HashedAsset.joinPaths(with: format, "app-assets", "710982414301790216", "store", self)
99+
.setSize(size: size)
100+
}
86101
}
87102

88103
public extension HashedAsset {

0 commit comments

Comments
 (0)