harmony/src/gateway/handlers/ready.ts

31 lines
946 B
TypeScript
Raw Normal View History

import { User } from '../../structures/user.ts'
import { Ready } from '../../types/gateway.ts'
2020-10-31 12:33:34 +00:00
import { GuildPayload } from '../../types/guild.ts'
2021-04-04 05:42:15 +00:00
import type { Gateway, GatewayEventHandler } from '../mod.ts'
export const ready: GatewayEventHandler = async (
gateway: Gateway,
d: Ready
) => {
2021-01-20 10:05:15 +00:00
gateway.client.upSince = new Date()
2021-01-26 20:15:47 +00:00
if ('application' in d) {
gateway.client.applicationID = d.application.id
gateway.client.applicationFlags = d.application.flags
}
await gateway.client.guilds.flush()
2020-11-25 11:53:40 +00:00
2020-12-08 06:43:06 +00:00
await gateway.client.users.set(d.user.id, d.user)
gateway.client.user = new User(gateway.client, d.user)
gateway.sessionID = d.session_id
gateway.debug(`Received READY. Session: ${gateway.sessionID}`)
await gateway.cache.set('session_id', gateway.sessionID)
2020-11-25 11:53:40 +00:00
d.guilds.forEach((guild: GuildPayload) => {
gateway.client.guilds.set(guild.id, guild)
})
2021-01-24 18:36:19 +00:00
gateway.client.emit('ready', gateway.shards?.[0] ?? 0)
}