2020-10-30 14:51:40 +00:00
|
|
|
import { User } from '../../structures/user.ts'
|
2020-12-02 08:02:00 +00:00
|
|
|
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'
|
2020-10-30 14:51:40 +00:00
|
|
|
|
2020-12-02 08:02:00 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-15 07:32:46 +00:00
|
|
|
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)
|
2020-10-30 14:51:40 +00:00
|
|
|
gateway.client.user = new User(gateway.client, d.user)
|
|
|
|
gateway.sessionID = d.session_id
|
2020-10-31 11:45:33 +00:00
|
|
|
gateway.debug(`Received READY. Session: ${gateway.sessionID}`)
|
2020-12-02 08:02:00 +00:00
|
|
|
await gateway.cache.set('session_id', gateway.sessionID)
|
2020-11-25 11:53:40 +00:00
|
|
|
|
2020-10-31 11:45:33 +00:00
|
|
|
d.guilds.forEach((guild: GuildPayload) => {
|
|
|
|
gateway.client.guilds.set(guild.id, guild)
|
|
|
|
})
|
2020-12-02 08:02:00 +00:00
|
|
|
|
2021-01-24 18:36:19 +00:00
|
|
|
gateway.client.emit('ready', gateway.shards?.[0] ?? 0)
|
2020-12-02 08:02:00 +00:00
|
|
|
}
|