From 81d9910e5ee97602a49c4e6f93c8f4debb059043 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 20 Oct 2024 12:45:28 +0200 Subject: [PATCH] fix(vocal): detection of connection and disconnection not working --- xp/events.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/xp/events.go b/xp/events.go index e8acd59..90af121 100644 --- a/xp/events.go +++ b/xp/events.go @@ -70,22 +70,26 @@ func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) { } LastEventUpdate(s, GetCopaing(e.UserID, e.GuildID)) cfg := config.GetGuildConfig(e.GuildID) - if cfg.IsDisabled(e.ChannelID) { - return - } client, err := getRedisClient() if err != nil { utils.SendAlert("xp/events.go - Getting redis client", err.Error()) return } - if e.BeforeUpdate == nil { + if e.BeforeUpdate == nil && e.ChannelID != "" { + if cfg.IsDisabled(e.ChannelID) { + return + } onConnection(s, e, client) - } else { + } else if e.BeforeUpdate != nil && e.ChannelID == "" { + if cfg.IsDisabled(e.BeforeUpdate.ChannelID) { + return + } onDisconnect(s, e, client) } } func onConnection(_ *discordgo.Session, e *discordgo.VoiceStateUpdate, client *redis.Client) { + utils.SendDebug("User connected", "username", e.Member.DisplayName()) c := GetCopaing(e.UserID, e.GuildID) err := client.Set( context.Background(), @@ -132,6 +136,7 @@ func onDisconnect(s *discordgo.Session, e *discordgo.VoiceStateUpdate, client *r )) return } + utils.SendDebug("User disconnected", "username", e.Member.DisplayName(), "since", con) err = client.Set(context.Background(), key, strconv.Itoa(NotConnected), 0).Err() if err != nil { utils.SendAlert("xp/events.go - Set connected_since to not connected", err.Error())