-
Notifications
You must be signed in to change notification settings - Fork 1
/
join.go
57 lines (51 loc) · 2.11 KB
/
join.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
package commands
import (
"fmt"
"log"
"os"
"os/exec"
"github.com/andersfylling/disgord"
"github.com/bottleneckco/discord-radio/ctx"
"github.com/bottleneckco/discord-radio/vscache"
"github.com/evalphobia/google-tts-go/googletts"
)
func join(s disgord.Session, m *disgord.MessageCreate) {
voiceChannelInit(s, m)
guildSession := safeGetGuildSession(m.Message.GuildID)
go guildSession.Loop()
}
func voiceChannelInit(s disgord.Session, m *disgord.MessageCreate) {
guildSession := safeGetGuildSession(m.Message.GuildID)
voiceStateCache, ok := vscache.FindUserVoiceState(m.Message.Author.ID)
if !ok {
log.Println("No voice state cached")
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s you are not in a voice channel", m.Message.Author.Mention()))
return
}
channel, err := s.GetChannel(ctx.Ctx, voiceStateCache.Current.ChannelID)
if err != nil {
log.Println(err)
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s error occurred: %s", m.Message.Author.Mention(), err))
return
}
voiceChannel, err := s.VoiceConnect(m.Message.GuildID, voiceStateCache.Current.ChannelID)
if err != nil {
log.Println(err)
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s error occurred: %s", m.Message.Author.Mention(), err))
return
}
guildSession.VoiceConnection = voiceChannel
guildSession.VoiceChannelID = channel.ID
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s joined '%s'", m.Message.Author.Mention(), channel.Name))
log.Printf(fmt.Sprintf("%s joined '%s' guild '%s'\n", m.Message.Author.Mention(), channel.Name, m.Message.GuildID))
url, _ := googletts.GetTTSURL("Ready", "en")
if os.Getenv("BOT_UPDATE_YTDL") == "true" {
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s updating youtube-dl binary, give me some time.", m.Message.Author.Mention()))
updateCmd := exec.Command("/usr/bin/curl", "-L", "https://yt-dl.org/downloads/latest/youtube-dl", "-o", "/usr/local/bin/youtube-dl")
updateCmd.Stdout = os.Stdout
updateCmd.Stderr = os.Stderr
updateCmd.Run()
s.SendMsg(ctx.Ctx, m.Message.ChannelID, fmt.Sprintf("%s done!", m.Message.Author.Mention()))
}
guildSession.PlayURL(url, 0.5)
}