mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
fix: Fixed currency rewards in patronage service
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using NadekoBot.Modules.Gambling.Services;
|
using NadekoBot.Modules.Gambling.Services;
|
||||||
using NadekoBot.Modules.Patronage;
|
using NadekoBot.Modules.Patronage;
|
||||||
using NadekoBot.Services.Currency;
|
using NadekoBot.Services.Currency;
|
||||||
@@ -8,7 +9,7 @@ using NadekoBot.Db.Models;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Utility;
|
namespace NadekoBot.Modules.Utility;
|
||||||
|
|
||||||
public sealed class CurrencyRewardService : INService, IDisposable
|
public sealed class CurrencyRewardService : INService, IReadyExecutor
|
||||||
{
|
{
|
||||||
private readonly ICurrencyService _cs;
|
private readonly ICurrencyService _cs;
|
||||||
private readonly IPatronageService _ps;
|
private readonly IPatronageService _ps;
|
||||||
@@ -32,16 +33,14 @@ public sealed class CurrencyRewardService : INService, IDisposable
|
|||||||
_config = config;
|
_config = config;
|
||||||
_client = client;
|
_client = client;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnReadyAsync()
|
||||||
|
{
|
||||||
_ps.OnNewPatronPayment += OnNewPayment;
|
_ps.OnNewPatronPayment += OnNewPayment;
|
||||||
_ps.OnPatronRefunded += OnPatronRefund;
|
_ps.OnPatronRefunded += OnPatronRefund;
|
||||||
_ps.OnPatronUpdated += OnPatronUpdate;
|
_ps.OnPatronUpdated += OnPatronUpdate;
|
||||||
}
|
return Task.CompletedTask;
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_ps.OnNewPatronPayment -= OnNewPayment;
|
|
||||||
_ps.OnPatronRefunded -= OnPatronRefund;
|
|
||||||
_ps.OnPatronUpdated -= OnPatronUpdate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnPatronUpdate(Patron oldPatron, Patron newPatron)
|
private async Task OnPatronUpdate(Patron oldPatron, Patron newPatron)
|
||||||
|
@@ -203,7 +203,8 @@ public sealed class PatronageService
|
|||||||
// if his sub would end in teh future, extend it by one month.
|
// 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
|
// if it's not, just add 1 month to the last charge date
|
||||||
var count = await ctx.GetTable<PatronUser>()
|
var count = await ctx.GetTable<PatronUser>()
|
||||||
.Where(x => x.UniquePlatformUserId == subscriber.UniquePlatformUserId)
|
.Where(x => x.UniquePlatformUserId
|
||||||
|
== subscriber.UniquePlatformUserId)
|
||||||
.UpdateAsync(old => new()
|
.UpdateAsync(old => new()
|
||||||
{
|
{
|
||||||
UserId = subscriber.UserId,
|
UserId = subscriber.UserId,
|
||||||
@@ -215,14 +216,13 @@ public sealed class PatronageService
|
|||||||
: dateInOneMonth,
|
: 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));
|
await OnNewPatronPayment(PatronUserToPatron(dbPatron));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user