forked from chanbakjsd/TerraOceanPlugin
go: Connect voice state update to the Kotlin plugin
parent
f3c69655e2
commit
69e2a2736c
@ -0,0 +1,62 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
||||
"TerraOceanBot/db"
|
||||
"TerraOceanBot/discord/config"
|
||||
"TerraOceanBot/server"
|
||||
)
|
||||
|
||||
func UpdateVoiceChannelState(s *discordgo.Session) {
|
||||
for _, guild := range s.State.Guilds {
|
||||
if guild.ID != config.GuildID {
|
||||
continue
|
||||
}
|
||||
for _, vs := range guild.VoiceStates {
|
||||
if vs.ChannelID != config.VoiceChannel {
|
||||
continue
|
||||
}
|
||||
if vs.Deaf || vs.SelfDeaf {
|
||||
continue
|
||||
}
|
||||
username, err := db.GetMinecraftUsername(vs.UserID)
|
||||
if err == db.ErrNotFound {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
//TODO Use auditError() once it's moved to its own package.
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
server.ConnectUser(username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func VoiceStateUpdate(vs *discordgo.VoiceState) {
|
||||
username, err := db.GetMinecraftUsername(vs.UserID)
|
||||
if err == db.ErrNotFound {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
//TODO Use auditError() once it's moved to its own package.
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if vs.GuildID != config.GuildID {
|
||||
server.DisconnectUser(username)
|
||||
return
|
||||
}
|
||||
if vs.ChannelID != config.VoiceChannel {
|
||||
server.DisconnectUser(username)
|
||||
return
|
||||
}
|
||||
if vs.Deaf || vs.SelfDeaf {
|
||||
server.DisconnectUser(username)
|
||||
return
|
||||
}
|
||||
server.ConnectUser(username)
|
||||
}
|
Loading…
Reference in New Issue