-
Notifications
You must be signed in to change notification settings - Fork 1
/
pickcommand.go
65 lines (61 loc) · 1.75 KB
/
pickcommand.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
package cmd
import (
"fmt"
"strconv"
"github.com/Cloud-Fortress/syborg/pkg/framework"
"github.com/bwmarrin/discordgo"
)
const (
invalid_song_format = "Invalid song number `%d`. Min: 1, max: %d"
)
func PickCommand(ctx framework.Context) {
argsLen := len(ctx.Args)
if argsLen == 0 {
ctx.Reply("Usage: `music pick <result number>`")
return
}
if argsLen > 5 {
ctx.Reply("You cannot pick more than 5 songs at once.")
return
}
identifier := ytSessionIdentifier(ctx.User, ctx.TextChannel)
var ytSession ytSearchSession
var ok bool
if ytSession, ok = ytSessions[identifier]; !ok {
ctx.Reply("You haven't searched for a song yet!")
return
}
sess := ctx.Sessions.GetByGuild(ctx.Guild.ID)
if sess == nil {
ctx.Reply("Not in a voice channel! To make the bot join one, use `music join`.")
return
}
rLen := len(ytSession.results)
var msg *discordgo.Message
for i := 0; i < argsLen; i++ {
num, err := strconv.Atoi(ctx.Args[i])
if err != nil {
ctx.Reply("An error occured!")
fmt.Print("Error parsing int,", err)
return
}
if num < 1 || num > rLen {
ctx.Reply(fmt.Sprintf(invalid_song_format, num, rLen))
return
}
result := ytSession.results[num-1]
_, inp, err := ctx.Youtube.Get(result.Id)
video, err := ctx.Youtube.Video(*inp)
song := framework.NewSong(video.Media, video.Title, result.Id)
sess.Queue.Add(*song)
if msg != nil {
msg, err = ctx.Discord.ChannelMessageEdit(ctx.TextChannel.ID, msg.ID, msg.Content+", `"+song.Title+"`")
} else {
msg = ctx.Reply("Added `" + song.Title + "`")
}
}
if !sess.Queue.Running {
ctx.Discord.ChannelMessageEdit(ctx.TextChannel.ID, msg.ID, msg.Content+
" to the song queue.\nUse **music play** to start playing the songs! To see the song queue, use **music queue**.")
}
}