From f9b5938e60831adca4990c40a2c2c782d178b1ad Mon Sep 17 00:00:00 2001 From: Sarisia Date: Mon, 18 May 2020 22:19:49 +0900 Subject: [PATCH] bot: fix voice state struct --- aria/bot.go | 4 ++-- aria/voice.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aria/bot.go b/aria/bot.go index 006c4c0..a796bb4 100644 --- a/aria/bot.go +++ b/aria/bot.go @@ -282,7 +282,7 @@ func (b *bot) onMessage(s *discordgo.Session, m *discordgo.MessageCreate) { func (b *bot) recoverVoiceConnections() { v := b.voice.cloneJoined() - for c, g := range v { + for g, c := range v { if err := b.joinVoice(g, c); err != nil { log.Printf("failedc to recover voice: %v\n", err) } @@ -311,7 +311,7 @@ func (b *bot) disconnectVoice(guildID string) error { return err } - b.voice.recordDisconnect(v.ChannelID) + b.voice.recordDisconnect(guildID) return nil } diff --git a/aria/voice.go b/aria/voice.go index 760899d..b912db0 100644 --- a/aria/voice.go +++ b/aria/voice.go @@ -6,11 +6,11 @@ import ( type voice struct { sync.RWMutex - joined map[string]string // channelID -> guildID + joined map[string]string // guildID: channelID } type voiceState interface { - // cloneJoined returns map contains channelID -> guildID + // cloneJoined returns map contains guildID: channelID cloneJoined() map[string]string recordJoin(guildID, channelID string) recordDisconnect(channelID string) @@ -38,12 +38,12 @@ func (v *voice) recordJoin(guildID, channelID string) { v.Lock() defer v.Unlock() - v.joined[channelID] = guildID + v.joined[guildID] = channelID } -func (v *voice) recordDisconnect(channelID string) { +func (v *voice) recordDisconnect(guildID string) { v.Lock() defer v.Unlock() - delete(v.joined, channelID) + delete(v.joined, guildID) }