Skip to content

Commit

Permalink
Fix bug when connecting cleent to vc multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
chilipizdrick committed Apr 6, 2024
1 parent ae75842 commit 190dfa7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 19 additions & 4 deletions utils/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"errors"
"log"
"os"

discord "github.com/bwmarrin/discordgo"
)
Expand Down Expand Up @@ -58,8 +59,15 @@ func GenericVoiceCommandHandler(filepath string) func(s *discord.Session, i *dis
})
defer s.InteractionResponseDelete(i.Interaction)

// Return if user is bot
if i.Member.User.Bot {
// Return if client already connected to vc on this server
vs, err := s.State.VoiceState(i.GuildID, os.Getenv("CLIENT_ID"))
if err != nil {
log.Printf("[ERROR] %v", err)
EditResponseWithString(s, i, "An error occured while executing command.")
return
}
if vs.ChannelID != "" {
log.Println("[TRACE] exited because already in vc")
return
}

Expand Down Expand Up @@ -95,8 +103,15 @@ func GenericRandomVoiceCommandHandler(dirpath string) func(s *discord.Session, i
})
defer s.InteractionResponseDelete(i.Interaction)

// Return if user is bot
if i.Member.User.Bot {
// Return if client already connected to vc on this server
vs, err := s.State.VoiceState(i.GuildID, os.Getenv("CLIENT_ID"))
if err != nil {
log.Printf("[ERROR] %v", err)
EditResponseWithString(s, i, "An error occured while executing command.")
return
}
if vs.ChannelID != "" {
log.Println("[TRACE] exited because already in vc")
return
}

Expand Down
3 changes: 1 addition & 2 deletions utils/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"fmt"
"log"
"math/rand"
"os"
"strings"
Expand All @@ -25,7 +24,7 @@ func PickRandomFileFromDirectory(dirpath string) (string, error) {
}

filepath := dirpath + filenames[rand.Intn(len(filenames))]
log.Printf("[TRACE] call: PickRandomFileFromDirectory -> filepath: %v", filepath)
// log.Printf("[TRACE] call: PickRandomFileFromDirectory -> filepath: %v", filepath)

return filepath, nil
}

0 comments on commit 190dfa7

Please sign in to comment.