Roll back broken audio, keep notifications.
This commit is contained in:
@@ -121,17 +121,6 @@ func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) {
|
||||
reason = e.String
|
||||
}
|
||||
b.stopRecordingForDisconnect()
|
||||
b.FileStreamMutex.Lock()
|
||||
fileStream := b.FileStream
|
||||
b.FileStream = nil
|
||||
b.FileStreamMutex.Unlock()
|
||||
if fileStream != nil && fileStream.IsPlaying() {
|
||||
_ = fileStream.Stop()
|
||||
}
|
||||
if b.Stream != nil {
|
||||
b.Stream.Destroy()
|
||||
b.Stream = nil
|
||||
}
|
||||
b.Notify("disconnect", "me", reason)
|
||||
if reason == "" {
|
||||
b.AddOutputLine("Disconnected")
|
||||
@@ -186,28 +175,18 @@ func (b *Barnard) OnUserChange(e *gumble.UserChangeEvent) {
|
||||
notification, hasNotification := b.userChangeNotification(e)
|
||||
audioNotification, hasAudioNotification := b.userAudioChangeNotification(e)
|
||||
if e.User != nil {
|
||||
previousLocalMute, previousLocalMuteGeneration := e.User.LocalMuteState()
|
||||
previousVolume := e.User.Volume
|
||||
b.UserConfig.UpdateUser(e.User)
|
||||
localMute, localMuteGeneration := e.User.LocalMuteState()
|
||||
if b.Stream != nil {
|
||||
if localMute != previousLocalMute || localMuteGeneration != previousLocalMuteGeneration {
|
||||
b.Stream.SetUserMuteState(e.User)
|
||||
} else if e.User.Volume != previousVolume {
|
||||
b.Stream.SetUserGain(e.User, e.User.Volume)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if user is joining a muted channel
|
||||
if e.Type.Has(gumble.UserChangeConnected) || e.Type.Has(gumble.UserChangeChannel) {
|
||||
// If the channel is muted, ensure the user is muted
|
||||
if b.MutedChannels[e.User.Channel.ID] {
|
||||
// Only mute if not already muted
|
||||
if !e.User.IsLocallyMuted() {
|
||||
if !e.User.LocallyMuted {
|
||||
b.UserConfig.ToggleMute(e.User)
|
||||
}
|
||||
if b.Stream != nil {
|
||||
b.Stream.SetUserMuteState(e.User)
|
||||
if e.User.AudioSource != nil {
|
||||
e.User.AudioSource.SetGain(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,31 +278,45 @@ func (b *Barnard) userAudioChangeNotification(e *gumble.UserChangeEvent) (userCh
|
||||
return userChangeNotification{}, false
|
||||
}
|
||||
|
||||
event := ""
|
||||
verb := ""
|
||||
muteEvent := ""
|
||||
muteVerb := ""
|
||||
if previous.selfMuted != e.User.SelfMuted {
|
||||
if e.User.SelfMuted {
|
||||
muteEvent = "mute"
|
||||
muteVerb = "muted"
|
||||
} else {
|
||||
muteEvent = "unmute"
|
||||
muteVerb = "unmuted"
|
||||
}
|
||||
}
|
||||
|
||||
deafenEvent := ""
|
||||
deafenVerb := ""
|
||||
if previous.selfDeafened != e.User.SelfDeafened {
|
||||
if e.User.SelfDeafened {
|
||||
event = "deafen"
|
||||
verb = "deafened"
|
||||
deafenEvent = "deafen"
|
||||
deafenVerb = "deafened"
|
||||
} else {
|
||||
event = "undeafen"
|
||||
verb = "undeafened"
|
||||
}
|
||||
} else if previous.selfMuted != e.User.SelfMuted {
|
||||
if e.User.SelfMuted {
|
||||
event = "mute"
|
||||
verb = "muted"
|
||||
} else {
|
||||
event = "unmute"
|
||||
verb = "unmuted"
|
||||
deafenEvent = "undeafen"
|
||||
deafenVerb = "undeafened"
|
||||
}
|
||||
}
|
||||
|
||||
event := muteEvent + deafenEvent
|
||||
verbs := make([]string, 0, 2)
|
||||
if muteVerb != "" {
|
||||
verbs = append(verbs, muteVerb)
|
||||
}
|
||||
if deafenVerb != "" {
|
||||
verbs = append(verbs, deafenVerb)
|
||||
}
|
||||
if event == "" {
|
||||
return userChangeNotification{}, false
|
||||
}
|
||||
|
||||
verb := strings.Join(verbs, " and ")
|
||||
who := e.User.Name
|
||||
line := fmt.Sprintf("%s %s themselves", e.User.Name, verb)
|
||||
line := fmt.Sprintf("%s %s", e.User.Name, verb)
|
||||
if e.User.Session == b.Client.Self.Session {
|
||||
who = "me"
|
||||
line = fmt.Sprintf("You %s yourself", verb)
|
||||
|
||||
Reference in New Issue
Block a user