This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.go
88 lines (68 loc) · 1.6 KB
/
server.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
80
81
82
83
84
85
86
87
88
package main
import (
"sync"
"github.com/Strum355/go-queue/queue"
)
type servers struct {
Count int `json:"-"`
VoiceInsts int `json:"-"`
Mutex sync.RWMutex `json:"-"`
serverMap map[string]*server
}
func (s *servers) server(id string) (val *server, ok bool) {
val, ok = s.serverMap[id]
return
}
func (s *servers) setServer(id string, serv server) {
s.serverMap[id] = &serv
}
type server struct {
LogChannel string `json:"log_channel"`
Prefix string `json:"server_prefix,omitempty"`
Log bool `json:"log_active"`
Kicked bool `json:"kicked"`
Nsfw bool `json:"nsfw"`
//Enabled, Message, Channel
JoinMessage [3]string `json:"join"`
VoiceInst *voiceInst `json:"-"`
Playlists map[string][]song `json:"playlists"`
}
func (s *servers) getCount() int {
return s.Count
}
/*
func (s *servers) validate() {
for _, guild := range s.Server {
details := guildDetails(guild.ID)
}
} */
func (s *server) newVoiceInstance() {
s.VoiceInst = &voiceInst{
Queue: queue.New(),
Done: make(chan error),
RWMutex: new(sync.RWMutex),
}
}
func (s server) nextSong() song {
return s.VoiceInst.Queue.Front().(song)
}
func (s server) finishedSong() {
s.VoiceInst.Queue.PopFront()
}
func (s server) addSong(song song) {
s.VoiceInst.Queue.PushBack(song)
}
func (s server) queueLength() int {
s.VoiceInst.RLock()
defer s.VoiceInst.RUnlock()
return s.VoiceInst.Queue.Len()
}
func (s server) iterateQueue() []song {
s.VoiceInst.RLock()
defer s.VoiceInst.RUnlock()
ret := make([]song, s.VoiceInst.Queue.Len())
for i, val := range s.VoiceInst.Queue.List() {
ret[i] = val.(song)
}
return ret
}