-
Notifications
You must be signed in to change notification settings - Fork 1
/
skip.go
61 lines (56 loc) · 1.88 KB
/
skip.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
package commands
import (
"fmt"
"strconv"
"github.com/bottleneckco/discord-radio/models"
"github.com/bwmarrin/discordgo"
)
func skip(s *discordgo.Session, m *discordgo.MessageCreate) {
guildSession := safeGetGuildSession(s, m.Message.GuildID)
guildSession.RWMutex.RLock()
if len(guildSession.Queue) == 0 || guildSession.MusicPlayer.PlaybackState == models.PlaybackStateStopped {
s.ChannelMessageSend(m.Message.ChannelID, fmt.Sprintf("%s nothing to skip", m.Message.Author.Mention()))
guildSession.RWMutex.RUnlock()
return
}
guildSession.RWMutex.RUnlock()
guildSession.RWMutex.Lock()
var skippedItem models.QueueItem
if len(m.Message.Content) == 0 {
// No args, skip current
skippedItem = guildSession.Queue[0]
// Queue = append(Queue[:0], Queue[1:]...)
guildSession.MusicPlayer.Control <- models.MusicPlayerActionStop
} else {
choice, err := strconv.ParseInt(m.Message.Content, 10, 64)
if err == nil && (choice-1 >= 0 && choice-1 < int64(len(guildSession.Queue))) {
skippedItem = guildSession.Queue[choice-1]
guildSession.Queue = append(guildSession.Queue[:choice-1], guildSession.Queue[choice:]...)
} else {
s.ChannelMessageSend(m.Message.ChannelID, fmt.Sprintf("%s invalid choice", m.Message.Author.Mention()))
guildSession.RWMutex.Unlock()
return
}
}
guildSession.RWMutex.Unlock()
avatarURL := m.Message.Author.AvatarURL("32")
s.ChannelMessageSendEmbed(
m.Message.ChannelID,
&discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
Name: "Removed from queue",
IconURL: avatarURL,
},
Title: skippedItem.Title,
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: skippedItem.Thumbnail,
},
URL: fmt.Sprintf("https://www.youtube.com/watch?v=%s", skippedItem.VideoID),
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "Channel",
Value: skippedItem.ChannelTitle,
},
},
})
}