This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
queue.go
75 lines (67 loc) · 1.48 KB
/
queue.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
package main
// QueueGetSong
func (v *VoiceInstance) QueueGetSong() (song Song) {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
if len(v.queue) != 0 {
return v.queue[0]
}
return
}
// QueueAdd
func (v *VoiceInstance) QueueAdd(song Song) {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
v.queue = append(v.queue, song)
}
// QueueRemoveFirst
func (v *VoiceInstance) QueueRemoveFisrt() {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
if len(v.queue) != 0 {
v.queue = v.queue[1:]
}
}
// QueueRemoveIndex
func (v *VoiceInstance) QueueRemoveIndex(k int) {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
if len(v.queue) != 0 && k <= len(v.queue) {
v.queue = append(v.queue[:k], v.queue[k+1:]...)
}
}
// QueueRemoveUser
func (v *VoiceInstance) QueueRemoveUser(user string) {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
queue := v.queue
v.queue = []Song{}
if len(v.queue) != 0 {
for _, q := range queue {
if q.User != user {
v.queue = append(v.queue, q)
}
}
}
}
// QueueRemoveLast
func (v *VoiceInstance) QueueRemoveLast() {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
if len(v.queue) != 0 {
v.queue = append(v.queue[:len(v.queue)-1], v.queue[len(v.queue):]...)
}
}
// QueueClean
func (v *VoiceInstance) QueueClean() {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
// hold the actual song in the queue
v.queue = v.queue[:1]
}
// QueueRemove
func (v *VoiceInstance) QueueRemove() {
v.queueMutex.Lock()
defer v.queueMutex.Unlock()
v.queue = []Song{}
}