Caching, Fetching, and other things
- Make the gateway fetches guilds from Discord response - Fetch guilds with only ID and client - Make more types - Fix lint errors Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com> Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com> Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com> Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
This commit is contained in:
		
							parent
							
								
									01d9b82f47
								
							
						
					
					
						commit
						1e8475456a
					
				
					 35 changed files with 667 additions and 358 deletions
				
			
		
							
								
								
									
										46
									
								
								src/models/cache.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/models/cache.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| let caches: any = {} | ||||
| 
 | ||||
| const get = (cacheName: string, key: string) => { | ||||
|   const gotCache: Map<string, any> = caches[cacheName] | ||||
|   if (gotCache === undefined || !(gotCache instanceof Map)) { | ||||
|     return undefined | ||||
|   } | ||||
| 
 | ||||
|   const gotMap = gotCache.get(key) | ||||
|   return gotMap | ||||
| } | ||||
| 
 | ||||
| const set = (cacheName: string, key: string, value: any) => { | ||||
|   let gotCache: Map<string, any> = caches[cacheName] | ||||
|   if (gotCache === undefined || !(gotCache instanceof Map)) { | ||||
|     gotCache = caches[cacheName] = new Map<string, any>() | ||||
|   } | ||||
| 
 | ||||
|   gotCache.set(key, value) | ||||
| 
 | ||||
|   return value | ||||
| } | ||||
| 
 | ||||
| const del = (cacheName: string, key: string) => { | ||||
|   const gotCache: Map<string, any> = caches[cacheName] | ||||
|   if (gotCache === undefined || !(gotCache instanceof Map)) { | ||||
|     return | ||||
|   } | ||||
| 
 | ||||
|   return gotCache.delete(key) | ||||
| } | ||||
| 
 | ||||
| const deleteCache = (cacheName: string) => { | ||||
|   const gotCache = caches[cacheName] | ||||
|   if (gotCache === undefined) { | ||||
|     return | ||||
|   } | ||||
| 
 | ||||
|   delete caches[cacheName] | ||||
| } | ||||
| 
 | ||||
| const resetCaches = () => { | ||||
|   caches = {} | ||||
| } | ||||
| 
 | ||||
| export { get, set, del, deleteCache, resetCaches } | ||||
|  | @ -1,7 +1,7 @@ | |||
| import { User } from '../structures/user.ts' | ||||
| import { GatewayIntents } from '../types/gatewayTypes.ts' | ||||
| import { Gateway } from './gateway.ts' | ||||
| import { Rest } from "./rest.ts" | ||||
| import { Rest } from './rest.ts' | ||||
| 
 | ||||
