Skip to content

Commit

Permalink
Ignore custom commands already existing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Sep 5, 2020
1 parent 3f6f379 commit f35cd08
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ func sendAndDeleteEmbed(s *discordgo.Session, embed *discordgo.MessageEmbed, txt
}
}

//Finds pointer for a given song id
func findQueuePointer(guildId, id string) int {
for i := range queue[guildId] {
if queue[guildId][i].id == id {
return i
}
}

return -1
}

//Formats a string given it's duration in seconds
func formatDuration(duration float64) string {
duration2 := int(duration)
Expand Down Expand Up @@ -145,14 +134,21 @@ func checkInDb(link string) Queue {

//Adds a custom command to db and to the command map
func addCommand(command string, song string, guild string) {
for _, c := range custom[guild] {
if c.song == song && c.command == command {
//If the song is already in the map, we ignore it
return
}
}
custom[guild] = append(custom[guild], CustomCommand{command, song})

statement, _ := db.Prepare("INSERT INTO customCommands (guild, command, song) VALUES(?, ?, ?)")

_, err := statement.Exec(guild, command, song)
if err != nil {
log.Println("Error inserting into the database,", err)
}

custom[guild] = append(custom[guild], CustomCommand{command, song})
}

//Removes a custom command from the db and from the command map
Expand Down

0 comments on commit f35cd08

Please sign in to comment.