-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.go
79 lines (68 loc) · 1.87 KB
/
commands.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
package commands
import (
"log"
"net/http"
"os"
"sync"
"time"
"github.com/bottleneckco/discord-radio/models"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
"google.golang.org/api/googleapi/transport"
youtube "google.golang.org/api/youtube/v3"
)
// CommandsMap a map of all the command handlers
var CommandsMap = make(map[string]func(*discordgo.Session, *discordgo.MessageCreate))
func newGuildSession(guildID, guildName string) models.GuildSession {
return models.GuildSession{
GuildID: guildID,
GuildName: guildName,
RWMutex: sync.RWMutex{},
MusicPlayer: models.MusicPlayer{
Control: make(chan models.MusicPlayerAction),
},
}
}
// GuildSessionMap a map of all the guild sessions
var GuildSessionMap = make(map[string]*models.GuildSession)
func safeGetGuildSession(s *discordgo.Session, guildID string) *models.GuildSession {
if session, ok := GuildSessionMap[guildID]; ok {
return session
}
var guildName string
guild, err := s.Guild(guildID)
if err == nil {
guildName = guild.Name
}
session := newGuildSession(guildID, guildName)
GuildSessionMap[guildID] = &session
return &session
}
var youtubeService *youtube.Service
func init() {
godotenv.Load()
var err error
client := &http.Client{
Transport: &transport.APIKey{Key: os.Getenv("GOOGLE_API_KEY")},
}
youtubeService, err = youtube.New(client)
if err != nil {
log.Println(err)
}
CommandsMap["ping"] = ping
CommandsMap["q"] = queue
CommandsMap["queue"] = queue
CommandsMap["play"] = play
CommandsMap["suicide"] = suicide
CommandsMap["skip"] = skip
CommandsMap["join"] = join
CommandsMap["pause"] = pause
CommandsMap["resume"] = resume
CommandsMap["help"] = help
CommandsMap["leave"] = leave
CommandsMap["status"] = status
}
func deleteMessageDelayed(s *discordgo.Session, msg *discordgo.Message) {
time.Sleep(20 * time.Second)
s.ChannelMessageDelete(msg.ChannelID, msg.ID)
}