fix: Guild#chunk

This commit is contained in:
DjDeveloperr 2021-01-01 10:18:18 +05:30
parent 8edef36ead
commit b344c2e24a
4 changed files with 71 additions and 12 deletions

View File

@ -188,7 +188,9 @@ export class Gateway extends EventEmitter {
this.reconnect()
break
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:
throw new Error("Invalid Payload was sent. This shouldn't happen!")
case GatewayCloseCodes.NOT_AUTHENTICATED:
@ -320,8 +322,8 @@ export class Gateway extends EventEmitter {
op: GatewayOpcodes.REQUEST_GUILD_MEMBERS,
d: {
guild_id: guild,
query: options.query,
limit: options.limit,
query: options.query ?? '',
limit: options.limit ?? 0,
presences: options.presences,
user_ids: options.users,
nonce
@ -387,14 +389,13 @@ export class Gateway extends EventEmitter {
send(data: GatewayResponse): boolean {
if (this.websocket.readyState !== this.websocket.OPEN) return false
this.websocket.send(
JSON.stringify({
op: data.op,
d: data.d,
s: typeof data.s === 'number' ? data.s : null,
t: data.t === undefined ? null : data.t
})
)
const packet = JSON.stringify({
op: data.op,
d: data.d,
s: typeof data.s === 'number' ? data.s : null,
t: data.t === undefined ? null : data.t
})
this.websocket.send(packet)
return true
}

View File

@ -327,7 +327,6 @@ export class Guild extends Base {
}
}, timeout)
}
resolve(this)
})
}
}

View File

@ -16,10 +16,32 @@ export class Invite extends Base {
approximatePresenceCount?: 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 {
return `https://discord.gg/${this.code}`
}
toString(): string {
return this.link
}
constructor(client: Client, data: InvitePayload) {
super(client)
this.code = data.code
@ -30,6 +52,12 @@ export class Invite extends Base {
this.targetUserType = data.target_user_type
this.approximateMemberCount = data.approximate_member_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. */
@ -49,5 +77,12 @@ export class Invite extends Base {
data.approximate_member_count ?? this.approximateMemberCount
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
View 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)