edit cdn.ts
This commit is contained in:
		
							parent
							
								
									45eadb5d11
								
							
						
					
					
						commit
						a143399f6e
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		|  | @ -1,11 +1,13 @@ | |||
| import { ImageFormats, ImageSize } from '../types/cdn.ts' | ||||
| 
 | ||||
| /** Function to get Image URL from a resource on Discord CDN */ | ||||
| export const ImageURL = ( | ||||
|   url: string, | ||||
|   format: ImageFormats, | ||||
|   size?: ImageSize | 128 | ||||
|   format: ImageFormats | undefined = 'webp', | ||||
|   size: ImageSize | undefined = 128 | ||||
| ): string => { | ||||
|   size = size === undefined ? 128 : size | ||||
|   if (url.includes('a_')) { | ||||
|     return `${url}.gif?size=${size}` | ||||
|   } else return `${url}.${format}?size=${size}` | ||||
| } | ||||
|     return `${url}.${format === undefined ? 'gif' : format}?size=${size}` | ||||
|   } else return `${url}.${format === 'gif' ? 'webp' : format}?size=${size}` | ||||
| } | ||||
|  | @ -42,7 +42,7 @@ export class User extends Base { | |||
| 
 | ||||
|   avatarURL(format: ImageFormats = 'webp', size: ImageSize = 512, dynamic: boolean = true): string { | ||||
|     return this.avatar != null | ||||
|       ? `${ImageURL(USER_AVATAR(this.id, dynamic ? this.avatar : this.avatar.replace('a_', '')), format, size)}` | ||||
|       ? `${ImageURL(USER_AVATAR(this.id, this.avatar), format, size)}` | ||||
|       : `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue