-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (80 loc) · 2.22 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
89
90
91
92
93
package main
import (
"log"
"os"
"os/signal"
"strings"
"github.com/bwmarrin/discordgo"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
)
// Initialize Discord & Setup Youtube
func init() {
var err error
botToken = os.Getenv("BOT_TOKEN") // Set your discord bot token as an environment variable.
youtubeToken = os.Getenv("YT_TOKEN") // Set your YouTube token as an environment variable.
s, err = discordgo.New("Bot " + botToken)
if err != nil {
log.Fatalf("Invalid bot parameters: %v", err)
}
service, err = youtube.NewService(ctx, option.WithAPIKey(youtubeToken))
if err != nil {
log.Fatalf("Error creating new YouTube client: %v", err)
}
setUpDcaOptions() // Encoder Settings
v.stop = true // Used to check if the bot is in channel playing music.
searchRequested = false
}
func main() {
// Add function handlers to trigger commands from discord chat
s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
log.Println("Firing up...")
})
s.AddHandler(executionHandler)
err := s.Open()
if err != nil {
log.Fatalf("Cannot open the session: %v", err)
}
defer s.Close()
log.Println("Session Open...")
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
log.Println("Graceful shutdown")
}
func executionHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// Avoid handling the message that the bot creates when replying to a user
if m.Author.Bot {
return
}
// Setup Channel Information
guildID := SearchGuild(m.ChannelID)
v.guildID = guildID
v.session = s
log.Println("Guild ID:", guildID)
log.Println("Channel ID:", m.ChannelID)
log.Println("Message:", m.Content)
// Commands
if m.Content != "" {
if m.Content == "play help" {
// TODO: Add Help Menu
} else if m.Content == "play stuff" {
go queueStuff(m)
} else if m.Content == "play kudasai" {
go queueKudasai(m)
} else if strings.Contains(m.Content, "play") {
go queueSong(m)
} else if m.Content == "stop" {
go stop(m)
} else if strings.Contains(m.Content, "skip") {
go skip(m)
} else if m.Content == "queue" {
go displayQueue(m)
} else if strings.Contains(m.Content, "remove") {
go remove(m)
}
} else {
log.Println("Message is empty:", m.Content)
return
}
}