meta: add travis ci
This commit is contained in:
parent
c8828fe4d2
commit
84aeb76f76
|
@ -0,0 +1,7 @@
|
||||||
|
language: go
|
||||||
|
go:
|
||||||
|
- "1.10"
|
||||||
|
install: go get -t ./...
|
||||||
|
script:
|
||||||
|
- go test
|
||||||
|
- go build ./example/...
|
344
example/main.go
344
example/main.go
|
@ -1,173 +1,171 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/foxbot/gavalink"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/foxbot/gavalink"
|
||||||
// this requires the "feature/manual-voice-connection branch!!"
|
)
|
||||||
"github.com/foxbot/discordgo"
|
|
||||||
)
|
var token string
|
||||||
|
var lavalink *gavalink.Lavalink
|
||||||
var token string
|
var player *gavalink.Player
|
||||||
var lavalink *gavalink.Lavalink
|
|
||||||
var player *gavalink.Player
|
func init() {
|
||||||
|
flag.StringVar(&token, "token", "", "token=unprefixed token")
|
||||||
func init() {
|
}
|
||||||
flag.StringVar(&token, "token", "", "token=unprefixed token")
|
|
||||||
}
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
if token == "" {
|
||||||
|
panic("no token specified!")
|
||||||
if token == "" {
|
}
|
||||||
panic("no token specified!")
|
token = "Bot " + token
|
||||||
}
|
|
||||||
token = "Bot " + token
|
dg, err := discordgo.New(token)
|
||||||
|
if err != nil {
|
||||||
dg, err := discordgo.New(token)
|
panic(err)
|
||||||
if err != nil {
|
}
|
||||||
panic(err)
|
dg.SyncEvents = false
|
||||||
}
|
|
||||||
dg.SyncEvents = false
|
dg.AddHandler(ready)
|
||||||
|
dg.AddHandler(messageCreate)
|
||||||
dg.AddHandler(ready)
|
dg.AddHandler(voiceServerUpdate)
|
||||||
dg.AddHandler(messageCreate)
|
|
||||||
dg.AddHandler(voiceServerUpdate)
|
err = dg.Open()
|
||||||
|
if err != nil {
|
||||||
err = dg.Open()
|
panic(err)
|
||||||
if err != nil {
|
}
|
||||||
panic(err)
|
|
||||||
}
|
sc := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
||||||
sc := make(chan os.Signal, 1)
|
<-sc
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
|
||||||
<-sc
|
dg.Close()
|
||||||
|
}
|
||||||
dg.Close()
|
|
||||||
}
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
|
log.Println("discordgo ready!")
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
s.UpdateStatus(0, "gavalink")
|
||||||
log.Println("discordgo ready!")
|
|
||||||
s.UpdateStatus(0, "gavalink")
|
lavalink = gavalink.NewLavalink("1", event.User.ID)
|
||||||
|
|
||||||
lavalink = gavalink.NewLavalink("1", event.User.ID)
|
err := lavalink.AddNodes(gavalink.NodeConfig{
|
||||||
|
REST: "http://localhost:2333",
|
||||||
err := lavalink.AddNodes(gavalink.NodeConfig{
|
WebSocket: "ws://localhost:2334",
|
||||||
REST: "http://localhost:2333",
|
Password: "youshallnotpass",
|
||||||
WebSocket: "ws://localhost:2334",
|
})
|
||||||
Password: "youshallnotpass",
|
if err != nil {
|
||||||
})
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
}
|
||||||
}
|
|
||||||
}
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
if m.Author.ID == s.State.User.ID {
|
||||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
return
|
||||||
if m.Author.ID == s.State.User.ID {
|
}
|
||||||
return
|
|
||||||
}
|
if m.Content == "~>>join" {
|
||||||
|
c, err := s.State.Channel(m.ChannelID)
|
||||||
if m.Content == "~>>join" {
|
if err != nil {
|
||||||
c, err := s.State.Channel(m.ChannelID)
|
log.Println("fail find channel")
|
||||||
if err != nil {
|
return
|
||||||
log.Println("fail find channel")
|
}
|
||||||
return
|
|
||||||
}
|
g, err := s.State.Guild(c.GuildID)
|
||||||
|
if err != nil {
|
||||||
g, err := s.State.Guild(c.GuildID)
|
log.Println("fail find guild")
|
||||||
if err != nil {
|
return
|
||||||
log.Println("fail find guild")
|
}
|
||||||
return
|
|
||||||
}
|
for _, vs := range g.VoiceStates {
|
||||||
|
if vs.UserID == m.Author.ID {
|
||||||
for _, vs := range g.VoiceStates {
|
log.Println("trying to connect to channel")
|
||||||
if vs.UserID == m.Author.ID {
|
err = s.ChannelVoiceJoinManual(c.GuildID, vs.ChannelID, false, false)
|
||||||
log.Println("trying to connect to channel")
|
if err != nil {
|
||||||
err = s.ChannelVoiceJoinManual(c.GuildID, vs.ChannelID, false, false)
|
log.Println(err)
|
||||||
if err != nil {
|
} else {
|
||||||
log.Println(err)
|
log.Println("channel voice join succeeded")
|
||||||
} else {
|
}
|
||||||
log.Println("channel voice join succeeded")
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if strings.HasPrefix(m.Content, "~>>play") {
|
||||||
}
|
query := m.Content[8:]
|
||||||
} else if strings.HasPrefix(m.Content, "~>>play") {
|
node, err := lavalink.BestNode()
|
||||||
query := m.Content[8:]
|
if err != nil {
|
||||||
node, err := lavalink.BestNode()
|
log.Println(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Println(err)
|
}
|
||||||
return
|
tracks, err := node.LoadTracks(query)
|
||||||
}
|
if err != nil {
|
||||||
tracks, err := node.LoadTracks(query)
|
log.Println(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Println(err)
|
}
|
||||||
return
|
if tracks.Type != gavalink.TrackLoaded {
|
||||||
}
|
log.Println("weird tracks type", tracks.Type)
|
||||||
if tracks.Type != gavalink.TrackLoaded {
|
}
|
||||||
log.Println("weird tracks type", tracks.Type)
|
track := tracks.Tracks[0].Data
|
||||||
}
|
err = player.Play(track)
|
||||||
track := tracks.Tracks[0].Data
|
if err != nil {
|
||||||
err = player.Play(track)
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
} else if m.Content == "~>>stop" {
|
||||||
}
|
err := player.Stop()
|
||||||
} else if m.Content == "~>>stop" {
|
if err != nil {
|
||||||
err := player.Stop()
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
} else if m.Content == "~>>pause" {
|
||||||
}
|
err := player.Pause(!player.Paused())
|
||||||
} else if m.Content == "~>>pause" {
|
if err != nil {
|
||||||
err := player.Pause(!player.Paused())
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
} else if strings.HasPrefix(m.Content, "~>>volume") {
|
||||||
}
|
query := m.Content[10:]
|
||||||
} else if strings.HasPrefix(m.Content, "~>>volume") {
|
vol, err := strconv.Atoi(query)
|
||||||
query := m.Content[10:]
|
if err != nil {
|
||||||
vol, err := strconv.Atoi(query)
|
log.Println(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Println(err)
|
}
|
||||||
return
|
err = player.Volume(vol)
|
||||||
}
|
if err != nil {
|
||||||
err = player.Volume(vol)
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
func voiceServerUpdate(s *discordgo.Session, event *discordgo.VoiceServerUpdate) {
|
||||||
|
log.Println("received VSU")
|
||||||
func voiceServerUpdate(s *discordgo.Session, event *discordgo.VoiceServerUpdate) {
|
vsu := gavalink.VoiceServerUpdate{
|
||||||
log.Println("received VSU")
|
Endpoint: event.Endpoint,
|
||||||
vsu := gavalink.VoiceServerUpdate{
|
GuildID: event.GuildID,
|
||||||
Endpoint: event.Endpoint,
|
Token: event.Token,
|
||||||
GuildID: event.GuildID,
|
}
|
||||||
Token: event.Token,
|
|
||||||
}
|
if p, err := lavalink.GetPlayer(event.GuildID); err == nil {
|
||||||
|
err = p.Forward(s.State.SessionID, vsu)
|
||||||
if p, err := lavalink.GetPlayer(event.GuildID); err == nil {
|
if err != nil {
|
||||||
err = p.Forward(s.State.SessionID, vsu)
|
log.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
node, err := lavalink.BestNode()
|
||||||
|
if err != nil {
|
||||||
node, err := lavalink.BestNode()
|
log.Println(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Println(err)
|
}
|
||||||
return
|
|
||||||
}
|
handler := new(gavalink.DummyEventHandler)
|
||||||
|
player, err = node.CreatePlayer(event.GuildID, s.State.SessionID, vsu, handler)
|
||||||
handler := new(gavalink.DummyEventHandler)
|
if err != nil {
|
||||||
player, err = node.CreatePlayer(event.GuildID, s.State.SessionID, vsu, handler)
|
log.Println(err)
|
||||||
if err != nil {
|
return
|
||||||
log.Println(err)
|
}
|
||||||
return
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue