@@ -26,6 +26,25 @@ export interface BaseImageURLOptions {
2626 size ?: ImageSize ;
2727}
2828
29+ interface EmojiURLOptionsWebp extends BaseImageURLOptions {
30+ /**
31+ * Whether to use the `animated` query parameter.
32+ *
33+ * @remarks An animated custom emoji with the WebP format utilises this query paramter to be animated.
34+ */
35+ animated ?: boolean ;
36+ extension ?: 'webp' ;
37+ }
38+
39+ interface EmojiURLOptionsNotWebP extends BaseImageURLOptions {
40+ extension : Exclude < ImageExtension , 'webp' > ;
41+ }
42+
43+ /**
44+ * The options used for emoji URLs.
45+ */
46+ export type EmojiURLOptions = EmojiURLOptionsNotWebP | EmojiURLOptionsWebp ;
47+
2948/**
3049 * The options used for image URLs with animated content
3150 */
@@ -44,6 +63,10 @@ export interface MakeURLOptions {
4463 * The allowed extensions that can be used
4564 */
4665 allowedExtensions ?: readonly string [ ] ;
66+ /**
67+ * Whether to use the `animated` query parameter
68+ */
69+ animated ?: boolean ;
4770 /**
4871 * The base URL.
4972 *
@@ -162,11 +185,10 @@ export class CDN {
162185 * Generates an emoji's URL.
163186 *
164187 * @param emojiId - The emoji id
165- * @param animated - Whether the emoji is animated
166188 * @param options - Optional options for the emoji
167189 */
168- public emoji ( emojiId : string , animated : boolean , options ?: Readonly < ImageURLOptions > ) : string {
169- return this . dynamicMakeURL ( `/emojis/${ emojiId } ` , animated ? 'a_' : '' , options ) ;
190+ public emoji ( emojiId : string , options ?: Readonly < EmojiURLOptions > ) : string {
191+ return this . makeURL ( `/emojis/${ emojiId } ` , options ) ;
170192 }
171193
172194 /**
@@ -326,6 +348,7 @@ export class CDN {
326348 base = this . cdn ,
327349 extension = 'webp' ,
328350 size,
351+ animated,
329352 } : Readonly < MakeURLOptions > = { } ,
330353 ) : string {
331354 // eslint-disable-next-line no-param-reassign
@@ -345,6 +368,10 @@ export class CDN {
345368 url . searchParams . set ( 'size' , String ( size ) ) ;
346369 }
347370
371+ if ( animated !== undefined ) {
372+ url . searchParams . set ( 'animated' , String ( animated ) ) ;
373+ }
374+
348375 return url . toString ( ) ;
349376 }
350377}
0 commit comments