2020-11-28 05:14:37 +00:00
|
|
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
|
|
|
import { TextChannel } from '../../structures/textChannel.ts'
|
|
|
|
import { ChannelPinsUpdatePayload } from '../../types/gateway.ts'
|
|
|
|
|
|
|
|
export const channelPinsUpdate: GatewayEventHandler = async (
|
|
|
|
gateway: Gateway,
|
|
|
|
d: ChannelPinsUpdatePayload
|
|
|
|
) => {
|
2020-12-02 08:02:00 +00:00
|
|
|
const after:
|
|
|
|
| TextChannel
|
|
|
|
| undefined = await gateway.client.channels.get<TextChannel>(d.channel_id)
|
2020-11-28 05:14:37 +00:00
|
|
|
if (after !== undefined) {
|
|
|
|
const before = after.refreshFromData({
|
2020-12-02 08:02:00 +00:00
|
|
|
last_pin_timestamp: d.last_pin_timestamp,
|
2020-11-28 05:14:37 +00:00
|
|
|
})
|
|
|
|
const raw = await gateway.client.channels._get(d.channel_id)
|
|
|
|
await gateway.client.channels.set(
|
|
|
|
after.id,
|
|
|
|
Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp })
|
|
|
|
)
|
|
|
|
gateway.client.emit('channelPinsUpdate', before, after)
|
|
|
|
}
|
|
|
|
}
|