63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
|
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)
|
||
|
}
|