forked from chanbakjsd/TerraOceanPlugin
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package backend
|
|
|
|
import (
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"TerraOceanBot/db"
|
|
"TerraOceanBot/discord/config"
|
|
"TerraOceanBot/discord/message"
|
|
"TerraOceanBot/server"
|
|
)
|
|
|
|
func UpdateVoiceChannelState(s *discordgo.Session, guild *discordgo.GuildCreate) {
|
|
if guild.ID != config.GuildID {
|
|
return
|
|
}
|
|
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 {
|
|
continue
|
|
}
|
|
server.ConnectUser(username)
|
|
}
|
|
}
|
|
|
|
func VoiceStateUpdate(s *discordgo.Session, vs *discordgo.VoiceState) {
|
|
username, err := db.GetMinecraftUsername(vs.UserID)
|
|
if err == db.ErrNotFound {
|
|
return
|
|
}
|
|
if err != nil {
|
|
message.AuditError(s, "", 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)
|
|
}
|