Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an event for VoiceStateDisconnect #828

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ type VoiceStateUpdate struct {
*VoiceState
}

// VoiceStateDisconnect is the data for a VoiceStateDisconnect event.
type VoiceStateDisconnect struct {
*VoiceState
}

// MessageDeleteBulk is the data for a MessageDeleteBulk event
type MessageDeleteBulk struct {
Messages []string `json:"ids"`
Expand Down
10 changes: 7 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (s *State) messageRemoveByID(channelID, messageID string) error {
return ErrStateNotFound
}

func (s *State) voiceStateUpdate(update *VoiceStateUpdate) error {
func (s *State) voiceStateUpdate(se *Session, update *VoiceStateUpdate) error {
guild, err := s.Guild(update.GuildID)
if err != nil {
return err
Expand All @@ -714,6 +714,9 @@ func (s *State) voiceStateUpdate(update *VoiceStateUpdate) error {
if update.ChannelID == "" {
for i, state := range guild.VoiceStates {
if state.UserID == update.UserID {
disconn := guild.VoiceStates[i]

se.handleEvent("VOICE_STATE_DISCONNECT", &VoiceStateDisconnect{disconn})
guild.VoiceStates = append(guild.VoiceStates[:i], guild.VoiceStates[i+1:]...)
return nil
}
Expand Down Expand Up @@ -921,7 +924,7 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
}
case *VoiceStateUpdate:
if s.TrackVoice {
err = s.voiceStateUpdate(t)
err = s.voiceStateUpdate(se, t)
}
case *PresenceUpdate:
if s.TrackPresences {
Expand Down Expand Up @@ -1046,7 +1049,8 @@ func (s *State) UserColor(userID, channelID string) int {
}

// MessageColor returns the color of the author's name as displayed
// in the client associated with this message.
// While colors are defined at a Guild level, determining for a message is more useful in message handlers.
// 0 is returned in cases of error, which is the color of @everyone.
func (s *State) MessageColor(message *Message) int {
if s == nil {
return 0
Expand Down