aboutsummaryrefslogtreecommitdiff
path: root/xp/events.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-10-20 12:45:28 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-10-20 12:45:28 +0200
commit81d9910e5ee97602a49c4e6f93c8f4debb059043 (patch)
tree0156c0a648925fbba6f9edd839051fba986af26d /xp/events.go
parent7306bcb83b0b2443ca8ab2247f4cc390ad2efd02 (diff)
fix(vocal): detection of connection and disconnection not working
Diffstat (limited to 'xp/events.go')
-rw-r--r--xp/events.go15
1 files 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())