Updated Xp module

This commit is contained in:
Toastie (DCS Team) 2024-06-27 21:07:29 +12:00
parent a9576e5aa1
commit b7b8366fe2
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
3 changed files with 12 additions and 8 deletions

View file

@ -2,6 +2,7 @@
using EllieBot.Modules.Xp.Services; using EllieBot.Modules.Xp.Services;
using EllieBot.Db.Models; using EllieBot.Db.Models;
using EllieBot.Modules.Patronage; using EllieBot.Modules.Patronage;
using EllieBot.Modules.Utility;
namespace EllieBot.Modules.Xp; namespace EllieBot.Modules.Xp;

View file

@ -668,7 +668,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
/// <param name="channel"></param> /// <param name="channel"></param>
private async Task ScanUserForVoiceXp(SocketGuildUser user, SocketVoiceChannel channel) private async Task ScanUserForVoiceXp(SocketGuildUser user, SocketVoiceChannel channel)
{ {
if (UserParticipatingInVoiceChannel(user) && ShouldTrackXp(user, channel.Id)) if (UserParticipatingInVoiceChannel(user) && ShouldTrackXp(user, channel))
await UserJoinedVoiceChannel(user); await UserJoinedVoiceChannel(user);
else else
await UserLeftVoiceChannel(user, channel); 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; return false;
if (_excludedServers.Contains(user.Guild.Id)) if (_excludedServers.Contains(user.Guild.Id))
@ -788,7 +791,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
_ = Task.Run(async () => _ = Task.Run(async () =>
{ {
if (!ShouldTrackXp(user, arg.Channel.Id)) if (!ShouldTrackXp(user, arg.Channel))
return; return;
var xpConf = _xpConfig.Data; var xpConf = _xpConfig.Data;
@ -1286,9 +1289,9 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
Image? frame = null; Image? frame = null;
if (item is null) if (item is null)
{ {
if (patron.Tier == PatronTier.V) if (patron?.Tier == PatronTier.V)
frame = Image.Load<Rgba32>(File.OpenRead("data/images/frame_silver.png")); frame = Image.Load<Rgba32>(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<Rgba32>(File.OpenRead("data/images/frame_gold.png")); frame = Image.Load<Rgba32>(File.OpenRead("data/images/frame_gold.png"));
} }
else else
@ -1465,7 +1468,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
{ {
var patron = await _ps.GetPatronAsync(userId); 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; return BuyResult.InsufficientPatronTier;
} }

View file

@ -1,4 +1,4 @@
#nullable disable warnings #nullable disable warnings
namespace EllieBot.Db.Models; namespace EllieBot.Db.Models;
public class XpShopOwnedItem : DbEntity public class XpShopOwnedItem : DbEntity