From a6adf73ecf3bffef5db7a63cd70217eed34df77a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 29 May 2024 09:54:05 +0000 Subject: [PATCH] fix: Fixed currency rewards in patronage service --- .../Modules/Patronage/CurrencyRewardService.cs | 15 +++++++-------- .../Modules/Patronage/PatronageService.cs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs b/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs index 854303136..b22d9d108 100644 --- a/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs +++ b/src/NadekoBot/Modules/Patronage/CurrencyRewardService.cs @@ -1,6 +1,7 @@ #nullable disable using LinqToDB; using LinqToDB.EntityFrameworkCore; +using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Modules.Gambling.Services; using NadekoBot.Modules.Patronage; using NadekoBot.Services.Currency; @@ -8,7 +9,7 @@ using NadekoBot.Db.Models; namespace NadekoBot.Modules.Utility; -public sealed class CurrencyRewardService : INService, IDisposable +public sealed class CurrencyRewardService : INService, IReadyExecutor { private readonly ICurrencyService _cs; private readonly IPatronageService _ps; @@ -32,16 +33,14 @@ public sealed class CurrencyRewardService : INService, IDisposable _config = config; _client = client; + } + + public Task OnReadyAsync() + { _ps.OnNewPatronPayment += OnNewPayment; _ps.OnPatronRefunded += OnPatronRefund; _ps.OnPatronUpdated += OnPatronUpdate; - } - - public void Dispose() - { - _ps.OnNewPatronPayment -= OnNewPayment; - _ps.OnPatronRefunded -= OnPatronRefund; - _ps.OnPatronUpdated -= OnPatronUpdate; + return Task.CompletedTask; } private async Task OnPatronUpdate(Patron oldPatron, Patron newPatron) diff --git a/src/NadekoBot/Modules/Patronage/PatronageService.cs b/src/NadekoBot/Modules/Patronage/PatronageService.cs index da6bc85e2..98b72d538 100644 --- a/src/NadekoBot/Modules/Patronage/PatronageService.cs +++ b/src/NadekoBot/Modules/Patronage/PatronageService.cs @@ -203,7 +203,8 @@ public sealed class PatronageService // if his sub would end in teh future, extend it by one month. // if it's not, just add 1 month to the last charge date var count = await ctx.GetTable() - .Where(x => x.UniquePlatformUserId == subscriber.UniquePlatformUserId) + .Where(x => x.UniquePlatformUserId + == subscriber.UniquePlatformUserId) .UpdateAsync(old => new() { UserId = subscriber.UserId, @@ -215,14 +216,13 @@ public sealed class PatronageService : dateInOneMonth, }); - // this should never happen - if (count == 0) - { - // await tran.RollbackAsync(); - continue; - } - // await tran.CommitAsync(); + dbPatron.UserId = subscriber.UserId; + dbPatron.AmountCents = subscriber.Cents; + dbPatron.LastCharge = lastChargeUtc; + dbPatron.ValidThru = dbPatron.ValidThru >= todayDate + ? dbPatron.ValidThru.AddMonths(1) + : dateInOneMonth; await OnNewPatronPayment(PatronUserToPatron(dbPatron)); }