Skip to content

Commit

Permalink
Merge pull request #134 from disgoorg/feature/text-in-voice
Browse files Browse the repository at this point in the history
support text in voice channels
  • Loading branch information
topi314 authored Jun 1, 2022
2 parents 5019b64 + 33d0ea6 commit 758a43d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 38 deletions.
111 changes: 84 additions & 27 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
})
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}
27 changes: 16 additions & 11 deletions discord/channels_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions handlers/message_create_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 758a43d

Please sign in to comment.