Skip to content

Commit

Permalink
Fix skip handling
Browse files Browse the repository at this point in the history
  • Loading branch information
h2yk committed Dec 30, 2023
1 parent 6da6b18 commit 8a150a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions lib/embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package embed
import (
"Kotone-DiVE/lib/config"
"log"
"runtime/debug"
"time"

"github.com/bwmarrin/discordgo"
Expand Down Expand Up @@ -43,6 +44,9 @@ func NewErrorEmbed(session *discordgo.Session, orgMsg *discordgo.MessageCreate,

func NewUnknownErrorEmbed(session *discordgo.Session, orgMsg *discordgo.MessageCreate, lang string, err error) *discordgo.MessageEmbed {
log.Print("WARN: UnknownError called:", err)
if config.CurrentConfig.Debug {
debug.PrintStack()
}
UnknownErrorNum++
return NewErrorEmbed(session, orgMsg, lang, config.Lang[lang].Error.Unknown)
}
2 changes: 1 addition & 1 deletion lib/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func VoiceStateUpdate(session *discordgo.Session, state *discordgo.VoiceStateUpd
utils.VoiceReconnect(session, state.GuildID, state.ChannelID)
} else if !db.StateCache[state.GuildID].ManualReconnectionOngoing {
if state.BeforeUpdate.ChannelID == state.ChannelID && state.Suppress == state.BeforeUpdate.Suppress && state.SelfMute == state.BeforeUpdate.SelfMute && state.SelfDeaf == state.BeforeUpdate.SelfDeaf && state.Mute == state.BeforeUpdate.Mute && state.Deaf == state.BeforeUpdate.Deaf {
log.Print("WARN: VoiceStateUpdate detected recollection.")
log.Print("WARN: VoiceStateUpdate detected reconnection.")
db.StateCache[state.GuildID].ReconnectionDetected = true
}
}
Expand Down
35 changes: 21 additions & 14 deletions lib/voices/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,26 @@ func ReadVoice(session *discordgo.Session, orgMsg *discordgo.MessageCreate, enco
stop := make(chan bool)
defer close(stop)
db.StateCache[orgMsg.GuildID].Stop = &stop
FrameLoop:
for i, v := range frames[db.StateCache[orgMsg.GuildID].FrameCount:] {
select {
case <-stop:
err = Skipped
break FrameLoop
default:
db.StateCache[orgMsg.GuildID].FrameCount = i
if session.VoiceConnections[orgMsg.GuildID].Ready == false || session.VoiceConnections[orgMsg.GuildID].OpusSend == nil {
err = VoiceConnClosed
break FrameLoop

result := make(chan error)
go func() {
for _, v := range frames[db.StateCache[orgMsg.GuildID].FrameCount:] {
select {
case <-stop:
result <- Skipped
return
default:
db.StateCache[orgMsg.GuildID].FrameCount++
if session.VoiceConnections[orgMsg.GuildID].Ready == false || session.VoiceConnections[orgMsg.GuildID].OpusSend == nil {
result <- VoiceConnClosed
return
}
session.VoiceConnections[orgMsg.GuildID].OpusSend <- v
}
session.VoiceConnections[orgMsg.GuildID].OpusSend <- v
}
}
result <- nil
}()
err := <-result

_, exists := db.StateCache[orgMsg.GuildID]
if !exists {
Expand All @@ -177,7 +182,9 @@ func ReadVoice(session *discordgo.Session, orgMsg *discordgo.MessageCreate, enco
db.StateCache[orgMsg.GuildID].Stop = nil

switch {
case err == io.EOF:
case errors.Is(err, io.EOF):
fallthrough
case errors.Is(err, Skipped):
fallthrough
case err == nil:
db.StateCache[orgMsg.GuildID].FrameCount = 0
Expand Down

0 comments on commit 8a150a8

Please sign in to comment.