-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
74 lines (62 loc) · 1.97 KB
/
main.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
package main
import (
"strings"
"github.com/CodingVoid/gomble/gomble"
"github.com/CodingVoid/gomble/logger"
)
// queue of tracks
var queue []*gomble.Track
func main() {
gomble.Init(logger.TRACE, "127.0.0.1:64738", false)
gomble.Listener.OnPrivateMessageReceived = OnPrivateMessageReceived
gomble.Listener.OnChannelMessageReceived = OnChannelMessageReceived
gomble.Listener.OnTrackFinished = OnTrackFinished
gomble.Listener.OnTrackPaused = OnTrackPaused
gomble.Listener.OnTrackStopped = OnTrackStopped
gomble.Listener.OnTrackException = OnTrackException
gomble.Begin()
}
func OnPrivateMessageReceived(e gomble.PrivateMessageReceivedEvent) {
gomble.SendMessageToUser("Send Back Private", e.Actor)
}
func OnChannelMessageReceived(e gomble.ChannelMessageReceivedEvent) {
if strings.HasPrefix(e.Message, "#play ") {
logger.Debugf(e.Message + "\n")
yt, err := gomble.LoadTrack(e.Message)
if err != nil {
logger.Errorf("%v", err)
return
}
queue = append(queue, yt)
startNextTrack()
} else if strings.HasPrefix(e.Message, "#stop") {
gomble.Stop()
} else if strings.HasPrefix(e.Message, "#pause") {
gomble.Pause()
} else if strings.HasPrefix(e.Message, "#resume") {
gomble.Resume()
}
}
func OnTrackFinished(e gomble.TrackFinishedEvent) {
startNextTrack()
}
func OnTrackPaused(e gomble.TrackPausedEvent) {
logger.Infof("Paused Track: %s", e.Track.GetTitle())
}
func OnTrackStopped(e gomble.TrackStoppedEvent) {
logger.Infof("Stopped Track: %s", e.Track.GetTitle())
}
func OnTrackException(e gomble.TrackExceptionEvent) {
logger.Warnf("Got an Exception while playing Track: %s", e.Track.GetTitle())
}
func startNextTrack() {
if len(queue) > 0 {
t := queue[0]
// returns false if a track is already playing (or t == nil). returns true if starting was successful
if gomble.Play(t) {
gomble.SendMessageToChannel("Start playing Track "+t.GetTitle(), gomble.BotUserState.ChannelId)
// If successful remove the track from the queue
queue = queue[1:]
}
}
}