Skip to content

Commit 5debdbe

Browse files
committed
feat(structures): use isFieldSet and add image URL getters
1 parent 57acbf5 commit 5debdbe

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

packages/structures/src/application/Application.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
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';
311
import { Structure } from '../Structure.js';
412
import { ApplicationFlagsBitField } from '../bitfields/ApplicationFlagsBitField.js';
513
import { kData } from '../utils/symbols.js';
6-
import { isIdSet } from '../utils/type-guards.js';
14+
import { isFieldSet, isIdSet } from '../utils/type-guards.js';
715
import type { Partialize } from '../utils/types.js';
816

9-
// TODO: missing "team" substructure
10-
1117
/**
1218
* Represents an application on Discord.
1319
*
@@ -45,6 +51,17 @@ export class Application<Omitted extends keyof APIApplication | '' = ''> extends
4551
return this[kData].icon;
4652
}
4753

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+
4865
/**
4966
* The description of the application.
5067
*/
@@ -130,13 +147,24 @@ export class Application<Omitted extends keyof APIApplication | '' = ''> extends
130147
return this[kData].cover_image;
131148
}
132149

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+
133161
/**
134162
* The application's public flags.
135163
*
136164
* @see {@link https://discord.com/developers/docs/resources/application#application-object-application-flags}
137165
*/
138166
public get flags() {
139-
return 'flags' in this[kData] && typeof this[kData].flags === 'number'
167+
return isFieldSet(this[kData], 'flags', 'number')
140168
? new ApplicationFlagsBitField(this[kData].flags as ApplicationFlags)
141169
: null;
142170
}

0 commit comments

Comments
 (0)