Merge branch 'develop' of https://github.com/bwmarrin/Discordgo into develop
This commit is contained in:
commit
1e2b1817bd
5 changed files with 44 additions and 14 deletions
|
@ -170,11 +170,7 @@ func (s *Session) AddHandler(handler interface{}) func() {
|
||||||
|
|
||||||
h := reflect.ValueOf(handler)
|
h := reflect.ValueOf(handler)
|
||||||
|
|
||||||
handlers := s.handlers[eventType]
|
s.handlers[eventType] = append(s.handlers[eventType], h)
|
||||||
if handlers == nil {
|
|
||||||
handlers = []reflect.Value{}
|
|
||||||
}
|
|
||||||
s.handlers[eventType] = append(handlers, h)
|
|
||||||
|
|
||||||
// This must be done as we need a consistent reference to the
|
// This must be done as we need a consistent reference to the
|
||||||
// reflected value, otherwise a RemoveHandler method would have
|
// reflected value, otherwise a RemoveHandler method would have
|
||||||
|
|
|
@ -34,6 +34,7 @@ var eventToInterface = map[string]interface{}{
|
||||||
"MESSAGE_UPDATE": MessageUpdate{},
|
"MESSAGE_UPDATE": MessageUpdate{},
|
||||||
"MESSAGE_DELETE": MessageDelete{},
|
"MESSAGE_DELETE": MessageDelete{},
|
||||||
"PRESENCE_UPDATE": PresenceUpdate{},
|
"PRESENCE_UPDATE": PresenceUpdate{},
|
||||||
|
"PRESENCES_REPLACE": PresencesReplace{},
|
||||||
"READY": Ready{},
|
"READY": Ready{},
|
||||||
"USER_UPDATE": UserUpdate{},
|
"USER_UPDATE": UserUpdate{},
|
||||||
"USER_SETTINGS_UPDATE": UserSettingsUpdate{},
|
"USER_SETTINGS_UPDATE": UserSettingsUpdate{},
|
||||||
|
@ -129,6 +130,9 @@ type GuildRoleUpdate struct {
|
||||||
*GuildRole
|
*GuildRole
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PresencesReplace is an array of Presences for an event.
|
||||||
|
type PresencesReplace []*Presence
|
||||||
|
|
||||||
// VoiceStateUpdate is a wrapper struct for an event.
|
// VoiceStateUpdate is a wrapper struct for an event.
|
||||||
type VoiceStateUpdate struct {
|
type VoiceStateUpdate struct {
|
||||||
*VoiceState
|
*VoiceState
|
||||||
|
|
5
state.go
5
state.go
|
@ -73,6 +73,11 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, update the channels to point to the right guild
|
||||||
|
for _, c := range guild.Channels {
|
||||||
|
c.GuildID = guild.ID
|
||||||
|
}
|
||||||
|
|
||||||
s.Guilds = append(s.Guilds, guild)
|
s.Guilds = append(s.Guilds, guild)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ type TypingStart struct {
|
||||||
Timestamp int `json:"timestamp"`
|
Timestamp int `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A PresenceUpdate stores data for the pressence update websocket event.
|
// A PresenceUpdate stores data for the presence update websocket event.
|
||||||
type PresenceUpdate struct {
|
type PresenceUpdate struct {
|
||||||
User *User `json:"user"`
|
User *User `json:"user"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
41
voice.go
41
voice.go
|
@ -59,8 +59,12 @@ type VoiceConnection struct {
|
||||||
|
|
||||||
op4 voiceOP4
|
op4 voiceOP4
|
||||||
op2 voiceOP2
|
op2 voiceOP2
|
||||||
|
|
||||||
|
voiceSpeakingUpdateHandlers []VoiceSpeakingUpdateHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VoiceSpeakingUpdateHandler func(vc *VoiceConnection, vs *VoiceSpeakingUpdate)
|
||||||
|
|
||||||
// Speaking sends a speaking notification to Discord over the voice websocket.
|
// Speaking sends a speaking notification to Discord over the voice websocket.
|
||||||
// This must be sent as true prior to sending audio and should be set to false
|
// This must be sent as true prior to sending audio and should be set to false
|
||||||
// once finished sending audio.
|
// once finished sending audio.
|
||||||
|
@ -151,6 +155,21 @@ func (v *VoiceConnection) Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds a Handler for VoiceSpeakingUpdate events.
|
||||||
|
func (v *VoiceConnection) AddHandler(h VoiceSpeakingUpdateHandler) {
|
||||||
|
v.Lock()
|
||||||
|
defer v.Unlock()
|
||||||
|
|
||||||
|
v.voiceSpeakingUpdateHandlers = append(v.voiceSpeakingUpdateHandlers, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VoiceSpeakingUpdate is a struct for a VoiceSpeakingUpdate event.
|
||||||
|
type VoiceSpeakingUpdate struct {
|
||||||
|
UserID string `json:"user_id"`
|
||||||
|
SSRC int `json:"ssrc"`
|
||||||
|
Speaking bool `json:"speaking"`
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Unexported Internal Functions Below.
|
// Unexported Internal Functions Below.
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -345,14 +364,20 @@ func (v *VoiceConnection) wsEvent(messageType int, message []byte) {
|
||||||
return
|
return
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
// SPEAKING TRUE/FALSE NOTIFICATION
|
if len(v.voiceSpeakingUpdateHandlers) == 0 {
|
||||||
/*
|
return
|
||||||
{
|
}
|
||||||
"user_id": "1238921738912",
|
|
||||||
"ssrc": 2,
|
voiceSpeakingUpdate := &VoiceSpeakingUpdate{}
|
||||||
"speaking": false
|
if err := json.Unmarshal(e.RawData, voiceSpeakingUpdate); err != nil {
|
||||||
}
|
fmt.Println("voiceWS.onEvent VoiceSpeakingUpdate Unmarshal error: ", err)
|
||||||
*/
|
printJSON(e.RawData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, h := range v.voiceSpeakingUpdateHandlers {
|
||||||
|
h(v, voiceSpeakingUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Println("UNKNOWN VOICE OP: ", e.Operation)
|
fmt.Println("UNKNOWN VOICE OP: ", e.Operation)
|
||||||
|
|
Loading…
Reference in a new issue