harmony/src/gateway/handlers/channelPinsUpdate.ts

26 lines
867 B
TypeScript
Raw Normal View History

2021-04-04 05:42:15 +00:00
import type { Gateway, GatewayEventHandler } from '../mod.ts'
2021-04-04 09:29:56 +00:00
import type { TextChannel } from '../../structures/textChannel.ts'
import type { ChannelPinsUpdatePayload } from '../../types/gateway.ts'
2020-12-02 12:29:52 +00:00
export const channelPinsUpdate: GatewayEventHandler = async (
gateway: Gateway,
d: ChannelPinsUpdatePayload
) => {
2020-12-03 05:28:20 +00:00
const before:
2020-12-02 12:29:52 +00:00
| TextChannel
| undefined = await gateway.client.channels.get<TextChannel>(d.channel_id)
2020-12-03 05:28:20 +00:00
if (before !== undefined) {
2020-12-02 12:29:52 +00:00
const raw = await gateway.client.channels._get(d.channel_id)
2020-12-03 05:28:20 +00:00
if (raw === undefined) return
2020-12-02 12:29:52 +00:00
await gateway.client.channels.set(
2020-12-03 05:28:20 +00:00
raw.id,
2020-12-02 12:29:52 +00:00
Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp })
)
2020-12-03 05:28:20 +00:00
const after = ((await gateway.client.channels.get(
d.channel_id
)) as unknown) as TextChannel
2020-12-02 12:29:52 +00:00
gateway.client.emit('channelPinsUpdate', before, after)
}
}