2019-10-13 11:39:17 +07:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"TerraOceanBot/db"
|
|
|
|
"TerraOceanBot/discord/config"
|
2019-10-13 12:38:00 +07:00
|
|
|
"TerraOceanBot/discord/message"
|
2019-10-13 11:39:17 +07:00
|
|
|
"TerraOceanBot/server"
|
|
|
|
)
|
|
|
|
|
2019-10-18 04:20:11 +07:00
|
|
|
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 {
|
2019-10-13 11:39:17 +07:00
|
|
|
continue
|
|
|
|
}
|
2019-10-18 04:20:11 +07:00
|
|
|
username, err := db.GetMinecraftUsername(vs.UserID)
|
|
|
|
if err == db.ErrNotFound {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
continue
|
2019-10-13 11:39:17 +07:00
|
|
|
}
|
2019-10-18 04:20:11 +07:00
|
|
|
server.ConnectUser(username)
|
2019-10-13 11:39:17 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 12:38:00 +07:00
|
|
|
func VoiceStateUpdate(s *discordgo.Session, vs *discordgo.VoiceState) {
|
2019-10-13 11:39:17 +07:00
|
|
|
username, err := db.GetMinecraftUsername(vs.UserID)
|
|
|
|
if err == db.ErrNotFound {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, "", err)
|
2019-10-13 11:39:17 +07:00
|
|
|
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)
|
|
|
|
}
|