| /** | ||||
|  * Discord Client. | ||||
|  | @ -11,6 +11,7 @@ export class Client { | |||
|   rest?: Rest | ||||
|   user?: User | ||||
|   ping = 0 | ||||
|   token?: string | ||||
| 
 | ||||
|   constructor () {} | ||||
| 
 | ||||
|  | @ -20,6 +21,7 @@ export class Client { | |||
|    * @param intents Gateway intents in array. This is required. | ||||
|    */ | ||||
|   connect (token: string, intents: GatewayIntents[]) { | ||||
|     this.token = token | ||||
|     this.gateway = new Gateway(this, token, intents) | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -10,7 +10,10 @@ import { | |||
|   GatewayIntents, | ||||
|   GatewayEvents | ||||
| } from '../types/gatewayTypes.ts' | ||||
| import { GuildPayload } from '../types/guildTypes.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import * as cache from './cache.ts' | ||||
| import { Guild } from '../structures/guild.ts' | ||||
| 
 | ||||
| /** | ||||
|  * Handles Discord gateway connection. | ||||
|  | @ -48,11 +51,11 @@ class Gateway { | |||
|     this.websocket.onerror = this.onerror.bind(this) | ||||
|   } | ||||
| 
 | ||||
|   onopen () { | ||||
|   private onopen () { | ||||
|     this.connected = true | ||||
|   } | ||||
| 
 | ||||
|   onmessage (event: MessageEvent) { | ||||
|   private onmessage (event: MessageEvent) { | ||||
|     let data = event.data | ||||
|     if (data instanceof ArrayBuffer) { | ||||
|       data = new Uint8Array(data) | ||||
|  | @ -114,6 +117,7 @@ class Gateway { | |||
|         break | ||||
| 
 | ||||
|       case GatewayOpcodes.DISPATCH: | ||||
|         this.heartbeatServerResponded = true | ||||
|         if (s !== null) { | ||||
|           this.sequenceID = s | ||||
|         } | ||||
|  | @ -121,6 +125,9 @@ class Gateway { | |||
|           case GatewayEvents.Ready: | ||||
|             this.client.user = new User(this.client, d.user) | ||||
|             this.sessionID = d.session_id | ||||
|             d.guilds.forEach((guild: GuildPayload) => { | ||||
|               cache.set('guilds', guild.id, new Guild(this.client, guild)) | ||||
|             }) | ||||
|             break | ||||
|           default: | ||||
|             break | ||||
|  | @ -131,17 +138,17 @@ class Gateway { | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   onclose (event: CloseEvent) { | ||||
|   private onclose (event: CloseEvent) { | ||||
|     // TODO: Handle close event codes.
 | ||||
|   } | ||||
| 
 | ||||
|   onerror (event: Event | ErrorEvent) { | ||||
|   private onerror (event: Event | ErrorEvent) { | ||||
|     const eventError = event as ErrorEvent | ||||
| 
 | ||||
|     console.log(eventError) | ||||
|   } | ||||
| 
 | ||||
|   sendIdentify () { | ||||
|   private sendIdentify () { | ||||
|     this.websocket.send( | ||||
|       JSON.stringify({ | ||||
|         op: GatewayOpcodes.IDENTIFY, | ||||
|  |  | |||
|  | @ -1,12 +1,12 @@ | |||
| import { Client } from "./client.ts"; | ||||
| import { Client } from './client.ts' | ||||
| 
 | ||||
| class Rest  { | ||||
|     client: Client | ||||
|     constructor(client: Client) { | ||||
|         this.client = client | ||||
|     } | ||||
| class Rest { | ||||
|   client: Client | ||||
|   constructor (client: Client) { | ||||
|     this.client = client | ||||
|   } | ||||
| 
 | ||||
|     //TODO: make endpoints function
 | ||||
|   //TODO: make endpoints function
 | ||||
| } | ||||
| 
 | ||||
| export { Rest } | ||||
| export { Rest } | ||||
|  |  | |||
							
								
								
									
										26
									
								
								src/structures/categoryChannel.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/structures/categoryChannel.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| import { GuildPayload, GuildFeatures } from '../types/guildTypes.ts' | ||||
| import { | ||||
|   GuildChannelCategoryPayload, | ||||
|   Overwrite | ||||
| } from '../types/channelTypes.ts' | ||||
| 
 | ||||
| export class categoryChannel extends Channel { | ||||
|   guildID: string | ||||
|   name: string | ||||
|   position: number | ||||
|   permissionOverwrites: Overwrite[] | ||||
|   nsfw: boolean | ||||
|   parentID?: string | ||||
| 
 | ||||
|   constructor (client: Client, data: GuildChannelCategoryPayload) { | ||||
|     super(client, data) | ||||
|     this.guildID = data.guild_id | ||||
|     this.name = data.name | ||||
|     this.position = data.position | ||||
|     this.permissionOverwrites = data.permission_overwrites | ||||
|     this.nsfw = data.nsfw | ||||
|     this.parentID = data.parent_id | ||||
|   } | ||||
| } | ||||
|  | @ -1,7 +1,18 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { ChannelPayload, ChannelTypes } from '../types/channelTypes.ts' | ||||
| import { | ||||
|   ChannelPayload, | ||||
|   GuildChannelCategoryPayload, | ||||
|   GuildNewsChannelPayload, | ||||
|   GuildTextChannelPayload, | ||||
|   GuildVoiceChannelPayload, | ||||
|   DMChannelPayload, | ||||
|   GroupDMChannelPayload, | ||||
|   ChannelTypes | ||||
| } from '../types/channelTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| import { PrivateChannel } from './dm.ts' | ||||
| import { DMChannel } from './dm.ts' | ||||
| import { GroupChannel } from './groupChannel.ts' | ||||
| import { VoiceChannel } from './guildVoiceChannel.ts' | ||||
| import { TextChannel } from './textChannel.ts' | ||||
| 
 | ||||
| export class Channel extends Base { | ||||
|  | @ -18,12 +29,29 @@ export class Channel extends Base { | |||
|     return `<#${this.id}>` | ||||
|   } | ||||
| 
 | ||||
|   static from (data: ChannelPayload, client: Client) { | ||||
|   static from ( | ||||
|     data: | ||||
|       | GuildChannelCategoryPayload | ||||
|       | GuildNewsChannelPayload | ||||
|       | GuildTextChannelPayload | ||||
|       | GuildVoiceChannelPayload | ||||
|       | DMChannelPayload | ||||
|       | GroupDMChannelPayload, | ||||
|     client: Client | ||||
|   ) { | ||||
|     switch (data.type) { | ||||
|       case ChannelTypes.GUILD_CATEGORY: | ||||
|         return | ||||
|       case ChannelTypes.GUILD_NEWS: | ||||
|         return | ||||
|       case ChannelTypes.GUILD_TEXT: | ||||
|         return new TextChannel(client, data) | ||||
|         return new TextChannel(client, data as GuildTextChannelPayload) | ||||
|       case ChannelTypes.GUILD_VOICE: | ||||
|         return new VoiceChannel(client, data as GuildVoiceChannelPayload) | ||||
|       case ChannelTypes.DM: | ||||
|         return new PrivateChannel(client, data) | ||||
|         return new DMChannel(client, data as DMChannelPayload) | ||||
|       case ChannelTypes.GROUP_DM: | ||||
|         return new GroupChannel(client, data as GroupDMChannelPayload) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,9 +1,13 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { ChannelPayload } from '../types/channelTypes.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| import { DMChannelPayload } from '../types/channelTypes.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { TextChannel } from './textChannel.ts' | ||||
| 
 | ||||
| export class PrivateChannel extends Channel implements ChannelPayload { | ||||
|   constructor (client: Client, data: ChannelPayload) { | ||||
| export class DMChannel extends TextChannel { | ||||
|   recipients: UserPayload[] | ||||
| 
 | ||||
|   constructor (client: Client, data: DMChannelPayload) { | ||||
|     super(client, data) | ||||
|     this.recipients = data.recipients | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ import { | |||
| } from '../types/channelTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| 
 | ||||
| export class Embed extends Base implements EmbedPayload { | ||||
| export class Embed extends Base { | ||||
|   title?: string | ||||
|   type?: EmbedTypes | ||||
|   description?: string | ||||
|  |  | |||
|  | @ -1,21 +1,22 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { EmojiPayload } from '../types/emojiTypes.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| import { User } from './user.ts' | ||||
| 
 | ||||
| export class Emoji extends Base implements EmojiPayload { | ||||
| export class Emoji extends Base { | ||||
|   id: string | ||||
|   name: string | ||||
|   roles?: [] | ||||
|   user?: User | ||||
|   require_colons?: boolean | ||||
|   user?: UserPayload | ||||
|   requireColons?: boolean | ||||
|   managed?: boolean | ||||
|   animated?: boolean | ||||
|   available?: boolean | ||||
| 
 | ||||
|   get CustomEmoji () { | ||||
|     if (this.animated === false) { | ||||
|      return `<:${this.name}:${this.id}>` | ||||
|       return `<:${this.name}:${this.id}>` | ||||
|     } else return `<a:${this.name}:${this.id}>` | ||||
|   } | ||||
| 
 | ||||
|  | @ -25,7 +26,7 @@ export class Emoji extends Base implements EmojiPayload { | |||
|     this.name = data.name | ||||
|     this.roles = data.roles | ||||
|     this.user = data.user | ||||
|     this.require_colons = data.require_colons | ||||
|     this.requireColons = data.require_colons | ||||
|     this.managed = data.managed | ||||
|     this.animated = data.animated | ||||
|     this.available = data.available | ||||
|  |  | |||
							
								
								
									
										17
									
								
								src/structures/groupChannel.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/structures/groupChannel.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { GroupDMChannelPayload } from '../types/channelTypes.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| 
 | ||||
| export class GroupChannel extends Channel { | ||||
|   name: string | ||||
|   icon?: string | ||||
|   ownerID: string | ||||
| 
 | ||||
|   constructor (client: Client, data: GroupDMChannelPayload) { | ||||
|     super(client, data) | ||||
| 
 | ||||
|     this.name = data.name | ||||
|     this.icon = data.icon | ||||
|     this.ownerID = data.owner_id | ||||
|   } | ||||
| } | ||||
|  | @ -1,106 +1,129 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { ChannelPayload } from '../types/channelTypes.ts' | ||||
| import { EmojiPayload } from '../types/emojiTypes.ts' | ||||
| import { GuildFeatures, GuildPayload } from '../types/guildTypes.ts' | ||||
| import { GUILD } from '../types/endpoint.ts' | ||||
| import { | ||||
|   GuildFeatures, | ||||
|   GuildPayload, | ||||
|   MemberPayload | ||||
| } from '../types/guildTypes.ts' | ||||
| import { PresenceUpdatePayload } from '../types/presenceTypes.ts' | ||||
| import { RolePayload } from '../types/roleTypes.ts' | ||||
| import { VoiceStatePayload } from '../types/voiceTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| import { Emoji } from './emoji.ts' | ||||
| import { Member } from './member.ts' | ||||
| import { Role } from './role.ts' | ||||
| import * as cache from '../models/cache.ts' | ||||
| 
 | ||||
| export class Guild extends Base implements GuildPayload { | ||||
| export class Guild extends Base { | ||||
|   id: string | ||||
|   name: string | ||||
|   icon: string | undefined | ||||
|   icon_hash?: string | undefined | ||||
|   splash: string | undefined | ||||
|   discovery_splash: string | undefined | ||||
|   owner?: boolean | undefined | ||||
|   owner_id: string | ||||
|   permissions?: string | undefined | ||||
|   icon?: string | ||||
|   iconHash?: string | ||||
|   splash?: string | ||||
|   discoverySplash?: string | ||||
|   owner?: boolean | ||||
|   ownerID: string | ||||
|   permissions?: string | ||||
|   region: string | ||||
|   afk_channel_id: string | undefined | ||||
|   afk_timeout: number | ||||
|   widget_enabled?: boolean | undefined | ||||
|   widge_channel_id?: string | undefined | ||||
|   verification_level: string | ||||
|   default_message_notifications: string | ||||
|   explicit_content_filter: string | ||||
|   roles: Role[] | ||||
|   emojis: Emoji[] | ||||
|   afkChannelID?: string | ||||
|   afkTimeout: number | ||||
|   widgetEnabled?: boolean | ||||
|   widgetChannelID?: string | ||||
|   verificationLevel: string | ||||
|   defaultMessageNotifications: string | ||||
|   explicitContentFilter: string | ||||
|   roles: RolePayload[] | ||||
|   emojis: EmojiPayload[] | ||||
|   features: GuildFeatures[] | ||||
|   mfa_level: string | ||||
|   application_id: string | undefined | ||||
|   system_channel_id: string | undefined | ||||
|   system_channel_flags: string | ||||
|   rules_channel_id: string | undefined | ||||
|   joined_at?: string | undefined | ||||
|   large?: boolean | undefined | ||||
|   mfaLevel: string | ||||
|   applicationID?: string | ||||
|   systemChannelID?: string | ||||
|   systemChannelFlags: string | ||||
|   rulesChannelID?: string | ||||
|   joinedAt?: string | ||||
|   large?: boolean | ||||
|   unavailable: boolean | ||||
|   member_count?: number | undefined | ||||
|   voice_states?: VoiceStatePayload[] | undefined | ||||
|   members?: Member[] | undefined | ||||
|   channels?: Channel[] | undefined | ||||
|   presences?: PresenceUpdatePayload[] | undefined | ||||
|   max_presences?: number | undefined | ||||
|   max_members?: number | undefined | ||||
|   vanity_url_code: string | undefined | ||||
|   description: string | undefined | ||||
|   banner: string | undefined | ||||
|   premium_tier: number | ||||
|   premium_subscription_count?: number | undefined | ||||
|   preferred_locale: string | ||||
|   public_updates_channel_id: string | undefined | ||||
|   max_video_channel_users?: number | undefined | ||||
|   approximate_number_count?: number | undefined | ||||
|   approximate_presence_count?: number | undefined | ||||
|   memberCount?: number | ||||
|   voiceStates?: VoiceStatePayload[] | ||||
|   members?: MemberPayload[] | ||||
|   channels?: ChannelPayload[] | ||||
|   presences?: PresenceUpdatePayload[] | ||||
|   maxPresences?: number | ||||
|   maxMembers?: number | ||||
|   vanityURLCode?: string | ||||
|   description?: string | ||||
|   banner?: string | ||||
|   premiumTier: number | ||||
|   premiumSubscriptionCount?: number | ||||
|   preferredLocale: string | ||||
|   publicUpdatesChannelID?: string | ||||
|   maxVideoChannelUsers?: number | ||||
|   approximateNumberCount?: number | ||||
|   approximatePresenceCount?: number | ||||
| 
 | ||||
|   constructor (client: Client, data: GuildPayload) { | ||||
|     super(client) | ||||
|     this.id = data.id | ||||
|     this.name = data.name | ||||
|     this.icon = data.icon | ||||
|     this.icon_hash = data.icon_hash | ||||
|     this.iconHash = data.icon_hash | ||||
|     this.splash = data.splash | ||||
|     this.discovery_splash = data.discovery_splash | ||||
|     this.discoverySplash = data.discovery_splash | ||||
|     this.owner = data.owner | ||||
|     this.owner_id = data.owner_id | ||||
|     this.ownerID = data.owner_id | ||||
|     this.permissions = data.permissions | ||||
|     this.region = data.region | ||||
|     this.afk_timeout = data.afk_timeout | ||||
|     this.afk_channel_id = data.afk_channel_id | ||||
|     this.widget_enabled = data.widget_enabled | ||||
|     this.widge_channel_id = data.widge_channel_id | ||||
|     this.verification_level = data.verification_level | ||||
|     this.default_message_notifications = data.default_message_notifications | ||||
|     this.explicit_content_filter = data.explicit_content_filter | ||||
|     this.afkTimeout = data.afk_timeout | ||||
|     this.afkChannelID = data.afk_channel_id | ||||
|     this.widgetEnabled = data.widget_enabled | ||||
|     this.widgetChannelID = data.widge_channel_id | ||||
|     this.verificationLevel = data.verification_level | ||||
|     this.defaultMessageNotifications = data.default_message_notifications | ||||
|     this.explicitContentFilter = data.explicit_content_filter | ||||
|     this.roles = data.roles | ||||
|     this.emojis = data.emojis | ||||
|     this.features = data.features | ||||
|     this.mfa_level = data.mfa_level | ||||
|     this.system_channel_id = data.system_channel_id | ||||
|     this.system_channel_flags = data.system_channel_flags | ||||
|     this.rules_channel_id = data.rules_channel_id | ||||
|     this.joined_at = data.joined_at | ||||
|     this.mfaLevel = data.mfa_level | ||||
|     this.systemChannelID = data.system_channel_id | ||||
|     this.systemChannelFlags = data.system_channel_flags | ||||
|     this.rulesChannelID = data.rules_channel_id | ||||
|     this.joinedAt = data.joined_at | ||||
|     this.large = data.large | ||||
|     this.unavailable = data.unavailable | ||||
|     this.member_count = data.member_count | ||||
|     this.voice_states = data.voice_states | ||||
|     this.memberCount = data.member_count | ||||
|     this.voiceStates = data.voice_states | ||||
|     this.members = data.members | ||||
|     this.channels = data.channels | ||||
|     this.presences = data.presences | ||||
|     this.max_presences = data.max_presences | ||||
|     this.max_members = data.max_members | ||||
|     this.vanity_url_code = data.vanity_url_code | ||||
|     this.maxPresences = data.max_presences | ||||
|     this.maxMembers = data.max_members | ||||
|     this.vanityURLCode = data.vanity_url_code | ||||
|     this.description = data.description | ||||
|     this.banner = data.banner | ||||
|     this.premium_tier = data.premium_tier | ||||
|     this.premium_subscription_count = data.premium_subscription_count | ||||
|     this.preferred_locale = data.preferred_locale | ||||
|     this.public_updates_channel_id = data.public_updates_channel_id | ||||
|     this.max_video_channel_users = data.max_video_channel_users | ||||
|     this.approximate_number_count = data.approximate_number_count | ||||
|     this.approximate_presence_count = data.approximate_presence_count | ||||
|     this.premiumTier = data.premium_tier | ||||
|     this.premiumSubscriptionCount = data.premium_subscription_count | ||||
|     this.preferredLocale = data.preferred_locale | ||||
|     this.publicUpdatesChannelID = data.public_updates_channel_id | ||||
|     this.maxVideoChannelUsers = data.max_video_channel_users | ||||
|     this.approximateNumberCount = data.approximate_number_count | ||||
|     this.approximatePresenceCount = data.approximate_presence_count | ||||
|   } | ||||
| 
 | ||||
|   static async autoInit (client: Client, guildID: string) { | ||||
|     const cached = cache.get('guilds', guildID) | ||||
|     if (cached === undefined || !(cached instanceof Guild)) { | ||||
|       const resp = await fetch(GUILD(guildID), { | ||||
|         headers: { | ||||
|           Authorization: `Bot ${client.token}` | ||||
|         } | ||||
|       }) | ||||
|       const guildParsed: GuildPayload = await resp.json() | ||||
| 
 | ||||
|       const newGuild = new Guild(client, guildParsed) | ||||
|       cache.set('guilds', guildID, newGuild) | ||||
|       return newGuild | ||||
|     } else { | ||||
|       return cached | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,9 +1,22 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { ChannelPayload } from '../types/channelTypes.ts' | ||||
| import { GuildChannelPayload, Overwrite } from '../types/channelTypes.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| 
 | ||||
| export class GuildChannel extends Channel { | ||||
|   constructor (client: Client, data: ChannelPayload) { | ||||
|   guildID: string | ||||
|   name: string | ||||
|   position: number | ||||
|   permissionOverwrites: Overwrite[] | ||||
|   nsfw: boolean | ||||
|   parentID?: string | ||||
| 
 | ||||
|   constructor (client: Client, data: GuildChannelPayload) { | ||||
|     super(client, data) | ||||
|     this.guildID = data.guild_id | ||||
|     this.name = data.name | ||||
|     this.position = data.position | ||||
|     this.permissionOverwrites = data.permission_overwrites | ||||
|     this.nsfw = data.nsfw | ||||
|     this.parentID = data.parent_id | ||||
|   } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										19
									
								
								src/structures/guildTextChannel.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/structures/guildTextChannel.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { GuildChannel } from './guildChannel.ts' | ||||
| import { GuildTextChannelPayload } from '../types/channelTypes.ts' | ||||
| import { User } from './user.ts' | ||||
| 
 | ||||
| export class GuildTextChannel extends GuildChannel { | ||||
|   rateLimit: number | ||||
|   topic?: string | ||||
| 
 | ||||
|   get mention () { | ||||
|     return `<#${this.id}>` | ||||
|   } | ||||
| 
 | ||||
|   constructor (client: Client, data: GuildTextChannelPayload) { | ||||
|     super(client, data) | ||||
|     this.topic = data.topic | ||||
|     this.rateLimit = data.rate_limit_per_user | ||||
|   } | ||||
| } | ||||
							
								
								
									
										28
									
								
								src/structures/guildVoiceChannel.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/structures/guildVoiceChannel.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { GuildVoiceChannelPayload, Overwrite } from '../types/channelTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| import { Member } from './member.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| 
 | ||||
| export class VoiceChannel extends Channel { | ||||
|   bitrate: string | ||||
|   userLimit: number | ||||
|   guildID: string | ||||
|   name: string | ||||
|   position: number | ||||
|   permissionOverwrites: Overwrite[] | ||||
|   nsfw: boolean | ||||
|   parentID?: string | ||||
| 
 | ||||
|   constructor (client: Client, data: GuildVoiceChannelPayload) { | ||||
|     super(client, data) | ||||
|     this.bitrate = data.bitrate | ||||
|     this.userLimit = data.user_limit | ||||
|     this.guildID = data.guild_id | ||||
|     this.name = data.name | ||||
|     this.position = data.position | ||||
|     this.permissionOverwrites = data.permission_overwrites | ||||
|     this.nsfw = data.nsfw | ||||
|     this.parentID = data.parent_id | ||||
|   } | ||||
| } | ||||
|  | @ -2,22 +2,24 @@ import { Client } from '../models/client.ts' | |||
| import { Channel } from '../structures/channel.ts' | ||||
| import { Guild } from '../structures/guild.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { ChannelPayload } from '../types/channelTypes.ts' | ||||
| import { GuildPayload } from '../types/guildTypes.ts' | ||||
| import { InvitePayload } from '../types/inviteTypes.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| 
 | ||||
| export class Invite extends Base implements InvitePayload { | ||||
| export class Invite extends Base { | ||||
|   code: string | ||||
|   guild?: Guild | ||||
|   channel: Channel | ||||
|   inviter?: User | ||||
|   target_user?: User | ||||
|   target_user_type?: number | ||||
|   approximate_presence_count?: number | ||||
|   approximate_member_count?: number | ||||
| 
 | ||||
|   guild?: GuildPayload | ||||
|   channel: ChannelPayload | ||||
|   inviter?: UserPayload | ||||
|   targetUser?: UserPayload | ||||
|   targetUserType?: number | ||||
|   approximatePresenceCount?: number | ||||
|   approximateMemberCount?: number | ||||
| 
 | ||||
|   get link () { | ||||
|     return `discord.gg/${this.code}` | ||||
|     return `https://discord.gg/${this.code}` | ||||
|   } | ||||
| 
 | ||||
|   constructor (client: Client, data: InvitePayload) { | ||||
|  | @ -26,9 +28,9 @@ export class Invite extends Base implements InvitePayload { | |||
|     this.guild = data.guild | ||||
|     this.channel = data.channel | ||||
|     this.inviter = data.inviter | ||||
|     this.target_user = data.target_user | ||||
|     this.target_user_type = data.target_user_type | ||||
|     this.approximate_member_count = data.approximate_member_count | ||||
|     this.approximate_presence_count = data.approximate_presence_count | ||||
|     this.targetUser = data.target_user | ||||
|     this.targetUserType = data.target_user_type | ||||
|     this.approximateMemberCount = data.approximate_member_count | ||||
|     this.approximatePresenceCount = data.approximate_presence_count | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,17 +1,18 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { MemberPayload } from '../types/guildTypes.ts' | ||||
| import { RolePayload } from '../types/roleTypes.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| import { Guild } from './guild.ts' | ||||
| import { Role } from './role.ts' | ||||
| import { User } from './user.ts' | ||||
| 
 | ||||
| export class Member extends Base implements MemberPayload { | ||||
|   user: User | ||||
|   nick: string | undefined | ||||
|   roles: Role[] | ||||
|   joined_at: string | ||||
|   premium_since?: string | undefined | ||||
| export class Member extends Base { | ||||
|   user: UserPayload | ||||
|   nick?: string | ||||
|   roles: RolePayload[] | ||||
|   joinedAt: string | ||||
|   premiumSince?: string | ||||
|   deaf: boolean | ||||
|   mute: boolean | ||||
| 
 | ||||
|  | @ -20,8 +21,8 @@ export class Member extends Base implements MemberPayload { | |||
|     this.user = data.user | ||||
|     this.nick = data.nick | ||||
|     this.roles = data.roles | ||||
|     this.joined_at = data.joined_at | ||||
|     this.premium_since = data.premium_since | ||||
|     this.joinedAt = data.joined_at | ||||
|     this.premiumSince = data.premium_since | ||||
|     this.deaf = data.deaf | ||||
|     this.mute = data.mute | ||||
|   } | ||||
|  |  | |||
|  | @ -13,57 +13,59 @@ import { Client } from '../models/client.ts' | |||
| import { User } from './user.ts' | ||||
| import { Role } from './role.ts' | ||||
| import { Embed } from './embed.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { RolePayload } from '../types/roleTypes.ts' | ||||
| 
 | ||||
| class Message extends Base implements MessagePayload { | ||||
| class Message extends Base { | ||||
|   id: string | ||||
|   channel_id: string | ||||
|   guild_id?: string | undefined | ||||
|   author: User | ||||
|   channelID: string | ||||
|   guildID?: string | ||||
|   author: UserPayload | ||||
|   member?: any | ||||
|   content: string | ||||
|   timestamp: string | ||||
|   edited_timestamp: string | undefined | ||||
|   editedTimestamp?: string | ||||
|   tts: boolean | ||||
|   mention_everyone: boolean | ||||
|   mentions: User[] | ||||
|   mention_roles: Role[] | ||||
|   mention_channels?: ChannelMention[] | undefined | ||||
|   mentionEveryone: boolean | ||||
|   mentions: UserPayload[] | ||||
|   mentionRoles: RolePayload[] | ||||
|   mentionChannels?: ChannelMention[] | ||||
|   attachments: Attachment[] | ||||
|   embeds: EmbedPayload[] | ||||
|   reactions?: Reaction[] | undefined | ||||
|   nonce?: string | number | undefined | ||||
|   reactions?: Reaction[] | ||||
|   nonce?: string | number | ||||
|   pinned: boolean | ||||
|   webhook_id?: string | undefined | ||||
|   webhookId?: string | ||||
|   type: number | ||||
|   activity?: MessageActivity | ||||
|   application?: MessageApplication | ||||
|   message_reference?: MessageReference | ||||
|   flags?: number | undefined | ||||
|   messageReference?: MessageReference | ||||
|   flags?: number | ||||
| 
 | ||||
|   constructor (client: Client, data: MessagePayload) { | ||||
|     super(client) | ||||
|     this.id = data.id | ||||
|     this.channel_id = data.channel_id | ||||
|     this.guild_id = data.guild_id | ||||
|     this.channelID = data.channel_id | ||||
|     this.guildID = data.guild_id | ||||
|     this.author = data.author | ||||
|     this.member = data.member | ||||
|     this.content = data.content | ||||
|     this.timestamp = data.timestamp | ||||
|     this.edited_timestamp = data.edited_timestamp | ||||
|     this.editedTimestamp = data.edited_timestamp | ||||
|     this.tts = data.tts | ||||
|     this.mention_everyone = data.mention_everyone | ||||
|     this.mentionEveryone = data.mention_everyone | ||||
|     this.mentions = data.mentions | ||||
|     this.mention_roles = data.mention_roles | ||||
|     this.mentionRoles = data.mention_roles | ||||
|     this.attachments = data.attachments | ||||
|     this.embeds = data.embeds | ||||
|     this.reactions = data.reactions | ||||
|     this.nonce = data.nonce | ||||
|     this.pinned = data.pinned | ||||
|     this.webhook_id = data.webhook_id | ||||
|     this.webhookId = data.webhook_id | ||||
|     this.type = data.type | ||||
|     this.activity = data.activity | ||||
|     this.application = data.application | ||||
|     this.message_reference = data.message_reference | ||||
|     this.messageReference = data.message_reference | ||||
|     this.flags = data.flags | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { Client } from '../models/client.ts' | |||
| import { Base } from './base.ts' | ||||
| import { RolePayload } from '../types/roleTypes.ts' | ||||
| 
 | ||||
| export class Role extends Base implements RolePayload { | ||||
| export class Role extends Base { | ||||
|   id: string | ||||
|   name: string | ||||
|   color: number | ||||
|  |  | |||
|  | @ -1,36 +1,16 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { GuildChannel } from './guildChannel.ts' | ||||
| import { ChannelPayload } from '../types/channelTypes.ts' | ||||
| import { User } from './user.ts' | ||||
| import { TextChannelPayload } from '../types/channelTypes.ts' | ||||
| import { Channel } from './channel.ts' | ||||
| import { Embed } from './embed.ts' | ||||
| export class TextChannel extends Channel { | ||||
|   lastMessageId?: string | ||||
|   lastPinTimestamp?: string | ||||
| 
 | ||||
| export class TextChannel extends GuildChannel implements ChannelPayload { | ||||
|   id: string | ||||
|   type: number | ||||
|   guild_id?: string | undefined | ||||
|   position?: number | undefined | ||||
|   approximate_member_count?: any | ||||
|   name?: string | undefined | ||||
|   topic?: string | undefined | ||||
|   nsfw?: boolean | undefined | ||||
|   last_message_id?: string | undefined | ||||
|   bitrate?: number | undefined | ||||
|   user_limit?: number | undefined | ||||
|   rate_limit_per_user?: number | undefined | ||||
|   recipients?: User | ||||
|   icon?: string | undefined | ||||
|   owner_id?: string | undefined | ||||
|   application_id?: string | undefined | ||||
|   parent_id?: string | undefined | ||||
|   last_pin_timestamp?: string | undefined | ||||
| 
 | ||||
| 
 | ||||
|   get mention () { | ||||
|     return `<#${this.id}>` | ||||
|   } | ||||
| 
 | ||||
|   constructor (client: Client, data: ChannelPayload) { | ||||
|   constructor (client: Client, data: TextChannelPayload) { | ||||
|     super(client, data) | ||||
|     this.id = data.id | ||||
|     this.type = data.type | ||||
|     this.lastMessageId = data.last_message_id | ||||
|     this.lastPinTimestamp = data.last_pin_timestamp | ||||
|   } | ||||
| 
 | ||||
|   send (content: string | Embed, option?: {}) {} //TODO: send function
 | ||||
| } | ||||
|  |  | |||
|  | @ -2,20 +2,20 @@ import { Client } from '../models/client.ts' | |||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { Base } from './base.ts' | ||||
| 
 | ||||
| export class User extends Base implements UserPayload { | ||||
| export class User extends Base { | ||||
|   id: string | ||||
|   username: string | ||||
|   discriminator: string | ||||
|   avatar?: string | ||||
|   bot?: boolean | ||||
|   system?: boolean | ||||
|   mfa_enabled?: boolean | ||||
|   mfaEnabled?: boolean | ||||
|   locale?: string | ||||
|   verified?: boolean | ||||
|   email?: string | ||||
|   flags?: number | ||||
|   premium_type?: 0 | 1 | 2 | ||||
|   public_flags?: number | ||||
|   premiumType?: 0 | 1 | 2 | ||||
|   publicFlags?: number | ||||
| 
 | ||||
|   get nickMention () { | ||||
|     return `<@!${this.id}>` | ||||
|  | @ -33,12 +33,12 @@ export class User extends Base implements UserPayload { | |||
|     this.avatar = data.avatar | ||||
|     this.bot = data.bot | ||||
|     this.system = data.system | ||||
|     this.mfa_enabled = data.mfa_enabled | ||||
|     this.mfaEnabled = data.mfa_enabled | ||||
|     this.locale = data.locale | ||||
|     this.verified = data.verified | ||||
|     this.email = data.email | ||||
|     this.flags = data.flags | ||||
|     this.premium_type = data.premium_type | ||||
|     this.public_flags = data.public_flags | ||||
|     this.premiumType = data.premium_type | ||||
|     this.publicFlags = data.public_flags | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,33 +1,34 @@ | |||
| import { Client } from "../models/client.ts" | ||||
| import { VoiceStatePayload } from "../types/voiceTypes.ts" | ||||
| import { Base } from "./base.ts" | ||||
| import { Member } from "./member.ts" | ||||
| import { Client } from '../models/client.ts' | ||||
| import { MemberPayload } from '../types/guildTypes.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 | ||||
| export class VoiceState extends Base { | ||||
|   guildID?: string | ||||
|   channelID?: string | ||||
|   userID: string | ||||
|   member?: MemberPayload | ||||
|   sessionID: string | ||||
|   deaf: boolean | ||||
|   mute: boolean | ||||
|   selfDeaf: boolean | ||||
|   selfMute: boolean | ||||
|   selfStream?: boolean | ||||
|   selfVideo: 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 | ||||
|     } | ||||
| } | ||||
|   constructor (client: Client, data: VoiceStatePayload) { | ||||
|     super(client) | ||||
|     this.channelID = data.channel_id | ||||
|     this.sessionID = data.session_id | ||||
|     this.userID = data.user_id | ||||
|     this.deaf = data.deaf | ||||
|     this.mute = data.mute | ||||
|     this.selfDeaf = data.self_deaf | ||||
|     this.selfMute = data.self_mute | ||||
|     this.selfStream = data.self_stream | ||||
|     this.selfVideo = data.self_video | ||||
|     this.suppress = data.suppress | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,23 +1,23 @@ | |||
| import { Client } from "../models/client.ts" | ||||
| import { WebhookPayload } from "../types/webhookTypes.ts" | ||||
| import { Base } from "./base.ts" | ||||
| import { User } from "./user.ts" | ||||
| import { Client } from '../models/client.ts' | ||||
| import { UserPayload } from '../types/userTypes.ts' | ||||
| import { WebhookPayload } from '../types/webhookTypes.ts' | ||||
| import { Base } from './base.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 | ||||
| export class Webhook extends Base { | ||||
|   id: string | ||||
|   type: 1 | 2 | ||||
|   guildID?: string | ||||
|   channelID: string | ||||
|   user?: UserPayload | ||||
|   name?: string | ||||
|   avatar?: string | ||||
|   token?: string | ||||
|   applicationID?: string | ||||
| 
 | ||||
|     constructor (client: Client, data: WebhookPayload) { | ||||
|         super(client) | ||||
|         this.id = data.id | ||||
|         this.type = data.type | ||||
|         this.channel_id = data.channel_id | ||||
|     } | ||||
| } | ||||
|   constructor (client: Client, data: WebhookPayload) { | ||||
|     super(client) | ||||
|     this.id = data.id | ||||
|     this.type = data.type | ||||
|     this.channelID = data.channel_id | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -1,7 +1,15 @@ | |||
| import { Client } from '../models/client.ts' | ||||
| import { Guild } from '../structures/guild.ts' | ||||
| import { GatewayIntents } from '../types/gatewayTypes.ts' | ||||
| import { TOKEN } from './config.ts' | ||||
| 
 | ||||
| const bot = new Client() | ||||
| 
 | ||||
| bot.connect(TOKEN, [GatewayIntents.GUILD_MESSAGES]) | ||||
| 
 | ||||
| Guild.autoInit(bot, '').then(a => console.log(a)) | ||||
| 
 | ||||
| setTimeout(async () => { | ||||
|   const result = Guild.autoInit(bot, '') | ||||
|   console.log(result) | ||||
| }, 30000) | ||||
|  |  | |||
|  | @ -1,29 +1,59 @@ | |||
| import { Member } from '../structures/member.ts' | ||||
| import { Role } from '../structures/role.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { EmojiPayload } from './emojiTypes.ts' | ||||
| import { MemberPayload } from './guildTypes.ts' | ||||
| import { RolePayload } from './roleTypes.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| interface ChannelPayload { | ||||
|   id: string | ||||
|   type: ChannelTypes | ||||
|   guild_id?: string | ||||
|   position?: number | ||||
|   approximate_member_count?: Overwrite | ||||
|   name?: string | ||||
|   topic?: string | ||||
|   nsfw?: boolean | ||||
| } | ||||
| 
 | ||||
| interface TextChannelPayload extends ChannelPayload { | ||||
|   last_message_id?: string | ||||
|   bitrate?: number | ||||
|   user_limit?: number | ||||
|   rate_limit_per_user?: number | ||||
|   recipients?: User | ||||
|   icon?: string | ||||
|   owner_id?: string | ||||
|   application_id?: string | ||||
|   parent_id?: string | ||||
|   last_pin_timestamp?: string | ||||
| } | ||||
| 
 | ||||
| interface GuildChannelPayload extends ChannelPayload { | ||||
|   guild_id: string | ||||
|   name: string | ||||
|   position: number | ||||
|   permission_overwrites: Overwrite[] | ||||
|   nsfw: boolean | ||||
|   parent_id?: string | ||||
| } | ||||
| 
 | ||||
| interface GuildTextChannelPayload | ||||
|   extends TextChannelPayload, | ||||
|     GuildChannelPayload { | ||||
|   rate_limit_per_user: number | ||||
|   topic?: string | ||||
| } | ||||
| 
 | ||||
| interface GuildNewsChannelPayload | ||||
|   extends TextChannelPayload, | ||||
|     GuildChannelPayload { | ||||
|   topic?: string | ||||
| } | ||||
| 
 | ||||
| interface GuildVoiceChannelPayload extends GuildChannelPayload { | ||||
|   bitrate: string | ||||
|   user_limit: number | ||||
| } | ||||
| 
 | ||||
| interface DMChannelPayload extends TextChannelPayload { | ||||
|   recipients: UserPayload[] | ||||
| } | ||||
| 
 | ||||
| interface GroupDMChannelPayload extends DMChannelPayload { | ||||
|   name: string | ||||
|   icon?: string | ||||
|   owner_id: string | ||||
| } | ||||
| 
 | ||||
| interface GuildChannelCategoryPayload | ||||
|   extends ChannelPayload, | ||||
|     GuildChannelPayload {} | ||||
| 
 | ||||
| interface Overwrite { | ||||
|   id: string | ||||
|   type: number | ||||
|  | @ -45,15 +75,15 @@ interface MessagePayload { | |||
|   id: string | ||||
|   channel_id: string | ||||
|   guild_id?: string | ||||
|   author: User | ||||
|   member?: Member | ||||
|   author: UserPayload | ||||
|   member?: MemberPayload | ||||
|   content: string | ||||
|   timestamp: string | ||||
|   edited_timestamp: string | undefined | ||||
|   edited_timestamp?: string | ||||
|   tts: boolean | ||||
|   mention_everyone: boolean | ||||
|   mentions: User[] | ||||
|   mention_roles: Role[] | ||||
|   mentions: UserPayload[] | ||||
|   mention_roles: RolePayload[] | ||||
|   mention_channels?: ChannelMention[] | ||||
|   attachments: Attachment[] | ||||
|   embeds: EmbedPayload[] | ||||
|  | @ -210,12 +240,6 @@ interface FollowedChannel { | |||
|   webhook_id: string | ||||
| } | ||||
| 
 | ||||
| interface Reaction { | ||||
|   count: number | ||||
|   me: boolean | ||||
|   emoji: EmojiPayload | ||||
| } | ||||
| 
 | ||||
| interface Overwrite { | ||||
|   id: string | ||||
|   type: number | ||||
|  | @ -231,6 +255,15 @@ interface ChannelMention { | |||
| 
 | ||||
| export { | ||||
|   ChannelPayload, | ||||
|   TextChannelPayload, | ||||
|   GuildChannelPayload, | ||||
|   GuildNewsChannelPayload, | ||||
|   GuildTextChannelPayload, | ||||
|   GuildVoiceChannelPayload, | ||||
|   GuildChannelCategoryPayload, | ||||
|   DMChannelPayload, | ||||
|   GroupDMChannelPayload, | ||||
|   Overwrite, | ||||
|   ChannelTypes, | ||||
|   ChannelMention, | ||||
|   Attachment, | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| import { User } from '../structures/user.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| export interface EmojiPayload { | ||||
|   id: string | ||||
|   name: string | ||||
|   roles?: [] | ||||
|   user?: User | ||||
|   user?: UserPayload | ||||
|   require_colons?: boolean | ||||
|   managed?: boolean | ||||
|   animated?: boolean | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ import { | |||
| } from '../consts/urlsAndVersions.ts' | ||||
| 
 | ||||
| //Guild Endpoints
 | ||||
| const GUILDS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds` | ||||
| const GUILDS = () => `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds` | ||||
| const GUILD = (guildID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}` | ||||
| const GUILD_AUDIT_LOGS = (guildID: string) => | ||||
|  | @ -60,10 +60,10 @@ const CHANNEL = (channelID: string) => | |||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}` | ||||
| const CHANNELS = (channelID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${channelID}/channels` | ||||
| const CHANNEL_MESSAGES = (channelID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages` | ||||
| const CHANNEL_MESSAGE = (channelID: string, messageID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}` | ||||
| const CHANNEL_MESSAGES = (channelID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages` | ||||
| const CHANNEL_CROSSPOST = (channelID: string, messageID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}/crosspost` | ||||
| const MESSAGE_REACTIONS = (channelID: string, messageID: string) => | ||||
|  | @ -105,10 +105,14 @@ const GROUP_RECIPIENT = (channelID: string, userID: string) => | |||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/recipient/${userID}` | ||||
| 
 | ||||
| //User Endpoints
 | ||||
| const CURRENT_USER = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me` | ||||
| const CURRENT_USER_GUILDS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds` | ||||
| const USER_DM = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/channels` | ||||
| const USER_CONNECTIONS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/connections` | ||||
| const CURRENT_USER = () => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me` | ||||
| const CURRENT_USER_GUILDS = () => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds` | ||||
| const USER_DM = () => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/channels` | ||||
| const USER_CONNECTIONS = () => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/connections` | ||||
| const LEAVE_GUILD = (guildID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds/${guildID}` | ||||
| const USER = (userID: string) => | ||||
|  | @ -129,12 +133,12 @@ const GITHUB_WEBHOOK = (webhookID: string, webhookTOKEN: string) => | |||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${webhookID}/${webhookTOKEN}/github` | ||||
| 
 | ||||
| //Gateway Endpoints
 | ||||
| const GATEWAY = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway` | ||||
| const GATEWAY_BOT = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot` | ||||
| const GATEWAY = () => `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway` | ||||
| const GATEWAY_BOT = () => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot` | ||||
| 
 | ||||
| //CDN Endpoints
 | ||||
| const CUSTOM_EMOJI = (emojiID: string) => | ||||
|   `${DISCORD_CDN_URL}/emojis/${emojiID}` | ||||
| const CUSTOM_EMOJI = (emojiID: string) => `${DISCORD_CDN_URL}/emojis/${emojiID}` | ||||
| const GUILD_ICON = (guildID: string, iconID: number) => | ||||
|   `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}` | ||||
| const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => | ||||
|  | @ -142,8 +146,7 @@ const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => | |||
| const GUILD_DISCOVERY_SPLASH = ( | ||||
|   guildID: string, | ||||
|   guildDiscoverySplash: string | ||||
| ) => | ||||
|   `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}` | ||||
| ) => `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}` | ||||
| const GUILD_BANNER = (guildID: string, guildBANNER: string) => | ||||
|   `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}` | ||||
| const DEFAULT_USER_AVATAR = (iconID: string) => | ||||
|  | @ -178,3 +181,75 @@ const INVITE = (inviteCODE: string) => | |||
| //Voice Endpoint
 | ||||
| const VOICE_REGIONS = (guildID: string) => | ||||
|   `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}/regions` | ||||
| 
 | ||||
| export { | ||||
|   GUILDS, | ||||
|   GUILD, | ||||
|   GUILD_AUDIT_LOGS, | ||||
|   GUILD_WIDGET, | ||||
|   GUILD_EMOJI, | ||||
|   GUILD_ROLE, | ||||
|   GUILD_ROLES, | ||||
|   GUILD_INTEGRATION, | ||||
|   GUILD_INTEGRATIONS, | ||||
|   GUILD_INTEGARTION_SYNC, | ||||
|   GUILD_BAN, | ||||
|   GUILD_BANS, | ||||
|   GUILD_CHANNEL, | ||||
|   GUILD_CHANNELS, | ||||
|   GUILD_MEMBER, | ||||
|   GUILD_MEMBERS, | ||||
|   GUILD_MEMBER_ROLE, | ||||
|   GUILD_INVITES, | ||||
|   GUILD_LEAVE, | ||||
|   GUILD_PRUNE, | ||||
|   GUILD_VANITY_URL, | ||||
|   GUILD_NICK, | ||||
|   GUILD_PREVIEW, | ||||
|   CHANNEL, | ||||
|   CHANNELS, | ||||
|   CHANNEL_MESSAGE, | ||||
|   CHANNEL_MESSAGES, | ||||
|   CHANNEL_CROSSPOST, | ||||
|   MESSAGE_REACTIONS, | ||||
|   MESSAGE_REACTION, | ||||
|   MESSAGE_REACTION_ME, | ||||
|   MESSAGE_REACTION_USER, | ||||
|   CHANNEL_BULK_DELETE, | ||||
|   CHANNEL_FOLLOW, | ||||
|   CHANNEL_INVITES, | ||||
|   CHANNEL_PIN, | ||||
|   CHANNEL_PINS, | ||||
|   CHANNEL_PERMISSION, | ||||
|   CHANNEL_TYPING, | ||||
|   GROUP_RECIPIENT, | ||||
|   CURRENT_USER, | ||||
|   CURRENT_USER_GUILDS, | ||||
|   USER_DM, | ||||
|   USER_CONNECTIONS, | ||||
|   LEAVE_GUILD, | ||||
|   USER, | ||||
|   CHANNEL_WEBHOOKS, | ||||
|   GUILD_WEBHOOK, | ||||
|   WEBHOOK, | ||||
|   WEBHOOK_WITH_TOKEN, | ||||
|   SLACK_WEBHOOK, | ||||
|   GITHUB_WEBHOOK, | ||||
|   GATEWAY, | ||||
|   GATEWAY_BOT, | ||||
|   CUSTOM_EMOJI, | ||||
|   GUILD_ICON, | ||||
|   GUILD_SPLASH, | ||||
|   GUILD_DISCOVERY_SPLASH, | ||||
|   GUILD_BANNER, | ||||
|   DEFAULT_USER_AVATAR, | ||||
|   USER_AVATAR, | ||||
|   APPLICATION_ASSET, | ||||
|   ACHIEVEMENT_ICON, | ||||
|   TEAM_ICON, | ||||
|   EMOJI, | ||||
|   EMOJIS, | ||||
|   TEMPLATE, | ||||
|   INVITE, | ||||
|   VOICE_REGIONS | ||||
| } | ||||
|  |  | |||
|  | @ -1,11 +1,10 @@ | |||
| // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
 | ||||
| // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
 | ||||
| import { Emoji } from '../structures/emoji.ts' | ||||
| import { Member } from '../structures/member.ts' | ||||
| import { Role } from '../structures/role.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { EmojiPayload } from './emojiTypes.ts' | ||||
| import { MemberPayload } from './guildTypes.ts' | ||||
| import { ActivityPayload, PresenceUpdatePayload } from './presenceTypes.ts' | ||||
| import { RolePayload } from './roleTypes.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| /** | ||||
|  * Gateway OPcodes from Discord docs. | ||||
|  | @ -124,7 +123,7 @@ enum UpdateStatus { | |||
| } | ||||
| 
 | ||||
| interface IdentityConnection { | ||||
|   $os: 'linux' | ||||
|   $os: 'darwin' | 'windows' | 'linux' | 'custom os' | ||||
|   $browser: 'discord.deno' | ||||
|   $device: 'discord.deno' | ||||
| } | ||||
|  | @ -139,7 +138,7 @@ interface GuildRequestMembers { | |||
|   guild_id: string | string[] | ||||
|   query?: string | ||||
|   limit: number | ||||
|   presences?: boolean //do you have any problems? tell me! i am so handsome
 | ||||
|   presences?: boolean | ||||
|   user_ids?: string | string[] | ||||
|   nonce?: string | ||||
| } | ||||
|  | @ -164,7 +163,7 @@ interface Hello { | |||
| 
 | ||||
| interface ReadyEvent { | ||||
|   v: number | ||||
|   user: User | ||||
|   user: UserPayload | ||||
|   privateChannels: [] | ||||
|   guilds: [] | ||||
|   session_id: string | ||||
|  | @ -179,12 +178,12 @@ interface ChannelPinsUpdate { | |||
| 
 | ||||
| interface GuildBanAdd { | ||||
|   guild_id: string | ||||
|   user: User | ||||
|   user: UserPayload | ||||
| } | ||||
| 
 | ||||
| interface GuildBanRemove { | ||||
|   guild_id: string | ||||
|   user: User | ||||
|   user: UserPayload | ||||
| } | ||||
| 
 | ||||
| interface GuildEmojiUpdate { | ||||
|  | @ -202,12 +201,12 @@ interface GuildMemberAddExtra { | |||
| 
 | ||||
| interface GuildMemberRemove { | ||||
|   guild_id: string | ||||
|   user: User | ||||
|   user: UserPayload | ||||
| } | ||||
| interface GuildMemberUpdate { | ||||
|   guild_id: string | ||||
|   roles: string[] | ||||
|   user: User | ||||
|   user: UserPayload | ||||
|   nick?: string | undefined | ||||
|   joined_at: string | ||||
|   premium_since?: string | undefined | ||||
|  | @ -225,12 +224,12 @@ interface GuildMemberChunk { | |||
| 
 | ||||
| interface GuildRoleCreate { | ||||
|   guild_id: string | ||||
|   role: Role | ||||
|   role: RolePayload | ||||
| } | ||||
| 
 | ||||
| interface GuildRoleUpdate { | ||||
|   guild_id: string | ||||
|   role: Role | ||||
|   role: RolePayload | ||||
| } | ||||
| 
 | ||||
| interface GuildRoleDelete { | ||||
|  | @ -243,10 +242,10 @@ interface InviteCreate { | |||
|   code: string | ||||
|   created_at: string | ||||
|   guild_id?: string | ||||
|   inviter?: User | ||||
|   inviter?: UserPayload | ||||
|   max_age: number | ||||
|   max_uses: number | ||||
|   target_user?: User | ||||
|   target_user?: UserPayload | ||||
|   target_user_type?: number | ||||
|   temporary: boolean | ||||
|   uses: number | ||||
|  | @ -275,7 +274,7 @@ interface MessageReactionAdd { | |||
|   channel_id: string | ||||
|   message_id: string | ||||
|   guild_id?: string | ||||
|   emoji: Emoji | ||||
|   emoji: EmojiPayload | ||||
| } | ||||
| 
 | ||||
| interface MessageReactionRemove { | ||||
|  | @ -283,25 +282,25 @@ interface MessageReactionRemove { | |||
|   channel_id: string | ||||
|   message_id: string | ||||
|   guild_id?: string | ||||
|   emoji: Emoji | ||||
|   emoji: EmojiPayload | ||||
| } | ||||
| 
 | ||||
| interface MessageReactionRemoveAll { | ||||
|   channel_id: string | ||||
|   guild_id?: string | ||||
|   message_id: string | ||||
|   emoji: Emoji | ||||
|   emoji: EmojiPayload | ||||
| } | ||||
| 
 | ||||
| interface MessageReactionRemove { | ||||
|   channel_id: string | ||||
|   guild_id?: string | ||||
|   message_id: string | ||||
|   emoji: Emoji | ||||
|   emoji: EmojiPayload | ||||
| } | ||||
| 
 | ||||
| interface PresenceUpdate { | ||||
|   user: User | ||||
|   user: UserPayload | ||||
|   guild_id: string | ||||
|   status: string | ||||
|   activities: ActivityPayload[] | ||||
|  | @ -323,7 +322,7 @@ interface Activity { | |||
|   application_id: string | ||||
|   details?: string | undefined | ||||
|   state?: string | undefined | ||||
|   emoji?: Emoji | undefined | ||||
|   emoji?: EmojiPayload | undefined | ||||
|   party?: ActivityParty | ||||
|   assets?: ActivityAssets | ||||
|   secrets?: ActivitySecrets | ||||
|  | @ -382,7 +381,7 @@ interface TypeStart { | |||
|   guild_id?: string | ||||
|   user_id: string | ||||
|   timestamp: number | ||||
|   member?: Member | ||||
|   member?: MemberPayload | ||||
| } | ||||
| 
 | ||||
| interface VoiceServerUpdate { | ||||
|  |  | |||
|  | @ -1,65 +1,64 @@ | |||
| import { Channel } from '../structures/channel.ts' | ||||
| import { Emoji } from '../structures/emoji.ts' | ||||
| import { Member } from '../structures/member.ts' | ||||
| import { Role } from '../structures/role.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { ChannelPayload } from './channelTypes.ts' | ||||
| import { EmojiPayload } from './emojiTypes.ts' | ||||
| import { PresenceUpdatePayload } from './presenceTypes.ts' | ||||
| import { RolePayload } from './roleTypes.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| import { VoiceStatePayload } from './voiceTypes.ts' | ||||
| 
 | ||||
| interface GuildPayload { | ||||
|   id: string | ||||
|   name: string | ||||
|   icon: string | undefined | ||||
|   icon_hash?: string | undefined | ||||
|   splash: string | undefined | ||||
|   discovery_splash: string | undefined | ||||
|   icon?: string | ||||
|   icon_hash?: string | ||||
|   splash?: string | ||||
|   discovery_splash?: string | ||||
|   owner?: boolean | ||||
|   owner_id: string | ||||
|   permissions?: string | ||||
|   region: string | ||||
|   afk_channel_id: string | undefined | ||||
|   afk_channel_id?: string | ||||
|   afk_timeout: number | ||||
|   widget_enabled?: boolean | ||||
|   widge_channel_id?: string | undefined | ||||
|   widge_channel_id?: string | ||||
|   verification_level: string | ||||
|   default_message_notifications: string | ||||
|   explicit_content_filter: string | ||||
|   roles: Role[] | ||||
|   emojis: Emoji[] | ||||
|   roles: RolePayload[] | ||||
|   emojis: EmojiPayload[] | ||||
|   features: GuildFeatures[] | ||||
|   mfa_level: string | ||||
|   application_id: string | undefined | ||||
|   system_channel_id: string | undefined | ||||
|   application_id?: string | ||||
|   system_channel_id?: string | ||||
|   system_channel_flags: string | ||||
|   rules_channel_id: string | undefined | ||||
|   rules_channel_id?: string | ||||
|   joined_at?: string | ||||
|   large?: boolean | ||||
|   unavailable: boolean | ||||
|   member_count?: number | ||||
|   voice_states?: VoiceStatePayload[] | ||||
|   members?: Member[] | ||||
|   channels?: Channel[] | ||||
|   members?: MemberPayload[] | ||||
|   channels?: ChannelPayload[] | ||||
|   presences?: PresenceUpdatePayload[] | ||||
|   max_presences?: number | undefined | ||||
|   max_presences?: number | ||||
|   max_members?: number | ||||
|   vanity_url_code: string | undefined | ||||
|   description: string | undefined | ||||
|   banner: string | undefined | ||||
|   vanity_url_code?: string | ||||
|   description?: string | ||||
|   banner?: string | ||||
|   premium_tier: number | ||||
|   premium_subscription_count?: number | ||||
|   preferred_locale: string | ||||
|   public_updates_channel_id: string | undefined | ||||
|   public_updates_channel_id?: string | ||||
|   max_video_channel_users?: number | ||||
|   approximate_number_count?: number | ||||
|   approximate_presence_count?: number | ||||
| } | ||||
| 
 | ||||
| interface MemberPayload { | ||||
|   user: User | ||||
|   nick: string | undefined | ||||
|   roles: Role[] | ||||
|   user: UserPayload | ||||
|   nick?: string | ||||
|   roles: RolePayload[] | ||||
|   joined_at: string | ||||
|   premium_since?: string | undefined | ||||
|   premium_since?: string | ||||
|   deaf: boolean | ||||
|   mute: boolean | ||||
| } | ||||
|  |  | |||
|  | @ -1,13 +1,13 @@ | |||
| import { Channel } from '../structures/channel.ts' | ||||
| import { Guild } from '../structures/guild.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { ChannelPayload } from './channelTypes.ts' | ||||
| import { GuildPayload } from './guildTypes.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| export interface InvitePayload { | ||||
|   code: string | ||||
|   guild?: Guild | ||||
|   channel: Channel | ||||
|   inviter?: User | ||||
|   target_user?: User | ||||
|   guild?: GuildPayload | ||||
|   channel: ChannelPayload | ||||
|   inviter?: UserPayload | ||||
|   target_user?: UserPayload | ||||
|   target_user_type?: number | ||||
|   approximate_presence_count?: number | ||||
|   approximate_member_count?: number | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { User } from '../structures/user.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| interface PresenceUpdatePayload { | ||||
|   user: User | ||||
|   user: UserPayload | ||||
|   guild_id: string | ||||
|   status: string | ||||
|   activities: ActivityPayload | ||||
|  |  | |||
|  | @ -15,8 +15,3 @@ export class Snowflake { | |||
|     return res | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // BigInt라서 이걸 어케 할까 고심끝에 나온게 toString 읍
 | ||||
| // 엄...
 | ||||
| 
 | ||||
| // deconstruct가 소멸자임? 색 봐서는 아닌거같은데
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { Guild } from '../structures/guild.ts' | ||||
| import { User } from '../structures/user.ts' | ||||
| import { GuildPayload } from './guildTypes.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| export interface TemplatePayload { | ||||
|   code: string | ||||
|  | @ -7,10 +7,10 @@ export interface TemplatePayload { | |||
|   description: string | undefined | ||||
|   usage_count: number | ||||
|   creator_id: string | ||||
|   creator: User | ||||
|   creator: UserPayload | ||||
|   created_at: string | ||||
|   updated_at: string | ||||
|   source_guild_id: string | ||||
|   serialized_source_guild: Guild | ||||
|   serialized_source_guild: GuildPayload | ||||
|   is_dirty: boolean | undefined | ||||
| } | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| // https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice
 | ||||
| import { Member } from '../structures/member.ts' | ||||
| import { MemberPayload } from './guildTypes.ts' | ||||
| 
 | ||||
| enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC -
 | ||||
|   IDENTIFY = 0, | ||||
|  | @ -31,9 +31,9 @@ enum VoiceCloseCodes { | |||
| 
 | ||||
| export interface VoiceStatePayload { | ||||
|   guild_id?: string | ||||
|   channel_id: string | undefined | ||||
|   channel_id?: string | ||||
|   user_id: string | ||||
|   member?: Member | ||||
|   member?: MemberPayload | ||||
|   session_id: string | ||||
|   deaf: boolean | ||||
|   mute: boolean | ||||
|  |  | |||
|  | @ -1,13 +1,13 @@ | |||
| import { User } from '../structures/user.ts' | ||||
| import { UserPayload } from './userTypes.ts' | ||||
| 
 | ||||
| export interface WebhookPayload { | ||||
|   id: string | ||||
|   type: 1 | 2 | ||||
|   guild_id?: string | ||||
|   channel_id: string | ||||
|   user?: User | ||||
|   name: string | undefined | ||||
|   avatar: string | undefined | ||||
|   user?: UserPayload | ||||
|   name?: string | ||||
|   avatar?: string | ||||
|   token?: string | ||||
|   application_id: string | undefined | ||||
|   application_id?: string | ||||
| } | ||||
|  |  | |||
|  | @ -8,8 +8,8 @@ | |||
|     "module": "ESNext", | ||||
|     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||||
|     "lib": [ | ||||
|       "esnext", | ||||
|     ], /* Specify library files to be included in the compilation. */ | ||||
|       "esnext" | ||||
|     ] /* Specify library files to be included in the compilation. */, | ||||
|     // "allowJs": true,                       /* Allow javascript files to be compiled. */ | ||||
|     // "checkJs": true,                       /* Report errors in .js files. */ | ||||
|     // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||||
|  | @ -67,4 +67,4 @@ | |||
|     /* Skip type checking of declaration files. */ | ||||
|     "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||||
|   } | ||||
| } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue