-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
48 lines (39 loc) · 1.07 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"errors"
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/zmb3/spotify"
)
type User struct {
discord *discordgo.User
spotify *spotify.Client
playlist *spotify.FullPlaylist
}
func NewUser(discord *discordgo.User, spotify *spotify.Client) *User {
user := new(User)
user.discord = discord
user.spotify = spotify
return user
}
func (user *User) CreatePlaylist() {
u, err := user.spotify.CurrentUser()
if err != nil {
fmt.Println("Error getting user")
}
p, err := user.spotify.CreatePlaylistForUser(u.ID, "Spotify Party :: Queue", "", true)
if err != nil {
fmt.Println("Error creating playlist")
}
user.playlist = p
}
func (user *User) PopFromPlaylist() (*spotify.FullTrack, error) {
tracks, err := user.spotify.GetPlaylistTracks(user.playlist.ID)
if err != nil || tracks == nil || tracks.Tracks == nil || len(tracks.Tracks) == 0 {
err := errors.New("something happened when getting the playlist")
return nil, err
}
track := tracks.Tracks[0].Track
user.spotify.RemoveTracksFromPlaylist(user.playlist.ID, track.ID)
return &track, nil
}