fix: Guild#chunk
This commit is contained in:
		
							parent
							
								
									8edef36ead
								
							
						
					
					
						commit
						b344c2e24a
					
				
					 4 changed files with 71 additions and 12 deletions
				
			
		|  | @ -188,7 +188,9 @@ export class Gateway extends EventEmitter { | ||||||
|         this.reconnect() |         this.reconnect() | ||||||
|         break |         break | ||||||
|       case GatewayCloseCodes.UNKNOWN_OPCODE: |       case GatewayCloseCodes.UNKNOWN_OPCODE: | ||||||
|         throw new Error("Unknown OP Code was sent. This shouldn't happen!") |         throw new Error( | ||||||
|  |           "Invalid OP Code or Payload was sent. This shouldn't happen!" | ||||||
|  |         ) | ||||||
|       case GatewayCloseCodes.DECODE_ERROR: |       case GatewayCloseCodes.DECODE_ERROR: | ||||||
|         throw new Error("Invalid Payload was sent. This shouldn't happen!") |         throw new Error("Invalid Payload was sent. This shouldn't happen!") | ||||||
|       case GatewayCloseCodes.NOT_AUTHENTICATED: |       case GatewayCloseCodes.NOT_AUTHENTICATED: | ||||||
|  | @ -320,8 +322,8 @@ export class Gateway extends EventEmitter { | ||||||
|       op: GatewayOpcodes.REQUEST_GUILD_MEMBERS, |       op: GatewayOpcodes.REQUEST_GUILD_MEMBERS, | ||||||
|       d: { |       d: { | ||||||
|         guild_id: guild, |         guild_id: guild, | ||||||
|         query: options.query, |         query: options.query ?? '', | ||||||
|         limit: options.limit, |         limit: options.limit ?? 0, | ||||||
|         presences: options.presences, |         presences: options.presences, | ||||||
|         user_ids: options.users, |         user_ids: options.users, | ||||||
|         nonce |         nonce | ||||||
|  | @ -387,14 +389,13 @@ export class Gateway extends EventEmitter { | ||||||
| 
 | 
 | ||||||
|   send(data: GatewayResponse): boolean { |   send(data: GatewayResponse): boolean { | ||||||
|     if (this.websocket.readyState !== this.websocket.OPEN) return false |     if (this.websocket.readyState !== this.websocket.OPEN) return false | ||||||
|     this.websocket.send( |     const packet = JSON.stringify({ | ||||||
|       JSON.stringify({ |       op: data.op, | ||||||
|         op: data.op, |       d: data.d, | ||||||
|         d: data.d, |       s: typeof data.s === 'number' ? data.s : null, | ||||||
|         s: typeof data.s === 'number' ? data.s : null, |       t: data.t === undefined ? null : data.t | ||||||
|         t: data.t === undefined ? null : data.t |     }) | ||||||
|       }) |     this.websocket.send(packet) | ||||||
|     ) |  | ||||||
|     return true |     return true | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -327,7 +327,6 @@ export class Guild extends Base { | ||||||
|           } |           } | ||||||
|         }, timeout) |         }, timeout) | ||||||
|       } |       } | ||||||
|       resolve(this) |  | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -16,10 +16,32 @@ export class Invite extends Base { | ||||||
|   approximatePresenceCount?: number |   approximatePresenceCount?: number | ||||||
|   approximateMemberCount?: number |   approximateMemberCount?: number | ||||||
| 
 | 
 | ||||||
|  |   /** Number of times Invite was used. This is an Invite Metadata property (not always available) */ | ||||||
|  |   uses?: number | ||||||
|  |   /** Max number of times this Invite can be used. This is an Invite Metadata property (not always available) */ | ||||||
|  |   maxUses?: number | ||||||
|  |   /** Max age of the Invite in seconds. This is an Invite Metadata property (not always available) */ | ||||||
|  |   maxAge?: number | ||||||
|  |   /** Whether Invite is temporary or not. This is an Invite Metadata property (not always available) */ | ||||||
|  |   temporary?: boolean | ||||||
|  |   /** Timestamp (string) when Invite was created. This is an Invite Metadata property (not always available) */ | ||||||
|  |   createdAtTimestamp?: string | ||||||
|  | 
 | ||||||
|  |   /** Timestamp (Date) when Invite was created. This is an Invite Metadata property (not always available) */ | ||||||
|  |   get createdAt(): Date | undefined { | ||||||
|  |     return this.createdAtTimestamp === undefined | ||||||
|  |       ? undefined | ||||||
|  |       : new Date(this.createdAtTimestamp) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   get link(): string { |   get link(): string { | ||||||
|     return `https://discord.gg/${this.code}` |     return `https://discord.gg/${this.code}` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   toString(): string { | ||||||
|  |     return this.link | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   constructor(client: Client, data: InvitePayload) { |   constructor(client: Client, data: InvitePayload) { | ||||||
|     super(client) |     super(client) | ||||||
|     this.code = data.code |     this.code = data.code | ||||||
|  | @ -30,6 +52,12 @@ export class Invite extends Base { | ||||||
|     this.targetUserType = data.target_user_type |     this.targetUserType = data.target_user_type | ||||||
|     this.approximateMemberCount = data.approximate_member_count |     this.approximateMemberCount = data.approximate_member_count | ||||||
|     this.approximatePresenceCount = data.approximate_presence_count |     this.approximatePresenceCount = data.approximate_presence_count | ||||||
|  | 
 | ||||||
|  |     this.uses = (data as any).uses | ||||||
|  |     this.maxUses = (data as any).maxUses | ||||||
|  |     this.maxAge = (data as any).maxAge | ||||||
|  |     this.temporary = (data as any).temporary | ||||||
|  |     this.createdAtTimestamp = (data as any).createdAtTimestamp | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Delete an invite. Requires the MANAGE_CHANNELS permission on the channel this invite belongs to, or MANAGE_GUILD to remove any invite across the guild. Returns an invite object on success. Fires a Invite Delete Gateway event. */ |   /** Delete an invite. Requires the MANAGE_CHANNELS permission on the channel this invite belongs to, or MANAGE_GUILD to remove any invite across the guild. Returns an invite object on success. Fires a Invite Delete Gateway event. */ | ||||||
|  | @ -49,5 +77,12 @@ export class Invite extends Base { | ||||||
|       data.approximate_member_count ?? this.approximateMemberCount |       data.approximate_member_count ?? this.approximateMemberCount | ||||||
|     this.approximatePresenceCount = |     this.approximatePresenceCount = | ||||||
|       data.approximate_presence_count ?? this.approximatePresenceCount |       data.approximate_presence_count ?? this.approximatePresenceCount | ||||||
|  | 
 | ||||||
|  |     this.uses = (data as any).uses ?? this.uses | ||||||
|  |     this.maxUses = (data as any).maxUses ?? this.maxUses | ||||||
|  |     this.maxAge = (data as any).maxAge ?? this.maxAge | ||||||
|  |     this.temporary = (data as any).temporary ?? this.temporary | ||||||
|  |     this.createdAtTimestamp = | ||||||
|  |       (data as any).createdAtTimestamp ?? this.createdAtTimestamp | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										24
									
								
								src/test/chunk.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/test/chunk.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | ||||||
|  | import { Client, Intents } from '../../mod.ts' | ||||||
|  | import { TOKEN } from './config.ts' | ||||||
|  | 
 | ||||||
|  | const client = new Client() | ||||||
|  | 
 | ||||||
|  | client.on('debug', console.log) | ||||||
|  | 
 | ||||||
|  | client.on('ready', () => { | ||||||
|  |   console.log(`Logged in as ${client.user?.tag}!`) | ||||||
|  |   client.guilds.get('783319033205751809').then((guild) => { | ||||||
|  |     if (guild === undefined) return console.log('Guild not found') | ||||||
|  |     guild | ||||||
|  |       .chunk({ presences: true }, true) | ||||||
|  |       .then((guild) => { | ||||||
|  |         console.log(`Chunked guild:`, guild.id) | ||||||
|  |       }) | ||||||
|  |       .catch((e) => { | ||||||
|  |         console.log(`Failed to Chunk: ${guild.id} - ${e}`) | ||||||
|  |       }) | ||||||
|  |   }) | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | console.log('Connecting...') | ||||||
|  | client.connect(TOKEN, Intents.All) | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue