|
1 | 1 | import { DiscordSnowflake } from '@sapphire/snowflake'; |
2 | | -import type { APIApplication, ApplicationFlags } from 'discord-api-types/v10'; |
| 2 | +import { |
| 3 | + type ApplicationIconFormat, |
| 4 | + type APIApplication, |
| 5 | + type ApplicationCoverFormat, |
| 6 | + type ApplicationFlags, |
| 7 | + CDNRoutes, |
| 8 | + ImageFormat, |
| 9 | + RouteBases, |
| 10 | +} from 'discord-api-types/v10'; |
3 | 11 | import { Structure } from '../Structure.js'; |
4 | 12 | import { ApplicationFlagsBitField } from '../bitfields/ApplicationFlagsBitField.js'; |
5 | 13 | import { kData } from '../utils/symbols.js'; |
6 | | -import { isIdSet } from '../utils/type-guards.js'; |
| 14 | +import { isFieldSet, isIdSet } from '../utils/type-guards.js'; |
7 | 15 | import type { Partialize } from '../utils/types.js'; |
8 | 16 |
|
9 | | -// TODO: missing "team" substructure |
10 | | - |
11 | 17 | /** |
12 | 18 | * Represents an application on Discord. |
13 | 19 | * |
@@ -45,6 +51,17 @@ export class Application<Omitted extends keyof APIApplication | '' = ''> extends |
45 | 51 | return this[kData].icon; |
46 | 52 | } |
47 | 53 |
|
| 54 | + /** |
| 55 | + * Get the URL to the icon. |
| 56 | + * |
| 57 | + * @param format - the file format to use |
| 58 | + */ |
| 59 | + public iconURL(format: ApplicationIconFormat = ImageFormat.WebP) { |
| 60 | + return isIdSet(this[kData].id) && isFieldSet(this[kData], 'icon', 'string') |
| 61 | + ? `${RouteBases.cdn}${CDNRoutes.applicationCover(this[kData].id.toString(), this[kData].icon, format)}` |
| 62 | + : null; |
| 63 | + } |
| 64 | + |
48 | 65 | /** |
49 | 66 | * The description of the application. |
50 | 67 | */ |
@@ -130,13 +147,24 @@ export class Application<Omitted extends keyof APIApplication | '' = ''> extends |
130 | 147 | return this[kData].cover_image; |
131 | 148 | } |
132 | 149 |
|
| 150 | + /** |
| 151 | + * Get the URL to the cover image. |
| 152 | + * |
| 153 | + * @param format - the file format to use |
| 154 | + */ |
| 155 | + public coverImageURL(format: ApplicationCoverFormat = ImageFormat.WebP) { |
| 156 | + return isIdSet(this[kData].id) && isFieldSet(this[kData], 'cover_image', 'string') |
| 157 | + ? `${RouteBases.cdn}${CDNRoutes.applicationCover(this[kData].id.toString(), this[kData].cover_image, format)}` |
| 158 | + : null; |
| 159 | + } |
| 160 | + |
133 | 161 | /** |
134 | 162 | * The application's public flags. |
135 | 163 | * |
136 | 164 | * @see {@link https://discord.com/developers/docs/resources/application#application-object-application-flags} |
137 | 165 | */ |
138 | 166 | public get flags() { |
139 | | - return 'flags' in this[kData] && typeof this[kData].flags === 'number' |
| 167 | + return isFieldSet(this[kData], 'flags', 'number') |
140 | 168 | ? new ApplicationFlagsBitField(this[kData].flags as ApplicationFlags) |
141 | 169 | : null; |
142 | 170 | } |
|
0 commit comments