diff --git a/src/EllieBot/Modules/Xp/Xp.cs b/src/EllieBot/Modules/Xp/Xp.cs index 2bf8fcb..a667be4 100644 --- a/src/EllieBot/Modules/Xp/Xp.cs +++ b/src/EllieBot/Modules/Xp/Xp.cs @@ -2,6 +2,7 @@ using EllieBot.Modules.Xp.Services; using EllieBot.Db.Models; using EllieBot.Modules.Patronage; +using EllieBot.Modules.Utility; namespace EllieBot.Modules.Xp; diff --git a/src/EllieBot/Modules/Xp/XpService.cs b/src/EllieBot/Modules/Xp/XpService.cs index 97d349a..6df1151 100644 --- a/src/EllieBot/Modules/Xp/XpService.cs +++ b/src/EllieBot/Modules/Xp/XpService.cs @@ -668,7 +668,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand /// private async Task ScanUserForVoiceXp(SocketGuildUser user, SocketVoiceChannel channel) { - if (UserParticipatingInVoiceChannel(user) && ShouldTrackXp(user, channel.Id)) + if (UserParticipatingInVoiceChannel(user) && ShouldTrackXp(user, channel)) await UserJoinedVoiceChannel(user); else await UserLeftVoiceChannel(user, channel); @@ -767,9 +767,12 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand } */ - private bool ShouldTrackXp(SocketGuildUser user, ulong channelId) + private bool ShouldTrackXp(SocketGuildUser user, IMessageChannel channel) { - if (_excludedChannels.TryGetValue(user.Guild.Id, out var chans) && chans.Contains(channelId)) + var channelId = channel.Id; + + if (_excludedChannels.TryGetValue(user.Guild.Id, out var chans) && (chans.Contains(channelId) + || (channel is SocketThreadChannel tc && chans.Contains(tc.ParentChannel.Id)))) return false; if (_excludedServers.Contains(user.Guild.Id)) @@ -788,7 +791,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand _ = Task.Run(async () => { - if (!ShouldTrackXp(user, arg.Channel.Id)) + if (!ShouldTrackXp(user, arg.Channel)) return; var xpConf = _xpConfig.Data; @@ -1286,9 +1289,9 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand Image? frame = null; if (item is null) { - if (patron.Tier == PatronTier.V) + if (patron?.Tier == PatronTier.V) frame = Image.Load(File.OpenRead("data/images/frame_silver.png")); - else if (patron.Tier >= PatronTier.X || _creds.IsOwner(userId)) + else if (patron?.Tier >= PatronTier.X || _creds.IsOwner(userId)) frame = Image.Load(File.OpenRead("data/images/frame_gold.png")); } else @@ -1465,7 +1468,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand { var patron = await _ps.GetPatronAsync(userId); - if ((int)patron.Tier < (int)req) + if (patron is null || (int)patron.Value.Tier < (int)req) return BuyResult.InsufficientPatronTier; } diff --git a/src/EllieBot/Modules/Xp/_common/db/XpShopOwnedItem.cs b/src/EllieBot/Modules/Xp/_common/db/XpShopOwnedItem.cs index 29b491e..955e17d 100644 --- a/src/EllieBot/Modules/Xp/_common/db/XpShopOwnedItem.cs +++ b/src/EllieBot/Modules/Xp/_common/db/XpShopOwnedItem.cs @@ -1,4 +1,4 @@ -#nullable disable warnings +#nullable disable warnings namespace EllieBot.Db.Models; public class XpShopOwnedItem : DbEntity