Compare commits
2 Commits
ddf7ea2f15
...
33230a54d5
Author | SHA1 | Date |
---|---|---|
Stein Ivar Berghei | 33230a54d5 | |
Stein Ivar Berghei | 38a43bde59 |
18
bot.go
18
bot.go
|
@ -9,7 +9,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/diamondburned/arikawa/v3/state"
|
||||||
|
"github.com/diamondburned/arikawa/v3/voice"
|
||||||
"github.com/faiface/beep"
|
"github.com/faiface/beep"
|
||||||
"github.com/fhs/gompd/v2/mpd"
|
"github.com/fhs/gompd/v2/mpd"
|
||||||
"github.com/gohugoio/hugo/cache/filecache"
|
"github.com/gohugoio/hugo/cache/filecache"
|
||||||
|
@ -51,8 +52,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
discord *discordgo.Session
|
discord *state.State
|
||||||
voice *discordgo.VoiceConnection
|
voice *voice.Session
|
||||||
youtube *youtube.Service
|
youtube *youtube.Service
|
||||||
ambiance beep.Mixer
|
ambiance beep.Mixer
|
||||||
curamb Ambiance
|
curamb Ambiance
|
||||||
|
@ -75,16 +76,17 @@ func main() {
|
||||||
|
|
||||||
ticker := time.NewTicker(300 * time.Millisecond)
|
ticker := time.NewTicker(300 * time.Millisecond)
|
||||||
|
|
||||||
sc := make(chan os.Signal, 1)
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
defer cancel()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sc:
|
case <-ctx.Done():
|
||||||
app.db.Close(context.Background())
|
app.db.Close(ctx)
|
||||||
app.mpdw.Close()
|
app.mpdw.Close()
|
||||||
app.mpdc()
|
app.mpdc()
|
||||||
app.voice.Close()
|
app.voice.Leave(ctx)
|
||||||
|
dgvc()
|
||||||
app.discord.Close()
|
app.discord.Close()
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
48
discord.go
48
discord.go
|
@ -1,42 +1,56 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
discordspeaker "dndmusicbot/speaker"
|
discordspeaker "dndmusicbot/speaker"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/diamondburned/arikawa/v3/discord"
|
||||||
|
"github.com/diamondburned/arikawa/v3/state"
|
||||||
|
"github.com/diamondburned/arikawa/v3/voice"
|
||||||
|
"github.com/diamondburned/arikawa/v3/voice/voicegateway"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var dgvc context.CancelFunc
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("discord.go loading..")
|
log.Println("discord.go loading..")
|
||||||
var err error
|
|
||||||
|
|
||||||
token := config.GetString("discord.token")
|
token := config.GetString("discord.token")
|
||||||
guild := config.GetString("discord.guild")
|
|
||||||
channel := config.GetString("discord.channel")
|
channel := config.GetString("discord.channel")
|
||||||
|
|
||||||
app.discord, err = discordgo.New("Bot " + token)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
if err != nil {
|
|
||||||
return
|
dgvc = cancel
|
||||||
|
s := state.New("Bot " + token)
|
||||||
|
|
||||||
|
// This is required for bots.
|
||||||
|
voice.AddIntents(s)
|
||||||
|
|
||||||
|
if err := s.Open(ctx); err != nil {
|
||||||
|
log.Fatalln("failed to open gateway:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.discord.LogLevel = discordgo.LogDebug
|
v, err := voice.NewSession(s)
|
||||||
|
|
||||||
err = app.discord.Open()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
log.Fatalln("failed to create voice session:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.voice, err = app.discord.ChannelVoiceJoin(guild, channel, false, true)
|
chsf, err := discord.ParseSnowflake(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
log.Fatalln("failed to create snowflake:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.voice.LogLevel = discordgo.LogDebug
|
if err := v.JoinChannelAndSpeak(ctx, discord.ChannelID(chsf), false, true); err != nil {
|
||||||
|
log.Fatalln("failed to join voice channel:", err)
|
||||||
err = discordspeaker.Init(app.voice)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.Speaking(ctx, voicegateway.NotSpeaking)
|
||||||
|
|
||||||
|
app.discord = s
|
||||||
|
app.voice = v
|
||||||
|
|
||||||
|
discordspeaker.Init(v)
|
||||||
|
|
||||||
log.Println("discord.go done.")
|
log.Println("discord.go done.")
|
||||||
}
|
}
|
||||||
|
|
101
events.go
101
events.go
|
@ -54,11 +54,112 @@ func init() {
|
||||||
app.events.On("next", app.nextSong)
|
app.events.On("next", app.nextSong)
|
||||||
app.events.On("prev", app.prevSong)
|
app.events.On("prev", app.prevSong)
|
||||||
|
|
||||||
|
app.events.On("vol_up", app.volup)
|
||||||
|
app.events.On("vol_down", app.voldown)
|
||||||
|
app.events.On("vol_set", app.volset)
|
||||||
|
|
||||||
//app.events.On("tick", app.checkQueue)
|
//app.events.On("tick", app.checkQueue)
|
||||||
app.events.On("tick", app.songPosition)
|
app.events.On("tick", app.songPosition)
|
||||||
//app.events.On("tick", app.checkTimeleft)
|
//app.events.On("tick", app.checkTimeleft)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) volup(payload ...interface{}) {
|
||||||
|
if !(len(payload) > 0) {
|
||||||
|
log.Println("volup called without a payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var t string
|
||||||
|
switch data := payload[0].(type) {
|
||||||
|
case json.RawMessage:
|
||||||
|
var err error
|
||||||
|
err = json.Unmarshal(data, &t)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Println("volup called with invalid payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t {
|
||||||
|
case "playlist":
|
||||||
|
pl_volume.Volume = pl_volume.Volume + 0.1
|
||||||
|
case "ambiance":
|
||||||
|
amb_volume.Volume = amb_volume.Volume + 0.1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) voldown(payload ...interface{}) {
|
||||||
|
if !(len(payload) > 0) {
|
||||||
|
log.Println("voldown called without a payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var t string
|
||||||
|
switch data := payload[0].(type) {
|
||||||
|
case json.RawMessage:
|
||||||
|
var err error
|
||||||
|
err = json.Unmarshal(data, &t)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Println("voldown called with invalid payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t {
|
||||||
|
case "playlist":
|
||||||
|
pl_volume.Volume = pl_volume.Volume - 0.1
|
||||||
|
case "ambiance":
|
||||||
|
amb_volume.Volume = amb_volume.Volume - 0.1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) volset(payload ...interface{}) {
|
||||||
|
if !(len(payload) > 0) {
|
||||||
|
log.Println("volset called without a payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data map[string]string
|
||||||
|
switch js := payload[0].(type) {
|
||||||
|
case json.RawMessage:
|
||||||
|
json.Unmarshal(js, &data)
|
||||||
|
default:
|
||||||
|
log.Println("volset called with invalid payload.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
vol, err := strconv.ParseFloat(data["vol"], 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch data["type"] {
|
||||||
|
case "playlist":
|
||||||
|
pl_volume.Volume = vol
|
||||||
|
case "ambiance":
|
||||||
|
amb_volume.Volume = vol
|
||||||
|
}
|
||||||
|
|
||||||
|
app.sendVolume()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) sendVolume() {
|
||||||
|
msg := make(map[string]interface{})
|
||||||
|
out := make(map[string]float64)
|
||||||
|
msg["event"] = "volume"
|
||||||
|
out["playlist"] = pl_volume.Volume
|
||||||
|
out["ambiance"] = amb_volume.Volume
|
||||||
|
msg["payload"] = out
|
||||||
|
ws_msg <- msg
|
||||||
|
}
|
||||||
|
|
||||||
func (app *App) songInfoEvent(event string) map[string]interface{} {
|
func (app *App) songInfoEvent(event string) map[string]interface{} {
|
||||||
msg := make(map[string]interface{})
|
msg := make(map[string]interface{})
|
||||||
msg["event"] = event
|
msg["event"] = event
|
||||||
|
|
14
go.mod
14
go.mod
|
@ -5,8 +5,8 @@ replace github.com/fhs/gompd/v2 => /home/steino/dev/go/gompd/
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bwmarrin/discordgo v0.26.1
|
|
||||||
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b
|
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b
|
||||||
|
github.com/diamondburned/arikawa/v3 v3.1.1-0.20221210140357-3b98cde06f9e
|
||||||
github.com/faiface/beep v1.1.0
|
github.com/faiface/beep v1.1.0
|
||||||
github.com/fhs/gompd/v2 v2.3.0
|
github.com/fhs/gompd/v2 v2.3.0
|
||||||
github.com/gohugoio/hugo v0.106.0
|
github.com/gohugoio/hugo v0.106.0
|
||||||
|
@ -22,11 +22,10 @@ require (
|
||||||
github.com/spf13/afero v1.9.3
|
github.com/spf13/afero v1.9.3
|
||||||
github.com/spf13/viper v1.14.0
|
github.com/spf13/viper v1.14.0
|
||||||
github.com/tidwall/gjson v1.14.3
|
github.com/tidwall/gjson v1.14.3
|
||||||
golang.org/x/net v0.2.0
|
golang.org/x/net v0.3.0
|
||||||
golang.org/x/time v0.2.0
|
golang.org/x/time v0.3.0
|
||||||
google.golang.org/api v0.103.0
|
google.golang.org/api v0.103.0
|
||||||
gopkg.in/hraban/opus.v2 v2.0.0-20220302220929-eeacdbcb92d0
|
gopkg.in/hraban/opus.v2 v2.0.0-20220302220929-eeacdbcb92d0
|
||||||
layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -53,6 +52,7 @@ require (
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
|
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
||||||
|
github.com/gorilla/schema v1.2.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||||
|
@ -77,10 +77,10 @@ require (
|
||||||
github.com/tidwall/pretty v1.2.1 // indirect
|
github.com/tidwall/pretty v1.2.1 // indirect
|
||||||
github.com/yuin/goldmark v1.5.3 // indirect
|
github.com/yuin/goldmark v1.5.3 // indirect
|
||||||
go.opencensus.io v0.24.0 // indirect
|
go.opencensus.io v0.24.0 // indirect
|
||||||
golang.org/x/crypto v0.2.0 // indirect
|
golang.org/x/crypto v0.4.0 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
|
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
|
||||||
golang.org/x/sys v0.2.0 // indirect
|
golang.org/x/sys v0.3.0 // indirect
|
||||||
golang.org/x/text v0.4.0 // indirect
|
golang.org/x/text v0.5.0 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
|
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
|
||||||
google.golang.org/grpc v1.50.1 // indirect
|
google.golang.org/grpc v1.50.1 // indirect
|
||||||
|
|
31
go.sum
31
go.sum
|
@ -72,8 +72,6 @@ github.com/bep/overlayfs v0.6.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXa
|
||||||
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
|
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
|
||||||
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
|
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
|
||||||
github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs=
|
github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs=
|
||||||
github.com/bwmarrin/discordgo v0.26.1 h1:AIrM+g3cl+iYBr4yBxCBp9tD9jR3K7upEjl0d89FRkE=
|
|
||||||
github.com/bwmarrin/discordgo v0.26.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||||
|
@ -93,6 +91,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b h1:a/CjIrvEH2NkUUIo4sqWIw+h3E63ttmS8L8Vx3ZaLS0=
|
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b h1:a/CjIrvEH2NkUUIo4sqWIw+h3E63ttmS8L8Vx3ZaLS0=
|
||||||
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b/go.mod h1:Gc/R1HBRJIEElnD4PGXGQZQYMb14oPbvTovm6WeuAvk=
|
github.com/davecheney/xattr v0.0.0-20151008032638-dc6dbbe49f0b/go.mod h1:Gc/R1HBRJIEElnD4PGXGQZQYMb14oPbvTovm6WeuAvk=
|
||||||
|
github.com/diamondburned/arikawa/v3 v3.1.1-0.20221210140357-3b98cde06f9e h1:vP/3xB9FOXh+rj86fQdlz/LFBmSeGmFHnmpDbF7QTCw=
|
||||||
|
github.com/diamondburned/arikawa/v3 v3.1.1-0.20221210140357-3b98cde06f9e/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
|
||||||
github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc=
|
github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc=
|
||||||
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
|
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
|
||||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||||
|
@ -202,6 +202,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
|
||||||
github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ=
|
github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ=
|
||||||
github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8=
|
github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8=
|
||||||
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
||||||
|
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
|
||||||
|
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
@ -353,9 +355,10 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
|
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
|
||||||
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||||
|
@ -426,8 +429,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
|
golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk=
|
||||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
@ -489,10 +492,11 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20211001092434-39dca1131b70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
@ -501,13 +505,14 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
|
||||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.2.0 h1:52I/1L54xyEQAYdtcSuxtiT84KGYTBGXwayxmIpNJhE=
|
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||||
|
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
@ -685,8 +690,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 h1:/S1gOotFo2sADAIdSGk1sDq1VxetoCWr6f5nxOG0dpY=
|
|
||||||
layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32/go.mod h1:yDtyzWZDFCVnva8NGtg38eH2Ns4J0D/6hD+MMeUGdF0=
|
|
||||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||||
|
|
16
queue.go
16
queue.go
|
@ -13,25 +13,35 @@ import (
|
||||||
discordspeaker "dndmusicbot/speaker"
|
discordspeaker "dndmusicbot/speaker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var pl_volume *effects.Volume
|
||||||
|
var amb_volume *effects.Volume
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("queue.go loading..")
|
log.Println("queue.go loading..")
|
||||||
|
|
||||||
app.ambiance = beep.Mixer{}
|
app.ambiance = beep.Mixer{}
|
||||||
discordspeaker.Play(&app.ambiance)
|
|
||||||
|
amb_volume = &effects.Volume{
|
||||||
|
Streamer: &app.ambiance,
|
||||||
|
Base: 2,
|
||||||
|
Volume: 2,
|
||||||
|
Silent: false,
|
||||||
|
}
|
||||||
|
discordspeaker.Play(amb_volume)
|
||||||
|
|
||||||
mpdstream, err := NewMPD()
|
mpdstream, err := NewMPD()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
volume := &effects.Volume{
|
pl_volume = &effects.Volume{
|
||||||
Streamer: mpdstream,
|
Streamer: mpdstream,
|
||||||
Base: 2,
|
Base: 2,
|
||||||
Volume: -2,
|
Volume: -2,
|
||||||
Silent: false,
|
Silent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
discordspeaker.Play(volume)
|
discordspeaker.Play(pl_volume)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
app.queue = new(Queue)
|
app.queue = new(Queue)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package discordspeaker
|
package discordspeaker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/diamondburned/arikawa/v3/voice"
|
||||||
|
"github.com/diamondburned/arikawa/v3/voice/voicegateway"
|
||||||
"github.com/faiface/beep"
|
"github.com/faiface/beep"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gopkg.in/hraban/opus.v2"
|
"gopkg.in/hraban/opus.v2"
|
||||||
|
@ -17,15 +19,17 @@ var (
|
||||||
samples [][2]float64
|
samples [][2]float64
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
encoder *opus.Encoder
|
encoder *opus.Encoder
|
||||||
voice *discordgo.VoiceConnection
|
//voice *discordgo.VoiceConnection
|
||||||
frameSize int = 960
|
frameSize int = 960
|
||||||
channels int = 2
|
channels int = 2
|
||||||
sampleRate int = 48000
|
sampleRate int = 48000
|
||||||
maxBytes int = (frameSize * 2) * 2
|
maxBytes int = (frameSize * 2) * 2
|
||||||
buf []byte
|
buf []byte
|
||||||
|
session *voice.Session
|
||||||
|
spk bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(dgv *discordgo.VoiceConnection) error {
|
func Init(dgv *voice.Session) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
|
@ -36,7 +40,7 @@ func Init(dgv *discordgo.VoiceConnection) error {
|
||||||
buf = make([]byte, maxBytes)
|
buf = make([]byte, maxBytes)
|
||||||
samples = make([][2]float64, frameSize)
|
samples = make([][2]float64, frameSize)
|
||||||
|
|
||||||
voice = dgv
|
session = dgv
|
||||||
|
|
||||||
encoder, err = opus.NewEncoder(sampleRate, channels, opus.AppVoIP)
|
encoder, err = opus.NewEncoder(sampleRate, channels, opus.AppVoIP)
|
||||||
encoder.SetBitrateToMax()
|
encoder.SetBitrateToMax()
|
||||||
|
@ -97,10 +101,21 @@ func update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if Silence(f32) {
|
if Silence(f32) {
|
||||||
|
if spk {
|
||||||
|
log.Println("Notspeaking")
|
||||||
|
session.Speaking(context.Background(), voicegateway.NotSpeaking)
|
||||||
|
spk = false
|
||||||
|
}
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !spk {
|
||||||
|
log.Println("Speaking")
|
||||||
|
session.Speaking(context.Background(), voicegateway.Microphone)
|
||||||
|
spk = true
|
||||||
|
}
|
||||||
|
|
||||||
n, err := encoder.EncodeFloat32(f32, buf)
|
n, err := encoder.EncodeFloat32(f32, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -108,11 +123,12 @@ func update() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !voice.Ready || voice.OpusSend == nil {
|
_, err = session.Write(buf[:n])
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
voice.OpusSend <- buf[:n]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Silence(in []float32) bool {
|
func Silence(in []float32) bool {
|
||||||
|
|
|
@ -35,6 +35,40 @@ window.onload = function () {
|
||||||
const link = document.querySelector("#link")
|
const link = document.querySelector("#link")
|
||||||
const time = document.querySelector("#time")
|
const time = document.querySelector("#time")
|
||||||
const waiting = document.querySelector("#waiting")
|
const waiting = document.querySelector("#waiting")
|
||||||
|
const pvol = document.querySelector("#playlist-volume")
|
||||||
|
const avol = document.querySelector("#ambiance-volume")
|
||||||
|
|
||||||
|
pvol.addEventListener("change", (e) => {
|
||||||
|
e.target.nextElementSibling.value = e.target.value
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
"event": "vol_set",
|
||||||
|
"payload": {
|
||||||
|
"type": "playlist",
|
||||||
|
"vol": e.target.value
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
pvol.nextElementSibling.addEventListener("change", (e) => {
|
||||||
|
e.target.previousElementSibling.value = e.target.value
|
||||||
|
e.target.previousElementSibling.dispatchEvent(new Event('change'));
|
||||||
|
})
|
||||||
|
|
||||||
|
avol.addEventListener("change", (e) => {
|
||||||
|
e.target.nextElementSibling.value = e.target.value
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
"event": "vol_set",
|
||||||
|
"payload": {
|
||||||
|
"type": "ambiance",
|
||||||
|
"vol": e.target.value
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
avol.nextElementSibling.addEventListener("change", (e) => {
|
||||||
|
e.target.previousElementSibling.value = e.target.value
|
||||||
|
e.target.previousElementSibling.dispatchEvent(new Event('change'));
|
||||||
|
})
|
||||||
|
|
||||||
addInteractHandler(
|
addInteractHandler(
|
||||||
document.querySelector("input#next"), (e) => {
|
document.querySelector("input#next"), (e) => {
|
||||||
|
@ -107,6 +141,12 @@ window.onload = function () {
|
||||||
ws.onmessage = (e) => {
|
ws.onmessage = (e) => {
|
||||||
data = JSON.parse(e.data)
|
data = JSON.parse(e.data)
|
||||||
switch (data.event) {
|
switch (data.event) {
|
||||||
|
case "volume":
|
||||||
|
pvol.value = data.payload.playlist
|
||||||
|
pvol.nextElementSibling.value = data.payload.playlist
|
||||||
|
avol.value = data.payload.ambiance
|
||||||
|
avol.nextElementSibling.value = data.payload.ambiance
|
||||||
|
break
|
||||||
case "ambiance_add":
|
case "ambiance_add":
|
||||||
const container = document.querySelector("#ambiance")
|
const container = document.querySelector("#ambiance")
|
||||||
var newdiv = document.createElement('div');
|
var newdiv = document.createElement('div');
|
||||||
|
|
|
@ -67,6 +67,19 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div id="volume_playlist" class="input-container">
|
||||||
|
<label for="playlist-volume">Playlist</label>
|
||||||
|
<input type="range" id="playlist-volume" min="-6" max="1" step="0.1">
|
||||||
|
<input id="playlist-volume-number" type="number" min="-6" max="1" step="0.1" style="width:50px" />
|
||||||
|
</div>
|
||||||
|
<div id="volume_ambiance" class="input-container">
|
||||||
|
<label for="ambiance-volume">Ambiance</label>
|
||||||
|
<input type="range" id="ambiance-volume" min="-4" max="4" step="0.1">
|
||||||
|
<input id="ambiance-volume-number" type="number" min="-4" max="4" step="0.1" style="width:50px" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- The Modal -->
|
<!-- The Modal -->
|
||||||
<div id="waiting" class="modal">
|
<div id="waiting" class="modal">
|
||||||
<!-- Modal content -->
|
<!-- Modal content -->
|
||||||
|
|
8
ws.go
8
ws.go
|
@ -66,8 +66,16 @@ func handleWS(c *websocket.Conn) error {
|
||||||
|
|
||||||
msg := app.songInfoEvent("song_info")
|
msg := app.songInfoEvent("song_info")
|
||||||
|
|
||||||
|
vol := make(map[string]interface{})
|
||||||
|
volout := make(map[string]float64)
|
||||||
|
vol["event"] = "volume"
|
||||||
|
volout["playlist"] = pl_volume.Volume
|
||||||
|
volout["ambiance"] = amb_volume.Volume
|
||||||
|
vol["payload"] = volout
|
||||||
|
|
||||||
c.SetWriteDeadline(time.Now().Add(10 * time.Second))
|
c.SetWriteDeadline(time.Now().Add(10 * time.Second))
|
||||||
c.WriteJSON(msg)
|
c.WriteJSON(msg)
|
||||||
|
c.WriteJSON(vol)
|
||||||
|
|
||||||
if app.ambiance.Len() > 0 {
|
if app.ambiance.Len() > 0 {
|
||||||
msg := make(map[string]interface{})
|
msg := make(map[string]interface{})
|
||||||
|
|
Loading…
Reference in New Issue