diff --git a/discord/channel.go b/discord/channel.go index 8db240e2..0d1d0d86 100644 --- a/discord/channel.go +++ b/discord/channel.go @@ -363,22 +363,28 @@ func (DMChannel) channel() {} func (DMChannel) messageChannel() {} var ( - _ Channel = (*GuildVoiceChannel)(nil) - _ GuildChannel = (*GuildVoiceChannel)(nil) - _ GuildAudioChannel = (*GuildVoiceChannel)(nil) + _ Channel = (*GuildVoiceChannel)(nil) + _ GuildChannel = (*GuildVoiceChannel)(nil) + _ GuildAudioChannel = (*GuildVoiceChannel)(nil) + _ GuildMessageChannel = (*GuildVoiceChannel)(nil) ) type GuildVoiceChannel struct { - id snowflake.ID - guildID snowflake.ID - position int - permissionOverwrites PermissionOverwrites - name string - bitrate int - UserLimit int - parentID *snowflake.ID - rtcRegion string - VideoQualityMode VideoQualityMode + id snowflake.ID + guildID snowflake.ID + position int + permissionOverwrites []PermissionOverwrite + name string + bitrate int + UserLimit int + parentID *snowflake.ID + rtcRegion string + VideoQualityMode VideoQualityMode + lastMessageID *snowflake.ID + lastPinTimestamp *time.Time + topic *string + nsfw bool + defaultAutoArchiveDuration AutoArchiveDuration } func (c *GuildVoiceChannel) UnmarshalJSON(data []byte) error { @@ -397,22 +403,32 @@ func (c *GuildVoiceChannel) UnmarshalJSON(data []byte) error { c.parentID = v.ParentID c.rtcRegion = v.RTCRegion c.VideoQualityMode = v.VideoQualityMode + c.lastMessageID = v.LastMessageID + c.lastPinTimestamp = v.LastPinTimestamp + c.topic = v.Topic + c.nsfw = v.NSFW + c.defaultAutoArchiveDuration = v.DefaultAutoArchiveDuration return nil } func (c GuildVoiceChannel) MarshalJSON() ([]byte, error) { return json.Marshal(guildVoiceChannel{ - ID: c.id, - Type: c.Type(), - GuildID: c.guildID, - Position: c.position, - PermissionOverwrites: c.permissionOverwrites, - Name: c.name, - Bitrate: c.bitrate, - UserLimit: c.UserLimit, - ParentID: c.parentID, - RTCRegion: c.rtcRegion, - VideoQualityMode: c.VideoQualityMode, + ID: c.id, + Type: c.Type(), + GuildID: c.guildID, + Position: c.position, + PermissionOverwrites: c.permissionOverwrites, + Name: c.name, + Bitrate: c.bitrate, + UserLimit: c.UserLimit, + ParentID: c.parentID, + RTCRegion: c.rtcRegion, + VideoQualityMode: c.VideoQualityMode, + LastMessageID: c.lastMessageID, + LastPinTimestamp: c.lastPinTimestamp, + Topic: c.topic, + NSFW: c.nsfw, + DefaultAutoArchiveDuration: c.defaultAutoArchiveDuration, }) } @@ -460,9 +476,31 @@ func (c GuildVoiceChannel) ParentID() *snowflake.ID { return c.parentID } -func (GuildVoiceChannel) channel() {} -func (GuildVoiceChannel) guildChannel() {} -func (GuildVoiceChannel) guildAudioChannel() {} +func (c GuildVoiceChannel) LastMessageID() *snowflake.ID { + return c.lastMessageID +} + +func (c GuildVoiceChannel) LastPinTimestamp() *time.Time { + return c.lastPinTimestamp +} + +func (c GuildVoiceChannel) Topic() *string { + return c.topic +} + +func (c GuildVoiceChannel) NSFW() bool { + return c.nsfw +} + +func (c GuildVoiceChannel) DefaultAutoArchiveDuration() AutoArchiveDuration { + return c.defaultAutoArchiveDuration +} + +func (GuildVoiceChannel) channel() {} +func (GuildVoiceChannel) messageChannel() {} +func (GuildVoiceChannel) guildChannel() {} +func (GuildVoiceChannel) guildAudioChannel() {} +func (GuildVoiceChannel) guildMessageChannel() {} var ( _ Channel = (*GuildCategoryChannel)(nil) @@ -957,3 +995,22 @@ func ApplyGuildIDToChannel(channel GuildChannel, guildID snowflake.ID) GuildChan panic("unknown channel type") } } + +func ApplyLastMessageIDToChannel(channel MessageChannel, lastMessageID snowflake.ID) MessageChannel { + switch c := channel.(type) { + case GuildTextChannel: + c.lastMessageID = &lastMessageID + return c + case GuildVoiceChannel: + c.lastMessageID = &lastMessageID + return c + case GuildNewsChannel: + c.lastMessageID = &lastMessageID + return c + case GuildThread: + c.lastMessageID = &lastMessageID + return c + default: + panic("unknown channel type") + } +} diff --git a/discord/channels_raw.go b/discord/channels_raw.go index 17156a79..b89e9208 100644 --- a/discord/channels_raw.go +++ b/discord/channels_raw.go @@ -115,17 +115,22 @@ func (t *guildCategoryChannel) UnmarshalJSON(data []byte) error { } type guildVoiceChannel struct { - ID snowflake.ID `json:"id"` - Type ChannelType `json:"type"` - GuildID snowflake.ID `json:"guild_id"` - Position int `json:"position"` - PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"` - Name string `json:"name"` - Bitrate int `json:"bitrate"` - UserLimit int `json:"user_limit"` - ParentID *snowflake.ID `json:"parent_id"` - RTCRegion string `json:"rtc_region"` - VideoQualityMode VideoQualityMode `json:"video_quality_mode"` + ID snowflake.ID `json:"id"` + Type ChannelType `json:"type"` + GuildID snowflake.ID `json:"guild_id"` + Position int `json:"position"` + PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"` + Name string `json:"name"` + Bitrate int `json:"bitrate"` + UserLimit int `json:"user_limit"` + ParentID *snowflake.ID `json:"parent_id"` + RTCRegion string `json:"rtc_region"` + VideoQualityMode VideoQualityMode `json:"video_quality_mode"` + LastMessageID *snowflake.ID `json:"last_message_id"` + LastPinTimestamp *time.Time `json:"last_pin_timestamp"` + Topic *string `json:"topic"` + NSFW bool `json:"nsfw"` + DefaultAutoArchiveDuration AutoArchiveDuration `json:"default_auto_archive_duration"` } func (t *guildVoiceChannel) UnmarshalJSON(data []byte) error { diff --git a/handlers/message_create_handler.go b/handlers/message_create_handler.go index 04f2d712..21fb87e6 100644 --- a/handlers/message_create_handler.go +++ b/handlers/message_create_handler.go @@ -30,6 +30,10 @@ func (h *gatewayHandlerMessageCreate) HandleGatewayEvent(client bot.Client, sequ client.Caches().Messages().Put(message.ChannelID, message.ID, message) + if channel, ok := client.Caches().Channels().GetMessageChannel(message.ChannelID); ok { + client.Caches().Channels().Put(message.ChannelID, discord.ApplyLastMessageIDToChannel(channel, message.ID)) + } + genericEvent := events.NewGenericEvent(client, sequenceNumber, shardID) client.EventManager().DispatchEvent(&events.MessageCreate{ GenericMessage: &events.GenericMessage{