1
0
mirror of https://github.com/stryan/mumble-discord-bridge.git synced 2024-11-22 21:35:44 -05:00

use discord CreateGuild instead of Ready

This commit is contained in:
stryan 2021-01-19 13:19:05 -05:00
parent 79f305cec1
commit daacaaad50
2 changed files with 5 additions and 30 deletions

View File

@ -15,25 +15,15 @@ type DiscordListener struct {
Bridge *BridgeState
}
func (l *DiscordListener) ready(s *discordgo.Session, event *discordgo.Ready) {
log.Println("READY event registered")
func (l *DiscordListener) guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
log.Println("CREATE event registered")
//Setup initial discord state
var g *discordgo.Guild
g = nil
for _, i := range event.Guilds {
if i.ID == l.Bridge.BridgeConfig.GID {
g = i
}
}
if g == nil {
log.Println("bad guild on READY")
if event.ID != l.Bridge.BridgeConfig.GID {
log.Println("received GuildCreate from a guild not in config")
return
}
for _, vs := range g.VoiceStates {
for _, vs := range event.VoiceStates {
if vs.ChannelID == l.Bridge.BridgeConfig.CID {
if s.State.User.ID == vs.UserID {
// Ignore bot
@ -143,20 +133,6 @@ func (l *DiscordListener) messageCreate(s *discordgo.Session, m *discordgo.Messa
}
}
func (l *DiscordListener) guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
if event.Guild.Unavailable {
return
}
for _, channel := range event.Guild.Channels {
if channel.ID == event.Guild.ID {
log.Println("Mumble-Discord bridge is active in new guild")
return
}
}
}
func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
l.Bridge.DiscordUsersMutex.Lock()
defer l.Bridge.DiscordUsersMutex.Unlock()

View File

@ -144,7 +144,6 @@ func main() {
Bridge.DiscordListener = &DiscordListener{
Bridge: Bridge,
}
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.ready)
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.messageCreate)
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.guildCreate)
Bridge.DiscordSession.AddHandler(Bridge.DiscordListener.voiceUpdate)