Skip to content

Commit

Permalink
Idk what to write anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
chilipizdrick committed Apr 6, 2024
1 parent 190dfa7 commit 55c742f
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions utils/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@ func GenericVoiceCommandHandler(filepath string) func(s *discord.Session, i *dis
s.InteractionRespond(i.Interaction, &discord.InteractionResponse{
Type: discord.InteractionResponseDeferredChannelMessageWithSource,
})
defer s.InteractionResponseDelete(i.Interaction)
// defer s.InteractionResponseDelete(i.Interaction)

// Return if client already connected to vc on this server
vs, err := s.State.VoiceState(i.GuildID, os.Getenv("CLIENT_ID"))
if err != nil {
if err != nil && err != discord.ErrStateNotFound {
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")
var guildID string
if err != discord.ErrStateNotFound {
guildID = vs.GuildID
} else {
guildID = ""
}
if guildID != "" {
// log.Println("[TRACE] exited because already in vc")
s.InteractionResponseDelete(i.Interaction)
return
}

Expand All @@ -87,10 +94,12 @@ func GenericVoiceCommandHandler(filepath string) func(s *discord.Session, i *dis
return
}

s.InteractionResponseDelete(i.Interaction)

err = PlayAudio(s, i.GuildID, voiceChannelID, audioBuffer)
if err != nil {
log.Printf("[ERROR] %v", err)
// editResponseWithString(s, i, "Could not connect to voice channel or disconnect from it!")
// EditResponseWithString(s, i, "Could not connect to voice channel or disconnect from it!")
return
}
}
Expand All @@ -101,17 +110,24 @@ func GenericRandomVoiceCommandHandler(dirpath string) func(s *discord.Session, i
s.InteractionRespond(i.Interaction, &discord.InteractionResponse{
Type: discord.InteractionResponseDeferredChannelMessageWithSource,
})
defer s.InteractionResponseDelete(i.Interaction)
// defer s.InteractionResponseDelete(i.Interaction)

// Return if client already connected to vc on this server
vs, err := s.State.VoiceState(i.GuildID, os.Getenv("CLIENT_ID"))
if err != nil {
if err != nil && err != discord.ErrStateNotFound {
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")
var guildID string
if err != discord.ErrStateNotFound {
guildID = vs.GuildID
} else {
guildID = ""
}
if guildID != "" {
// log.Println("[TRACE] exited because already in vc")
s.InteractionResponseDelete(i.Interaction)
return
}

Expand All @@ -127,20 +143,22 @@ func GenericRandomVoiceCommandHandler(dirpath string) func(s *discord.Session, i
filepath, err := PickRandomFileFromDirectory(dirpath)
if err != nil {
log.Printf("[ERROR] %v", err)
EditResponseWithString(s, i, "Could not randomly pick audio file path!")
EditResponseWithString(s, i, "Could not randomly pick audio file.")
return
}
err = LoadOpusFile(filepath, &audioBuffer)
if err != nil {
log.Printf("[ERROR] %v", err)
EditResponseWithString(s, i, "Could not load audio file!")
EditResponseWithString(s, i, "Could not load audio file.")
return
}

s.InteractionResponseDelete(i.Interaction)

err = PlayAudio(s, i.GuildID, voiceChannelID, audioBuffer)
if err != nil {
log.Printf("[ERROR] %v", err)
// editResponseWithString(s, i, "Could not connect to voice channel or disconnect from it!")
// EditResponseWithString(s, i, "Could not connect to voice channel or disconnect from it!")
return
}
}
Expand Down

0 comments on commit 55c742f

Please sign in to comment.