handling empty command, fixing #3

This commit is contained in:
Nico Wunder
2023-02-28 17:23:02 +01:00
parent c49a32a741
commit 6d71fc2605
+18 -3
View File
@@ -101,8 +101,22 @@ It is not planned to extend this in the future.`,
err = viper.WriteConfig()
cobra.CheckErr(err)
}
results, err := client.Search(ctx, strings.TrimPrefix(update.Message.Text, "/spotigram "), spotify.SearchTypeTrack)
cobra.CheckErr(err)
var results *spotify.SearchResult
if strings.HasPrefix(update.Message.Text, "/spotigram ") {
results, err = client.Search(ctx, strings.TrimPrefix(update.Message.Text, "/spotigram "), spotify.SearchTypeTrack)
cobra.CheckErr(err)
}
if !strings.HasPrefix(update.Message.Text, "/spotigram ") {
msg.Text = "⛔ Ooops, du musst einen Titel angeben!\n <code>/spotigram [Titel]</code>"
msg.ParseMode = "HTML"
_, err = bot.Send(msg)
cobra.CheckErr(err)
fmt.Printf("Command used incorrectly.")
}
if results != nil {
@@ -145,7 +159,8 @@ It is not planned to extend this in the future.`,
track.Name,
track.Artists[0].Name)
} else {
}
if !contains(trackIDs, results.Tracks.Tracks[0].ID) {
track := results.Tracks.Tracks[0]
addTrackResponse, err := client.AddTracksToPlaylist(ctx,