-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
88 lines (73 loc) · 1.8 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"os"
"strings"
"sync"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
"github.com/zmb3/spotify"
)
var (
Parties *PartyManager
wg = new(sync.WaitGroup)
Auth spotify.Authenticator
CmdHandler *CommandHandler
PREFIX string
)
func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate) {
user := message.Author
if user.ID == session.State.User.ID {
return
}
content := message.Content
if len(content) <= len(PREFIX) || content[:len(PREFIX)] != PREFIX {
return
}
content = content[len(PREFIX):]
if len(content) < 1 {
return
}
args := strings.Fields(content)
name := strings.ToLower(args[0])
command, err := CmdHandler.Get(name)
if err != nil {
return
}
channel, err := session.State.Channel(message.ChannelID)
if err != nil {
fmt.Println("Error getting channel: ", err)
return
}
guild, err := session.State.Guild(message.GuildID)
if err != nil {
fmt.Println("Error getting guild: ", err)
return
}
ctx := NewContext(session, guild, channel, user, message, Parties, Auth, args[1:])
c := *command
c(ctx)
}
func main() {
err := godotenv.Load()
PREFIX = os.Getenv("PREFIX")
if err != nil {
fmt.Println("Could not find a .env file")
}
wg.Add(2)
Parties = NewPartyManager()
CmdHandler = NewCommandHandler()
Auth = GetSpotifyAuth()
go InitDiscord()
go InitAuthServer()
wg.Wait()
}
// GetSpotifyAuth ...
func GetSpotifyAuth() spotify.Authenticator {
clientID := os.Getenv("SPOTIFY_ID")
secretKey := os.Getenv("SPOTIFY_SECRET")
url := os.Getenv("URL")
auth := spotify.NewAuthenticator(url, spotify.ScopeUserReadCurrentlyPlaying, spotify.ScopeUserReadPlaybackState, spotify.ScopeUserModifyPlaybackState, spotify.ScopePlaylistModifyPublic)
auth.SetAuthInfo(clientID, secretKey)
return auth
}