Add cdn
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
This commit is contained in:
		
							parent
							
								
									d091201ead
								
							
						
					
					
						commit
						0c9ab24f39
					
				
					 17 changed files with 152 additions and 13 deletions
				
			
		
							
								
								
									
										5
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							|  | @ -2,5 +2,8 @@ | ||||||
|   "deno.enable": true, |   "deno.enable": true, | ||||||
|   "deno.lint": false, |   "deno.lint": false, | ||||||
|   "deno.unstable": false, |   "deno.unstable": false, | ||||||
|   "deepscan.enable": true |   "deepscan.enable": true, | ||||||
|  |   "deno.import_intellisense_origins": { | ||||||
|  |     "https://deno.land": true | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | @ -1,12 +1,14 @@ | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { GatewayIntents } from '../types/gatewayTypes.ts' | import { GatewayIntents } from '../types/gatewayTypes.ts' | ||||||
| import { Gateway } from './gateway.ts' | import { Gateway } from './gateway.ts' | ||||||
|  | import { Rest } from "./rest.ts" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Discord Client. |  * Discord Client. | ||||||
|  */ |  */ | ||||||
| export class Client { | export class Client { | ||||||
|   gateway?: Gateway |   gateway?: Gateway | ||||||
|  |   rest?: Rest | ||||||
|   user?: User |   user?: User | ||||||
|   ping = 0 |   ping = 0 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -180,6 +180,10 @@ class Gateway { | ||||||
|     this.websocket.onclose = this.onclose.bind(this) |     this.websocket.onclose = this.onclose.bind(this) | ||||||
|     this.websocket.onerror = this.onerror.bind(this) |     this.websocket.onerror = this.onerror.bind(this) | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   close () { | ||||||
|  |     this.websocket.close(1000) | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export { Gateway } | export { Gateway } | ||||||
|  |  | ||||||
|  | @ -1 +1,12 @@ | ||||||
| // rest api
 | import { Client } from "./client.ts"; | ||||||
|  | 
 | ||||||
|  | class Rest  { | ||||||
|  |     client: Client | ||||||
|  |     constructor(client: Client) { | ||||||
|  |         this.client = client | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     //TODO: make endpoints function
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export { Rest } | ||||||
|  | @ -1,4 +1,3 @@ | ||||||
| // 일단 대충 여러 봇 라이브러리에서 본 구조 가져오는 중..
 |  | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| 
 | 
 | ||||||
| export class Base { | export class Base { | ||||||
|  |  | ||||||
							
								
								
									
										11
									
								
								src/structures/cdn.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/structures/cdn.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | import { ImageFormats, ImageSize } from "../types/cdnTypes.ts"; | ||||||
|  | 
 | ||||||
|  | export const ImageURL = ( | ||||||
|  |     url: string,  | ||||||
|  |     format: ImageFormats, | ||||||
|  |     size?: ImageSize | 128 | ||||||
|  | ) => { | ||||||
|  |     if (url.includes('a_')) { | ||||||
|  |         return url + '.gif' + '?size=' + size | ||||||
|  |     } else return url + '.' + format + '?size=' + size | ||||||
|  | } | ||||||
|  | @ -12,6 +12,13 @@ export class Emoji extends Base implements EmojiPayload { | ||||||
|   managed?: boolean |   managed?: boolean | ||||||
|   animated?: boolean |   animated?: boolean | ||||||
|   available?: boolean |   available?: boolean | ||||||
|  | 
 | ||||||
|  |   get CustomEmoji () { | ||||||
|  |     if (this.animated === false) { | ||||||
|  |      return `<:${this.name}:${this.id}>` | ||||||
|  |     } else return `<a:${this.name}:${this.id}>` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor (client: Client, data: EmojiPayload) { |   constructor (client: Client, data: EmojiPayload) { | ||||||
|     super(client) |     super(client) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|  |  | ||||||
|  | @ -15,6 +15,11 @@ export class Invite extends Base implements InvitePayload { | ||||||
|   approximate_presence_count?: number |   approximate_presence_count?: number | ||||||
|   approximate_member_count?: number |   approximate_member_count?: number | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |   get link () { | ||||||
|  |     return `discord.gg/${this.code}` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor (client: Client, data: InvitePayload) { |   constructor (client: Client, data: InvitePayload) { | ||||||
|     super(client) |     super(client) | ||||||
|     this.code = data.code |     this.code = data.code | ||||||
|  |  | ||||||
|  | @ -12,6 +12,10 @@ export class Role extends Base implements RolePayload { | ||||||
|   managed: boolean |   managed: boolean | ||||||
|   mentionable: boolean |   mentionable: boolean | ||||||
| 
 | 
 | ||||||
|  |   get mention () { | ||||||
|  |     return `<@&${this.id}>` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor (client: Client, data: RolePayload) { |   constructor (client: Client, data: RolePayload) { | ||||||
|     super(client) |     super(client) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|  |  | ||||||
|  | @ -23,6 +23,11 @@ export class TextChannel extends GuildChannel implements ChannelPayload { | ||||||
|   parent_id?: string | undefined |   parent_id?: string | undefined | ||||||
|   last_pin_timestamp?: string | undefined |   last_pin_timestamp?: string | undefined | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |   get mention () { | ||||||
|  |     return `<#${this.id}>` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor (client: Client, data: ChannelPayload) { |   constructor (client: Client, data: ChannelPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|  |  | ||||||
|  | @ -17,6 +17,14 @@ export class User extends Base implements UserPayload { | ||||||
|   premium_type?: 0 | 1 | 2 |   premium_type?: 0 | 1 | 2 | ||||||
|   public_flags?: number |   public_flags?: number | ||||||
| 
 | 
 | ||||||
|  |   get nickMention () { | ||||||
|  |     return `<@!${this.id}>` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   get mention () { | ||||||
|  |     return `<@${this.id}>` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor (client: Client, data: UserPayload) { |   constructor (client: Client, data: UserPayload) { | ||||||
|     super(client) |     super(client) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|  |  | ||||||
							
								
								
									
										33
									
								
								src/structures/voicestate.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/structures/voicestate.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | ||||||
|  | import { Client } from "../models/client.ts" | ||||||
|  | import { VoiceStatePayload } from "../types/voiceTypes.ts" | ||||||
|  | import { Base } from "./base.ts" | ||||||
|  | import { Member } from "./member.ts" | ||||||
|  | 
 | ||||||
|  | export class VoiceState extends Base implements VoiceStatePayload { | ||||||
|  |     guild_id?: string | ||||||
|  |     channel_id: string | undefined | ||||||
|  |     user_id: string | ||||||
|  |     member?: Member | ||||||
|  |     session_id: string | ||||||
|  |     deaf: boolean | ||||||
|  |     mute: boolean | ||||||
|  |     self_deaf: boolean | ||||||
|  |     self_mute: boolean | ||||||
|  |     self_stream?: boolean | ||||||
|  |     self_video: boolean | ||||||
|  |     suppress: boolean | ||||||
|  | 
 | ||||||
|  |     constructor (client: Client, data: VoiceStatePayload) { | ||||||
|  |         super(client) | ||||||
|  |         this.channel_id = data.channel_id | ||||||
|  |         this.session_id = data.session_id | ||||||
|  |         this.user_id = data.user_id | ||||||
|  |         this.deaf = data.deaf | ||||||
|  |         this.mute = data.mute | ||||||
|  |         this.self_deaf = data.self_deaf | ||||||
|  |         this.self_mute = data.self_mute | ||||||
|  |         this.self_stream = data.self_stream | ||||||
|  |         this.self_video = data.self_video | ||||||
|  |         this.suppress = data.suppress | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								src/structures/webhook.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/structures/webhook.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | import { Client } from "../models/client.ts" | ||||||
|  | import { WebhookPayload } from "../types/webhookTypes.ts" | ||||||
|  | import { Base } from "./base.ts" | ||||||
|  | import { User } from "./user.ts" | ||||||
|  | 
 | ||||||
|  | export class VoiceState extends Base implements WebhookPayload { | ||||||
|  |     id: string | ||||||
|  |     type: 1 | 2 | ||||||
|  |     guild_id?: string | ||||||
|  |     channel_id: string | ||||||
|  |     user?: User | ||||||
|  |     name: string | undefined | ||||||
|  |     avatar: string | undefined | ||||||
|  |     token?: string | ||||||
|  |     application_id: string | undefined | ||||||
|  | 
 | ||||||
|  |     constructor (client: Client, data: WebhookPayload) { | ||||||
|  |         super(client) | ||||||
|  |         this.id = data.id | ||||||
|  |         this.type = data.type | ||||||
|  |         this.channel_id = data.channel_id | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -1 +1,2 @@ | ||||||
| const TOKEN = '' | const TOKEN = '' | ||||||
|  | export { TOKEN } | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								src/types/cdnTypes.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/types/cdnTypes.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | ||||||
|  | export type ImageFormats = "jpg" | "jpeg" | "png" | "webp" | "gif" | ||||||
|  | @ -134,32 +134,32 @@ const GATEWAY_BOT = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot` | ||||||
| 
 | 
 | ||||||
| //CDN Endpoints
 | //CDN Endpoints
 | ||||||
| const CUSTOM_EMOJI = (emojiID: string) => | const CUSTOM_EMOJI = (emojiID: string) => | ||||||
|   `${DISCORD_CDN_URL}/emojis/${emojiID}.png` |   `${DISCORD_CDN_URL}/emojis/${emojiID}` | ||||||
| const GUILD_ICON = (guildID: string, iconID: number) => | const GUILD_ICON = (guildID: string, iconID: number) => | ||||||
|   `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}.png` |   `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}` | ||||||
| const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => | const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => | ||||||
|   `${DISCORD_CDN_URL}/splashes/${guildID}/${guildSPLASH}.png` |   `${DISCORD_CDN_URL}/splashes/${guildID}/${guildSPLASH}` | ||||||
| const GUILD_DISCOVERY_SPLASH = ( | const GUILD_DISCOVERY_SPLASH = ( | ||||||
|   guildID: string, |   guildID: string, | ||||||
|   guildDiscoverySplash: string |   guildDiscoverySplash: string | ||||||
| ) => | ) => | ||||||
|   `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}.png	` |   `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}` | ||||||
| const GUILD_BANNER = (guildID: string, guildBANNER: string) => | const GUILD_BANNER = (guildID: string, guildBANNER: string) => | ||||||
|   `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}.png` |   `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}` | ||||||
| const DEFAULT_USER_AVATAR = (iconID: string) => | const DEFAULT_USER_AVATAR = (iconID: string) => | ||||||
|   `${DISCORD_CDN_URL}/embed/avatars/${iconID}.png` |   `${DISCORD_CDN_URL}/embed/avatars/${iconID}` | ||||||
| const USER_AVATAR = (userID: string, iconID: string) => | const USER_AVATAR = (userID: string, iconID: string) => | ||||||
|   `${DISCORD_CDN_URL}/avatars/${userID}/${iconID}.png` |   `${DISCORD_CDN_URL}/avatars/${userID}/${iconID}` | ||||||
| const APPLICATION_ASSET = (applicationID: string, assetID: number) => | const APPLICATION_ASSET = (applicationID: string, assetID: number) => | ||||||
|   `${DISCORD_CDN_URL}/app-icons/${applicationID}/${assetID}.png` |   `${DISCORD_CDN_URL}/app-icons/${applicationID}/${assetID}` | ||||||
| const ACHIEVEMENT_ICON = ( | const ACHIEVEMENT_ICON = ( | ||||||
|   applicationID: string, |   applicationID: string, | ||||||
|   achievementID: string, |   achievementID: string, | ||||||
|   iconHASH: string |   iconHASH: string | ||||||
| ) => | ) => | ||||||
|   `${DISCORD_CDN_URL}/app-assets/${applicationID}/achievements/${achievementID}/icons/${iconHASH}.png` |   `${DISCORD_CDN_URL}/app-assets/${applicationID}/achievements/${achievementID}/icons/${iconHASH}` | ||||||
| const TEAM_ICON = (teamID: string, iconID: string) => | const TEAM_ICON = (teamID: string, iconID: string) => | ||||||
|   `${DISCORD_CDN_URL}/team-icons/${teamID}/${iconID}.png` |   `${DISCORD_CDN_URL}/team-icons/${teamID}/${iconID}` | ||||||
| 
 | 
 | ||||||
| //Emoji Endpoints
 | //Emoji Endpoints
 | ||||||
| const EMOJI = (guildID: string, emojiID: string) => | const EMOJI = (guildID: string, emojiID: string) => | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
 | // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
 | ||||||
| // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
 | // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
 | ||||||
| import { Emoji } from '../structures/emoji.ts' | import { Emoji } from '../structures/emoji.ts' | ||||||
|  | import { Member } from '../structures/member.ts' | ||||||
| import { Role } from '../structures/role.ts' | import { Role } from '../structures/role.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { MemberPayload } from './guildTypes.ts' | import { MemberPayload } from './guildTypes.ts' | ||||||
|  | @ -360,6 +361,7 @@ interface ActivityAssets { | ||||||
|   small_image?: string |   small_image?: string | ||||||
|   small_text?: string |   small_text?: string | ||||||
| } | } | ||||||
|  | 
 | ||||||
| interface ActivitySecrets { | interface ActivitySecrets { | ||||||
|   join?: string |   join?: string | ||||||
|   spectate?: string |   spectate?: string | ||||||
|  | @ -375,5 +377,24 @@ enum ActivityFlags { | ||||||
|   PLAY = 1 << 5 |   PLAY = 1 << 5 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | interface TypeStart { | ||||||
|  |   channel_id: string | ||||||
|  |   guild_id?: string | ||||||
|  |   user_id: string | ||||||
|  |   timestamp: number | ||||||
|  |   member?: Member | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | interface VoiceServerUpdate { | ||||||
|  |   token: string | ||||||
|  |   guild_id: string | ||||||
|  |   endpoint: string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | interface WebhooksUpdate { | ||||||
|  |   guild_id: string | ||||||
|  |   channel_id: string | ||||||
|  | } | ||||||
|  | 
 | ||||||
| //https://discord.com/developers/docs/topics/gateway#typing-start-typing-start-event-fields
 | //https://discord.com/developers/docs/topics/gateway#typing-start-typing-start-event-fields
 | ||||||
| export { GatewayCloseCodes, GatewayOpcodes, GatewayIntents, GatewayEvents } | export { GatewayCloseCodes, GatewayOpcodes, GatewayIntents, GatewayEvents } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue